Change binary_asm_labels to only fire on x86 and x86_64

In <https://github.com/rust-lang/rust/pull/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.
This commit is contained in:
Trevor Gross 2024-07-18 15:00:56 -05:00
parent 5753b30676
commit 9387a7523e
2 changed files with 33 additions and 9 deletions

View File

@ -66,6 +66,7 @@
use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::{BytePos, InnerSpan, Span}; use rustc_span::{BytePos, InnerSpan, Span};
use rustc_target::abi::Abi; use rustc_target::abi::Abi;
use rustc_target::asm::InlineAsmArch;
use rustc_trait_selection::infer::{InferCtxtExt, TyCtxtInferExt}; use rustc_trait_selection::infer::{InferCtxtExt, TyCtxtInferExt};
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _; use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _;
use rustc_trait_selection::traits::{self, misc::type_allowed_to_implement_copy}; use rustc_trait_selection::traits::{self, misc::type_allowed_to_implement_copy};
@ -2908,16 +2909,22 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>) {
InvalidAsmLabel::FormatArg { missing_precise_span }, InvalidAsmLabel::FormatArg { missing_precise_span },
); );
} }
AsmLabelKind::Binary => { // the binary asm issue only occurs when using intel syntax on x86 targets
// the binary asm issue only occurs when using intel syntax AsmLabelKind::Binary
if !options.contains(InlineAsmOptions::ATT_SYNTAX) { if !options.contains(InlineAsmOptions::ATT_SYNTAX)
&& matches!(
cx.tcx.sess.asm_arch,
Some(InlineAsmArch::X86 | InlineAsmArch::X86_64) | None
) =>
{
cx.emit_span_lint( cx.emit_span_lint(
BINARY_ASM_LABELS, BINARY_ASM_LABELS,
span, span,
InvalidAsmLabel::Binary { missing_precise_span, span }, InvalidAsmLabel::Binary { missing_precise_span, span },
) )
} }
} // No lint on anything other than x86
AsmLabelKind::Binary => (),
}; };
} }
} }

View File

@ -0,0 +1,17 @@
//@ build-pass
//@ only-aarch64
// The `binary_asm_labels` lint should only be raised on `x86`. Make sure it
// doesn't get raised on other platforms.
use std::arch::asm;
fn main() {
unsafe {
asm!("0: bl 0b");
asm!("1: bl 1b");
asm!("10: bl 10b");
asm!("01: bl 01b");
asm!("1001101: bl 1001101b");
}
}