Skip to content

Commit 11e7897

Browse files
Rollup merge of #81812 - nagisa:nagisa/escape-the-escape-hatch, r=Amanieu
Add a test for escaping LLVMisms in inline asm We escape certain LLVM-specific features when passing the inline assembly string to the LLVM. Until now, however, there was no test making sure this behaviour stays intact. This commit adds such a test! r? `@Amanieu` cc `@joshtriplett`
2 parents e143159 + 243755a commit 11e7897

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/test/codegen/asm-sanitize-llvm.rs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// FIXME(nagisa): remove the flags here once all targets support `asm!`.
2+
// compile-flags: --target x86_64-unknown-linux-gnu
3+
4+
// Verify we sanitize the special tokens for the LLVM inline-assembly, ensuring people won't
5+
// inadvertently rely on the LLVM-specific syntax and features.
6+
#![no_core]
7+
#![feature(no_core, lang_items, rustc_attrs)]
8+
#![crate_type = "rlib"]
9+
10+
#[rustc_builtin_macro]
11+
macro_rules! asm {
12+
() => {};
13+
}
14+
15+
#[lang = "sized"]
16+
trait Sized {}
17+
#[lang = "copy"]
18+
trait Copy {}
19+
20+
pub unsafe fn we_escape_dollar_signs() {
21+
// CHECK: call void asm sideeffect alignstack inteldialect "banana$$:"
22+
asm!(
23+
r"banana$:",
24+
)
25+
}
26+
27+
pub unsafe fn we_escape_escapes_too() {
28+
// CHECK: call void asm sideeffect alignstack inteldialect "banana\{{(\\|5C)}}36:"
29+
asm!(
30+
r"banana\36:",
31+
)
32+
}

0 commit comments

Comments
 (0)