2021-07-21 18:01:05 -04:00
|
|
|
// only-x86_64
|
|
|
|
|
2021-07-20 16:35:26 -04:00
|
|
|
#![feature(asm, global_asm)]
|
|
|
|
|
2021-07-21 18:01:05 -04:00
|
|
|
#[no_mangle]
|
|
|
|
pub static FOO: usize = 42;
|
|
|
|
|
2021-07-20 16:35:26 -04:00
|
|
|
fn main() {
|
|
|
|
unsafe {
|
|
|
|
// Basic usage
|
2021-07-29 18:56:31 -04:00
|
|
|
asm!("bar: nop"); //~ ERROR avoid using named labels
|
2021-07-20 16:35:26 -04:00
|
|
|
|
|
|
|
// No following asm
|
2021-07-29 18:56:31 -04:00
|
|
|
asm!("abcd:"); //~ ERROR avoid using named labels
|
2021-07-20 16:35:26 -04:00
|
|
|
|
|
|
|
// Multiple labels on one line
|
|
|
|
asm!("foo: bar1: nop");
|
2021-07-29 18:56:31 -04:00
|
|
|
//~^ ERROR avoid using named labels
|
|
|
|
//~| ERROR avoid using named labels
|
2021-07-20 16:35:26 -04:00
|
|
|
|
|
|
|
// Multiple lines
|
2021-07-29 18:56:31 -04:00
|
|
|
asm!("foo1: nop", "nop"); //~ ERROR avoid using named labels
|
2021-07-20 16:35:26 -04:00
|
|
|
asm!("foo2: foo3: nop", "nop");
|
2021-07-29 18:56:31 -04:00
|
|
|
//~^ ERROR avoid using named labels
|
|
|
|
//~| ERROR avoid using named labels
|
|
|
|
asm!("nop", "foo4: nop"); //~ ERROR avoid using named labels
|
2021-07-20 16:35:26 -04:00
|
|
|
asm!("foo5: nop", "foo6: nop");
|
2021-07-29 18:56:31 -04:00
|
|
|
//~^ ERROR avoid using named labels
|
|
|
|
//~| ERROR avoid using named labels
|
2021-07-20 16:35:26 -04:00
|
|
|
|
|
|
|
// Statement separator
|
|
|
|
asm!("foo7: nop; foo8: nop");
|
2021-07-29 18:56:31 -04:00
|
|
|
//~^ ERROR avoid using named labels
|
|
|
|
//~| ERROR avoid using named labels
|
|
|
|
asm!("foo9: nop; nop"); //~ ERROR avoid using named labels
|
|
|
|
asm!("nop; foo10: nop"); //~ ERROR avoid using named labels
|
2021-07-20 16:35:26 -04:00
|
|
|
|
|
|
|
// Escaped newline
|
|
|
|
asm!("bar2: nop\n bar3: nop");
|
2021-07-29 18:56:31 -04:00
|
|
|
//~^ ERROR avoid using named labels
|
|
|
|
//~| ERROR avoid using named labels
|
|
|
|
asm!("bar4: nop\n nop"); //~ ERROR avoid using named labels
|
|
|
|
asm!("nop\n bar5: nop"); //~ ERROR avoid using named labels
|
2021-07-20 16:35:26 -04:00
|
|
|
asm!("nop\n bar6: bar7: nop");
|
2021-07-29 18:56:31 -04:00
|
|
|
//~^ ERROR avoid using named labels
|
|
|
|
//~| ERROR avoid using named labels
|
2021-07-20 16:35:26 -04:00
|
|
|
|
|
|
|
// Raw strings
|
|
|
|
asm!(
|
|
|
|
r"
|
|
|
|
blah2: nop
|
|
|
|
blah3: nop
|
|
|
|
"
|
|
|
|
);
|
2021-07-29 18:56:31 -04:00
|
|
|
//~^^^^ ERROR avoid using named labels
|
|
|
|
//~^^^^ ERROR avoid using named labels
|
2021-07-20 16:35:26 -04:00
|
|
|
asm!(
|
|
|
|
r###"
|
|
|
|
nop
|
|
|
|
nop ; blah4: nop
|
|
|
|
"###
|
|
|
|
);
|
2021-07-29 18:56:31 -04:00
|
|
|
//~^^^ ERROR avoid using named labels
|
2021-07-20 16:35:26 -04:00
|
|
|
|
|
|
|
// Non-labels
|
|
|
|
// should not trigger lint, but may be invalid asm
|
|
|
|
asm!("ab cd: nop");
|
|
|
|
|
2021-07-21 17:47:37 -04:00
|
|
|
// `blah:` does not trigger because labels need to be at the start
|
|
|
|
// of the statement, and there was already a non-label
|
|
|
|
asm!("1bar: blah: nop");
|
2021-07-20 16:35:26 -04:00
|
|
|
|
|
|
|
// Only `blah1:` should trigger
|
2021-07-29 18:56:31 -04:00
|
|
|
asm!("blah1: 2bar: nop"); //~ ERROR avoid using named labels
|
2021-07-20 16:35:26 -04:00
|
|
|
|
|
|
|
// Duplicate labels
|
2021-07-29 18:56:31 -04:00
|
|
|
asm!("def: def: nop"); //~ ERROR avoid using named labels
|
|
|
|
asm!("def: nop\ndef: nop"); //~ ERROR avoid using named labels
|
|
|
|
asm!("def: nop; def: nop"); //~ ERROR avoid using named labels
|
2021-07-20 16:35:26 -04:00
|
|
|
|
|
|
|
// Trying to break parsing
|
|
|
|
asm!(":");
|
|
|
|
asm!("\n:\n");
|
|
|
|
asm!("::::");
|
|
|
|
|
|
|
|
// 0x3A is a ':'
|
2021-07-29 18:56:31 -04:00
|
|
|
asm!("fooo\u{003A} nop"); //~ ERROR avoid using named labels
|
|
|
|
asm!("foooo\x3A nop"); //~ ERROR avoid using named labels
|
2021-07-20 16:35:26 -04:00
|
|
|
|
|
|
|
// 0x0A is a newline
|
2021-07-29 18:56:31 -04:00
|
|
|
asm!("fooooo:\u{000A} nop"); //~ ERROR avoid using named labels
|
|
|
|
asm!("foooooo:\x0A nop"); //~ ERROR avoid using named labels
|
2021-07-20 16:35:26 -04:00
|
|
|
|
|
|
|
// Intentionally breaking span finding
|
|
|
|
// equivalent to "ABC: nop"
|
2021-07-29 18:56:31 -04:00
|
|
|
asm!("\x41\x42\x43\x3A\x20\x6E\x6F\x70"); //~ ERROR avoid using named labels
|
2021-07-21 17:47:37 -04:00
|
|
|
|
|
|
|
// Non-label colons - should pass
|
|
|
|
// (most of these are stolen from other places)
|
|
|
|
asm!("{:l}", in(reg) 0i64);
|
|
|
|
asm!("{:e}", in(reg) 0f32);
|
|
|
|
asm!("mov rax, qword ptr fs:[0]");
|
|
|
|
|
|
|
|
// Comments
|
|
|
|
asm!(
|
|
|
|
r"
|
|
|
|
ab: nop // ab: does foo
|
|
|
|
// cd: nop
|
|
|
|
"
|
|
|
|
);
|
2021-07-29 18:56:31 -04:00
|
|
|
//~^^^^ ERROR avoid using named labels
|
2021-07-21 18:01:05 -04:00
|
|
|
|
|
|
|
// Tests usage of colons in non-label positions
|
|
|
|
asm!(":lo12:FOO"); // this is apparently valid aarch64
|
|
|
|
// is there an example that is valid x86 for this test?
|
|
|
|
asm!(":bbb nop");
|
2021-07-22 19:26:16 -04:00
|
|
|
|
|
|
|
// Test include_str in asm
|
2021-07-29 18:56:31 -04:00
|
|
|
asm!(include_str!("named-asm-labels.s")); //~ ERROR avoid using named labels
|
2021-07-22 19:26:16 -04:00
|
|
|
|
|
|
|
// Test allowing or warning on the lint instead
|
|
|
|
#[allow(named_asm_labels)]
|
|
|
|
{
|
|
|
|
asm!("allowed: nop"); // Should not emit anything
|
|
|
|
}
|
|
|
|
|
|
|
|
#[warn(named_asm_labels)]
|
|
|
|
{
|
2021-07-29 18:56:31 -04:00
|
|
|
asm!("warned: nop"); //~ WARNING avoid using named labels
|
2021-07-22 19:26:16 -04:00
|
|
|
}
|
2021-07-20 16:35:26 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't trigger on global asm
|
|
|
|
global_asm!("aaaaaaaa: nop");
|