-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add lint for inline asm labels that look like binary
- Loading branch information
1 parent
35b658f
commit 87856c4
Showing
8 changed files
with
397 additions
and
91 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,17 @@ | ||
//@ needs-asm-support | ||
//@ only-x86_64 | ||
|
||
// tests that labels containing only the digits 0 and 1 are rejected | ||
// uses of such labels can sometimes be interpreted as a binary literal | ||
|
||
use std::arch::{asm, global_asm}; | ||
|
||
fn main() { | ||
unsafe { | ||
asm!("0: jmp 0b"); //~ ERROR avoid using labels containing only the digits | ||
asm!("1: jmp 1b"); //~ ERROR avoid using labels containing only the digits | ||
asm!("10: jmp 10b"); //~ ERROR avoid using labels containing only the digits | ||
asm!("01: jmp 01b"); //~ ERROR avoid using labels containing only the digits | ||
asm!("1001101: jmp 1001101b"); //~ ERROR avoid using labels containing only the digits | ||
} | ||
} |
This file contains 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,43 @@ | ||
error: avoid using labels containing only the digits `0` and `1` in inline assembly | ||
--> $DIR/binary_asm_labels.rs:11:15 | ||
| | ||
LL | asm!("0: jmp 0b"); | ||
| ^ use a different label that doesn't start with `0` or `1` | ||
| | ||
= note: an LLVM bug makes these labels ambiguous with a binary literal number | ||
= note: `#[deny(binary_asm_labels)]` on by default | ||
|
||
error: avoid using labels containing only the digits `0` and `1` in inline assembly | ||
--> $DIR/binary_asm_labels.rs:12:15 | ||
| | ||
LL | asm!("1: jmp 1b"); | ||
| ^ use a different label that doesn't start with `0` or `1` | ||
| | ||
= note: an LLVM bug makes these labels ambiguous with a binary literal number | ||
|
||
error: avoid using labels containing only the digits `0` and `1` in inline assembly | ||
--> $DIR/binary_asm_labels.rs:13:15 | ||
| | ||
LL | asm!("10: jmp 10b"); | ||
| ^^ use a different label that doesn't start with `0` or `1` | ||
| | ||
= note: an LLVM bug makes these labels ambiguous with a binary literal number | ||
|
||
error: avoid using labels containing only the digits `0` and `1` in inline assembly | ||
--> $DIR/binary_asm_labels.rs:14:15 | ||
| | ||
LL | asm!("01: jmp 01b"); | ||
| ^^ use a different label that doesn't start with `0` or `1` | ||
| | ||
= note: an LLVM bug makes these labels ambiguous with a binary literal number | ||
|
||
error: avoid using labels containing only the digits `0` and `1` in inline assembly | ||
--> $DIR/binary_asm_labels.rs:15:15 | ||
| | ||
LL | asm!("1001101: jmp 1001101b"); | ||
| ^^^^^^^ use a different label that doesn't start with `0` or `1` | ||
| | ||
= note: an LLVM bug makes these labels ambiguous with a binary literal number | ||
|
||
error: aborting due to 5 previous errors | ||
|
Oops, something went wrong.