Skip to content

Commit a9b2bfb

Browse files
committed
Auto merge of #89937 - JohnTitor:fix-89875, r=Amanieu
Properly check `target_features` not to trigger an assertion Fixes #89875 I think it should be a condition instead of an assertion to check if it's a register as it's possible that `reg` is a register class. Also, this isn't related to the issue directly, but `is_target_supported` doesn't check `target_features` attributes. Is there any way to check it on rustc_codegen_llvm? r? `@Amanieu`
2 parents e269e6b + 12647ea commit a9b2bfb

File tree

6 files changed

+28
-9
lines changed

6 files changed

+28
-9
lines changed

compiler/rustc_ast_lowering/src/asm.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use std::fmt::Write;
1111

1212
impl<'a, 'hir> LoweringContext<'a, 'hir> {
1313
crate fn lower_inline_asm(&mut self, sp: Span, asm: &InlineAsm) -> &'hir hir::InlineAsm<'hir> {
14-
// Rustdoc needs to support asm! from foriegn architectures: don't try
15-
// lowering the register contraints in this case.
14+
// Rustdoc needs to support asm! from foreign architectures: don't try
15+
// lowering the register constraints in this case.
1616
let asm_arch = if self.sess.opts.actually_rustdoc { None } else { self.sess.asm_arch };
1717
if asm_arch.is_none() && !self.sess.opts.actually_rustdoc {
1818
struct_span_err!(self.sess, sp, E0472, "inline assembly is unsupported on this target")
@@ -214,9 +214,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
214214
// means that we disallow passing a value in/out of the asm and
215215
// require that the operand name an explicit register, not a
216216
// register class.
217-
if reg_class.is_clobber_only(asm_arch.unwrap())
218-
&& !(op.is_clobber() && matches!(reg, asm::InlineAsmRegOrRegClass::Reg(_)))
219-
{
217+
if reg_class.is_clobber_only(asm_arch.unwrap()) && !op.is_clobber() {
220218
let msg = format!(
221219
"register class `{}` can only be used as a clobber, \
222220
not as an input or output",

compiler/rustc_codegen_gcc/src/asm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
118118
true
119119
}
120120

121-
fn codegen_inline_asm(&mut self, template: &[InlineAsmTemplatePiece], rust_operands: &[InlineAsmOperandRef<'tcx, Self>], options: InlineAsmOptions, _span: &[Span]) {
121+
fn codegen_inline_asm(&mut self, template: &[InlineAsmTemplatePiece], rust_operands: &[InlineAsmOperandRef<'tcx, Self>], options: InlineAsmOptions, _span: &[Span], _instance: Instance<'_>) {
122122
let asm_arch = self.tcx.sess.asm_arch.unwrap();
123123
let is_x86 = matches!(asm_arch, InlineAsmArch::X86 | InlineAsmArch::X86_64);
124124
let att_dialect = is_x86 && options.contains(InlineAsmOptions::ATT_SYNTAX);

compiler/rustc_codegen_llvm/src/asm.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_codegen_ssa::traits::*;
1313
use rustc_data_structures::fx::FxHashMap;
1414
use rustc_hir as hir;
1515
use rustc_middle::ty::layout::TyAndLayout;
16-
use rustc_middle::{bug, span_bug};
16+
use rustc_middle::{bug, span_bug, ty::Instance};
1717
use rustc_span::{Pos, Span, Symbol};
1818
use rustc_target::abi::*;
1919
use rustc_target::asm::*;
@@ -120,6 +120,7 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
120120
operands: &[InlineAsmOperandRef<'tcx, Self>],
121121
options: InlineAsmOptions,
122122
line_spans: &[Span],
123+
instance: Instance<'_>,
123124
) {
124125
let asm_arch = self.tcx.sess.asm_arch.unwrap();
125126

@@ -135,7 +136,10 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
135136
let is_target_supported = |reg_class: InlineAsmRegClass| {
136137
for &(_, feature) in reg_class.supported_types(asm_arch) {
137138
if let Some(feature) = feature {
138-
if self.tcx.sess.target_features.contains(&Symbol::intern(feature))
139+
let codegen_fn_attrs = self.tcx.codegen_fn_attrs(instance.def_id());
140+
let feature_name = Symbol::intern(feature);
141+
if self.tcx.sess.target_features.contains(&feature_name)
142+
|| codegen_fn_attrs.target_features.contains(&feature_name)
139143
{
140144
return true;
141145
}

compiler/rustc_codegen_ssa/src/mir/block.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
845845
options: ast::InlineAsmOptions,
846846
line_spans: &[Span],
847847
destination: Option<mir::BasicBlock>,
848+
instance: Instance<'_>,
848849
) {
849850
let span = terminator.source_info.span;
850851

@@ -898,7 +899,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
898899
})
899900
.collect();
900901

901-
bx.codegen_inline_asm(template, &operands, options, line_spans);
902+
bx.codegen_inline_asm(template, &operands, options, line_spans, instance);
902903

903904
if let Some(target) = destination {
904905
helper.funclet_br(self, &mut bx, target);
@@ -1029,6 +1030,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
10291030
options,
10301031
line_spans,
10311032
destination,
1033+
self.instance,
10321034
);
10331035
}
10341036
}

compiler/rustc_codegen_ssa/src/traits/asm.rs

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ pub trait AsmBuilderMethods<'tcx>: BackendTypes {
5858
operands: &[InlineAsmOperandRef<'tcx, Self>],
5959
options: InlineAsmOptions,
6060
line_spans: &[Span],
61+
instance: Instance<'_>,
6162
);
6263
}
6364

src/test/ui/asm/x86_64/issue-89875.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// build-pass
2+
// only-x86_64
3+
4+
#![feature(asm, target_feature_11)]
5+
6+
#[target_feature(enable = "avx")]
7+
fn main() {
8+
unsafe {
9+
asm!(
10+
"/* {} */",
11+
out(ymm_reg) _,
12+
);
13+
}
14+
}

0 commit comments

Comments
 (0)