Skip to content

Commit fb751e0

Browse files
Rollup merge of rust-lang#127935 - tgross35:binary_asm_labels-x86-only, r=estebank
Change `binary_asm_labels` to only fire on x86 and x86_64 In <rust-lang#126922>, the `binary_asm_labels` lint was added which flags labels such as `0:` and `1:`. Before that change, LLVM was giving a confusing error on x86/x86_64 because of an incorrect interpretation. However, targets other than x86 and x86_64 never had the error message and have not been a problem. This means that the lint was causing code that previously worked to start failing (e.g. `compiler_builtins`), rather than only providing a more clear messages where there has always been an error. Adjust the lint to only fire on x86 and x86_64 assembly to avoid this regression. Also update the help message. Fixes: rust-lang#127821
2 parents 6bcfb73 + 8410348 commit fb751e0

File tree

5 files changed

+54
-17
lines changed

5 files changed

+54
-17
lines changed

compiler/rustc_lint/messages.ftl

+3-2
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,9 @@ lint_inner_macro_attribute_unstable = inner macro attributes are unstable
403403
404404
lint_invalid_asm_label_binary = avoid using labels containing only the digits `0` and `1` in inline assembly
405405
.label = use a different label that doesn't start with `0` or `1`
406-
.note = an LLVM bug makes these labels ambiguous with a binary literal number
407-
.note = see <https://bugs.llvm.org/show_bug.cgi?id=36144> for more information
406+
.help = start numbering with `2` instead
407+
.note1 = an LLVM bug makes these labels ambiguous with a binary literal number on x86
408+
.note2 = see <https://github.com/llvm/llvm-project/issues/99547> for more information
408409
409410
lint_invalid_asm_label_format_arg = avoid using named labels in inline assembly
410411
.help = only local labels of the form `<number>:` should be used in inline asm

compiler/rustc_lint/src/builtin.rs

+16-9
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ use rustc_span::source_map::Spanned;
6666
use rustc_span::symbol::{kw, sym, Ident, Symbol};
6767
use rustc_span::{BytePos, InnerSpan, Span};
6868
use rustc_target::abi::Abi;
69+
use rustc_target::asm::InlineAsmArch;
6970
use rustc_trait_selection::infer::{InferCtxtExt, TyCtxtInferExt};
7071
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _;
7172
use rustc_trait_selection::traits::{self, misc::type_allowed_to_implement_copy};
@@ -2908,16 +2909,22 @@ impl<'tcx> LateLintPass<'tcx> for AsmLabels {
29082909
InvalidAsmLabel::FormatArg { missing_precise_span },
29092910
);
29102911
}
2911-
AsmLabelKind::Binary => {
2912-
// the binary asm issue only occurs when using intel syntax
2913-
if !options.contains(InlineAsmOptions::ATT_SYNTAX) {
2914-
cx.emit_span_lint(
2915-
BINARY_ASM_LABELS,
2916-
span,
2917-
InvalidAsmLabel::Binary { missing_precise_span, span },
2918-
)
2919-
}
2912+
// the binary asm issue only occurs when using intel syntax on x86 targets
2913+
AsmLabelKind::Binary
2914+
if !options.contains(InlineAsmOptions::ATT_SYNTAX)
2915+
&& matches!(
2916+
cx.tcx.sess.asm_arch,
2917+
Some(InlineAsmArch::X86 | InlineAsmArch::X86_64) | None
2918+
) =>
2919+
{
2920+
cx.emit_span_lint(
2921+
BINARY_ASM_LABELS,
2922+
span,
2923+
InvalidAsmLabel::Binary { missing_precise_span, span },
2924+
)
29202925
}
2926+
// No lint on anything other than x86
2927+
AsmLabelKind::Binary => (),
29212928
};
29222929
}
29232930
}

compiler/rustc_lint/src/lints.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2074,7 +2074,9 @@ pub enum InvalidAsmLabel {
20742074
missing_precise_span: bool,
20752075
},
20762076
#[diag(lint_invalid_asm_label_binary)]
2077-
#[note]
2077+
#[help]
2078+
#[note(lint_note1)]
2079+
#[note(lint_note2)]
20782080
Binary {
20792081
#[note(lint_invalid_asm_label_no_span)]
20802082
missing_precise_span: bool,

tests/ui/asm/binary_asm_labels.stderr

+15-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ error: avoid using labels containing only the digits `0` and `1` in inline assem
44
LL | asm!("0: jmp 0b");
55
| ^ use a different label that doesn't start with `0` or `1`
66
|
7-
= note: an LLVM bug makes these labels ambiguous with a binary literal number
7+
= help: start numbering with `2` instead
8+
= note: an LLVM bug makes these labels ambiguous with a binary literal number on x86
9+
= note: see <https://github.com/llvm/llvm-project/issues/99547> for more information
810
= note: `#[deny(binary_asm_labels)]` on by default
911

1012
error: avoid using labels containing only the digits `0` and `1` in inline assembly
@@ -13,31 +15,39 @@ error: avoid using labels containing only the digits `0` and `1` in inline assem
1315
LL | asm!("1: jmp 1b");
1416
| ^ use a different label that doesn't start with `0` or `1`
1517
|
16-
= note: an LLVM bug makes these labels ambiguous with a binary literal number
18+
= help: start numbering with `2` instead
19+
= note: an LLVM bug makes these labels ambiguous with a binary literal number on x86
20+
= note: see <https://github.com/llvm/llvm-project/issues/99547> for more information
1721

1822
error: avoid using labels containing only the digits `0` and `1` in inline assembly
1923
--> $DIR/binary_asm_labels.rs:13:15
2024
|
2125
LL | asm!("10: jmp 10b");
2226
| ^^ use a different label that doesn't start with `0` or `1`
2327
|
24-
= note: an LLVM bug makes these labels ambiguous with a binary literal number
28+
= help: start numbering with `2` instead
29+
= note: an LLVM bug makes these labels ambiguous with a binary literal number on x86
30+
= note: see <https://github.com/llvm/llvm-project/issues/99547> for more information
2531

2632
error: avoid using labels containing only the digits `0` and `1` in inline assembly
2733
--> $DIR/binary_asm_labels.rs:14:15
2834
|
2935
LL | asm!("01: jmp 01b");
3036
| ^^ use a different label that doesn't start with `0` or `1`
3137
|
32-
= note: an LLVM bug makes these labels ambiguous with a binary literal number
38+
= help: start numbering with `2` instead
39+
= note: an LLVM bug makes these labels ambiguous with a binary literal number on x86
40+
= note: see <https://github.com/llvm/llvm-project/issues/99547> for more information
3341

3442
error: avoid using labels containing only the digits `0` and `1` in inline assembly
3543
--> $DIR/binary_asm_labels.rs:15:15
3644
|
3745
LL | asm!("1001101: jmp 1001101b");
3846
| ^^^^^^^ use a different label that doesn't start with `0` or `1`
3947
|
40-
= note: an LLVM bug makes these labels ambiguous with a binary literal number
48+
= help: start numbering with `2` instead
49+
= note: an LLVM bug makes these labels ambiguous with a binary literal number on x86
50+
= note: see <https://github.com/llvm/llvm-project/issues/99547> for more information
4151

4252
error: aborting due to 5 previous errors
4353

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@ build-pass
2+
//@ only-aarch64
3+
4+
// The `binary_asm_labels` lint should only be raised on `x86`. Make sure it
5+
// doesn't get raised on other platforms.
6+
7+
use std::arch::asm;
8+
9+
fn main() {
10+
unsafe {
11+
asm!("0: bl 0b");
12+
asm!("1: bl 1b");
13+
asm!("10: bl 10b");
14+
asm!("01: bl 01b");
15+
asm!("1001101: bl 1001101b");
16+
}
17+
}

0 commit comments

Comments
 (0)