about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTomasz Miąsko <tomasz.miasko@gmail.com>2023-10-20 00:00:00 +0000
committerTomasz Miąsko <tomasz.miasko@gmail.com>2023-10-24 22:49:15 +0200
commit011b260cc83713599c4a3ff9bb242f92ee792b7e (patch)
treec476315c8ff804ac24432e96f7f4327dd7897876
parentb3cfd5bb04d1622b4bd35da7983e29321be18e47 (diff)
downloadrust-011b260cc83713599c4a3ff9bb242f92ee792b7e.tar.gz
rust-011b260cc83713599c4a3ff9bb242f92ee792b7e.zip
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 #116573. For other concerns with respect to
the previous implementation also see areInlineCompatible in LLVM.
-rw-r--r--compiler/rustc_mir_transform/src/inline.rs6
-rw-r--r--tests/mir-opt/inline/inline_compatibility.rs2
2 files changed, 3 insertions, 5 deletions
diff --git a/compiler/rustc_mir_transform/src/inline.rs b/compiler/rustc_mir_transform/src/inline.rs
index 8b33e00c63c..277060573bc 100644
--- a/compiler/rustc_mir_transform/src/inline.rs
+++ b/compiler/rustc_mir_transform/src/inline.rs
@@ -438,10 +438,8 @@ impl<'tcx> Inliner<'tcx> {
             return Err("incompatible instruction set");
         }
 
-        for feature in &callee_attrs.target_features {
-            if !self.codegen_fn_attrs.target_features.contains(feature) {
-                return Err("incompatible target feature");
-            }
+        if callee_attrs.target_features != self.codegen_fn_attrs.target_features {
+            return Err("incompatible target features");
         }
 
         Ok(())
diff --git a/tests/mir-opt/inline/inline_compatibility.rs b/tests/mir-opt/inline/inline_compatibility.rs
index 8045ea39f95..3ad880715fe 100644
--- a/tests/mir-opt/inline/inline_compatibility.rs
+++ b/tests/mir-opt/inline/inline_compatibility.rs
@@ -31,7 +31,7 @@ pub unsafe fn f1() {
 
 // CHECK-LABEL: fn f2()
 // CHECK:       bb0: {
-// CHECK-NEXT:  return;
+// CHECK-NEXT:  nop()
 #[target_feature(enable = "avx")]
 pub unsafe fn f2() {
     nop();