-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Lint against named asm labels #87324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
75915ad
Lint against named asm labels
asquared31415 1e1f219
Comment tweaks
asquared31415 1f8f863
Revert accidental removal of attributes
asquared31415 6f45f62
Proper characters in labels, ignore comments
asquared31415 8e7bbc9
Handle leading colons properly
asquared31415 1ae19b6
Fix lint capitalization and ignoring, test with include_str
asquared31415 ae8a1ba
Update error message
asquared31415 51e414f
Combine spans into one error, deduplicate code
asquared31415 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
// only-x86_64 | ||
|
||
#![feature(asm, global_asm)] | ||
|
||
#[no_mangle] | ||
pub static FOO: usize = 42; | ||
|
||
fn main() { | ||
unsafe { | ||
// Basic usage | ||
asm!("bar: nop"); //~ ERROR avoid using named labels | ||
|
||
// No following asm | ||
asm!("abcd:"); //~ ERROR avoid using named labels | ||
|
||
// Multiple labels on one line | ||
asm!("foo: bar1: nop"); | ||
//~^ ERROR avoid using named labels | ||
|
||
// Multiple lines | ||
asm!("foo1: nop", "nop"); //~ ERROR avoid using named labels | ||
asm!("foo2: foo3: nop", "nop"); | ||
//~^ ERROR avoid using named labels | ||
asm!("nop", "foo4: nop"); //~ ERROR avoid using named labels | ||
asm!("foo5: nop", "foo6: nop"); | ||
//~^ ERROR avoid using named labels | ||
//~| ERROR avoid using named labels | ||
|
||
// Statement separator | ||
asm!("foo7: nop; foo8: nop"); | ||
//~^ ERROR avoid using named labels | ||
asm!("foo9: nop; nop"); //~ ERROR avoid using named labels | ||
asm!("nop; foo10: nop"); //~ ERROR avoid using named labels | ||
|
||
// Escaped newline | ||
asm!("bar2: nop\n bar3: nop"); | ||
//~^ 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 | ||
asm!("nop\n bar6: bar7: nop"); | ||
//~^ ERROR avoid using named labels | ||
|
||
// Raw strings | ||
asm!( | ||
r" | ||
blah2: nop | ||
blah3: nop | ||
" | ||
); | ||
//~^^^^ ERROR avoid using named labels | ||
|
||
asm!( | ||
r###" | ||
nop | ||
nop ; blah4: nop | ||
"### | ||
); | ||
//~^^^ ERROR avoid using named labels | ||
|
||
// Non-labels | ||
// should not trigger lint, but may be invalid asm | ||
asm!("ab cd: nop"); | ||
|
||
// `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"); | ||
|
||
// Only `blah1:` should trigger | ||
asm!("blah1: 2bar: nop"); //~ ERROR avoid using named labels | ||
|
||
// Duplicate labels | ||
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 | ||
|
||
// Trying to break parsing | ||
asm!(":"); | ||
asm!("\n:\n"); | ||
asm!("::::"); | ||
|
||
// 0x3A is a ':' | ||
asm!("fooo\u{003A} nop"); //~ ERROR avoid using named labels | ||
asm!("foooo\x3A nop"); //~ ERROR avoid using named labels | ||
|
||
// 0x0A is a newline | ||
asm!("fooooo:\u{000A} nop"); //~ ERROR avoid using named labels | ||
asm!("foooooo:\x0A nop"); //~ ERROR avoid using named labels | ||
|
||
// Intentionally breaking span finding | ||
// equivalent to "ABC: nop" | ||
asm!("\x41\x42\x43\x3A\x20\x6E\x6F\x70"); //~ ERROR avoid using named labels | ||
|
||
// 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 | ||
" | ||
); | ||
//~^^^^ ERROR avoid using named labels | ||
|
||
// 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"); | ||
|
||
// Test include_str in asm | ||
asm!(include_str!("named-asm-labels.s")); //~ ERROR avoid using named labels | ||
|
||
// Test allowing or warning on the lint instead | ||
#[allow(named_asm_labels)] | ||
{ | ||
asm!("allowed: nop"); // Should not emit anything | ||
} | ||
|
||
#[warn(named_asm_labels)] | ||
{ | ||
asm!("warned: nop"); //~ WARNING avoid using named labels | ||
} | ||
} | ||
} | ||
|
||
// Don't trigger on global asm | ||
global_asm!("aaaaaaaa: nop"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
lab1: nop | ||
// do more things | ||
lab2: nop // does bar | ||
// a: b | ||
lab3: nop; lab4: nop |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.