Skip to content

Commit 011b260

Browse files
committed
Require target features to match exactly during inlining
In general it is not correct to inline a callee with a target features that are subset of the callee. Require target features to match exactly during inlining. The exact match could be potentially relaxed, but this would require identifying specific feature that are allowed to differ, those that need to match, and those that can be present in caller but not in callee. This resolves MIR part of rust-lang#116573. For other concerns with respect to the previous implementation also see areInlineCompatible in LLVM.
1 parent b3cfd5b commit 011b260

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

compiler/rustc_mir_transform/src/inline.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -438,10 +438,8 @@ impl<'tcx> Inliner<'tcx> {
438438
return Err("incompatible instruction set");
439439
}
440440

441-
for feature in &callee_attrs.target_features {
442-
if !self.codegen_fn_attrs.target_features.contains(feature) {
443-
return Err("incompatible target feature");
444-
}
441+
if callee_attrs.target_features != self.codegen_fn_attrs.target_features {
442+
return Err("incompatible target features");
445443
}
446444

447445
Ok(())

tests/mir-opt/inline/inline_compatibility.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub unsafe fn f1() {
3131

3232
// CHECK-LABEL: fn f2()
3333
// CHECK: bb0: {
34-
// CHECK-NEXT: return;
34+
// CHECK-NEXT: nop()
3535
#[target_feature(enable = "avx")]
3636
pub unsafe fn f2() {
3737
nop();

0 commit comments

Comments
 (0)