Skip to content

Commit 12647ea

Browse files
committed
Properly check target_features not to trigger an assertion
1 parent bd309e4 commit 12647ea

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

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

0 commit comments

Comments
 (0)