Skip to content

Commit 9387a75

Browse files
committed
Change binary_asm_labels to only fire on x86 and x86_64
In <#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.
1 parent 5753b30 commit 9387a75

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

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
}
+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)