Closed
Description
rustc 1.59.0 (9d1b2106e 2022-02-23)
Here's a function that jumps to a local numberic label inside of asm!
:
use std::arch::asm;
#[cfg(target_arch = "x86_64")]
fn main() {
let mut counter: u64 = 0;
unsafe {
asm!(
"2:",
"inc {counter}",
"cmp {counter}, 10",
"jnz 2b",
counter = inout(reg) counter,
);
}
dbg!(counter); // prints 10
}
As per Rust By Example, we use 2:
as a local label there to work around an LLVM bug that mistakes labels like 0:
, 1:
, or 10:
for binary. This example works. However, if we don't know about this rule, and we try to use 0:
instead, the error we get is confusing:
error: invalid operand for instruction
--> src/main.rs:11:14
|
11 | "jnz 0b",
| ^
|
note: instantiated into assembly here
--> <inline asm>:5:1
|
5 | jnz 0b
| ^
error: could not compile `scratch` due to previous error
Using 1:
is the same:
error: invalid operand for instruction
--> src/main.rs:11:14
|
11 | "jnz 1b",
| ^
|
note: instantiated into assembly here
--> <inline asm>:5:1
|
5 | jnz 1b
| ^
error: could not compile `scratch` due to previous error
It would be pretty great to have a hint here like "0:
and 1:
aren't valid local labels unfortunately, so just start with 2:
".
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: Inline assembly (`asm!(…)`)Diagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint; hard to understand for new users.Lint: LLVM parses labels like 0, 1, 10, 11, etc. oddlyRelevant to the compiler team, which will review and decide on the PR/issue.