-
Notifications
You must be signed in to change notification settings - Fork 13.3k
in asm!() using a local numeric label made of all 0's and 1's gives a confusing error #94426
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
@rustbot claim |
Documenting something that isn't explicitly stated here: this is an issue specifically related to the use of Intel syntax, because (AFAICT) LLVM doesn't have this issue for AT&T syntax. This seems like something that, eventually, we could try to get a fix for into LLVM. We would need an assembly dialect option that either handles binary numbers differently or handles backwards labels differently. |
…estebank add lint for inline asm labels that look like binary fixes rust-lang#94426 Due to a bug/feature in LLVM, labels composed of only the digits `0` and `1` can sometimes be confused with binary literals, even if a binary literal would not be valid in that position. This PR adds detection for such labels and also as a drive-by change, adds a note to cases such as `asm!(include_str!("file"))` that the label that it found came from an expansion of a macro, it wasn't found in the source code. I expect this PR to upset some people that were using labels `0:` or `1:` without issue because they never hit the case where LLVM got it wrong, but adding a heuristic to the lint to prevent this is not feasible - it would involve writing a whole assembly parser for every target that we have assembly support for. [zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/238009-t-compiler.2Fmeetings/topic/.5Bweekly.5D.202024-06-20/near/445870628) r? `@estebank`
Rollup merge of rust-lang#126922 - asquared31415:asm_binary_label, r=estebank add lint for inline asm labels that look like binary fixes rust-lang#94426 Due to a bug/feature in LLVM, labels composed of only the digits `0` and `1` can sometimes be confused with binary literals, even if a binary literal would not be valid in that position. This PR adds detection for such labels and also as a drive-by change, adds a note to cases such as `asm!(include_str!("file"))` that the label that it found came from an expansion of a macro, it wasn't found in the source code. I expect this PR to upset some people that were using labels `0:` or `1:` without issue because they never hit the case where LLVM got it wrong, but adding a heuristic to the lint to prevent this is not feasible - it would involve writing a whole assembly parser for every target that we have assembly support for. [zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/238009-t-compiler.2Fmeetings/topic/.5Bweekly.5D.202024-06-20/near/445870628) r? ``@estebank``
While the diagnostics side of this is fixed and so this issue should remain closed, I think that the underlying bug that prevents these labels from being usable should be tracked somewhere, does anyone know if we already have an issue for that underlying bug? |
@asquared31415 I don't think we have an issue for that. We probably should, but ultimately I think we can't fix it without some upstream support in LLVM. (Assuming we continue to not attempt to parse all assembly ourselves.) |
Here's a function that jumps to a local numberic label inside of
asm!
:As per Rust By Example, we use
2:
as a local label there to work around an LLVM bug that mistakes labels like0:
,1:
, or10:
for binary. This example works. However, if we don't know about this rule, and we try to use0:
instead, the error we get is confusing:Using
1:
is the same:It would be pretty great to have a hint here like "
0:
and1:
aren't valid local labels unfortunately, so just start with2:
".The text was updated successfully, but these errors were encountered: