about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2024-12-26 19:47:41 +0100
committerRalf Jung <post@ralfj.de>2024-12-31 12:41:20 +0100
commiteb527424a5f0206a464d0968387d85636ac9d305 (patch)
treedd45b32bab6ad06c8b0f8d2393809fa07e5c8303
parent0a8cfc2f8f1343fc99f18ca3cad8e2d11f60d7d2 (diff)
downloadrust-eb527424a5f0206a464d0968387d85636ac9d305.tar.gz
rust-eb527424a5f0206a464d0968387d85636ac9d305.zip
x86-64 hardfloat actually requires sse2
-rw-r--r--compiler/rustc_codegen_gcc/src/gcc_util.rs18
-rw-r--r--compiler/rustc_codegen_llvm/src/llvm_util.rs19
-rw-r--r--compiler/rustc_target/src/target_features.rs11
-rw-r--r--tests/codegen/target-feature-overrides.rs4
-rw-r--r--tests/ui/target-feature/forbidden-hardfloat-target-feature-flag-disable-implied.rs10
-rw-r--r--tests/ui/target-feature/forbidden-hardfloat-target-feature-flag-disable-implied.stderr7
6 files changed, 54 insertions, 15 deletions
diff --git a/compiler/rustc_codegen_gcc/src/gcc_util.rs b/compiler/rustc_codegen_gcc/src/gcc_util.rs
index b0fd07827d6..3e579d75d86 100644
--- a/compiler/rustc_codegen_gcc/src/gcc_util.rs
+++ b/compiler/rustc_codegen_gcc/src/gcc_util.rs
@@ -129,12 +129,18 @@ pub(crate) fn global_gcc_features(sess: &Session, diagnostics: bool) -> Vec<Stri
                     });
                 }
             } else {
-                if abi_enable_set.contains(feature) {
-                    sess.dcx().emit_warn(ForbiddenCTargetFeature {
-                        feature,
-                        enabled: "disabled",
-                        reason: "this feature is required by the target ABI",
-                    });
+                // FIXME: we have to request implied features here since
+                // negative features do not handle implied features above.
+                #[allow(rustc::potential_query_instability)] // order does not matter
+                for &required in abi_enable_set.iter() {
+                    let implied = sess.target.implied_target_features(std::iter::once(required));
+                    if implied.contains(feature) {
+                        sess.dcx().emit_warn(ForbiddenCTargetFeature {
+                            feature,
+                            enabled: "disabled",
+                            reason: "this feature is required by the target ABI",
+                        });
+                    }
                 }
             }
 
diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs
index d4b2260123b..7fe0624e166 100644
--- a/compiler/rustc_codegen_llvm/src/llvm_util.rs
+++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs
@@ -753,12 +753,19 @@ pub(crate) fn global_llvm_features(
                         });
                     }
                 } else {
-                    if abi_enable_set.contains(feature) {
-                        sess.dcx().emit_warn(ForbiddenCTargetFeature {
-                            feature,
-                            enabled: "disabled",
-                            reason: "this feature is required by the target ABI",
-                        });
+                    // FIXME: we have to request implied features here since
+                    // negative features do not handle implied features above.
+                    #[allow(rustc::potential_query_instability)] // order does not matter
+                    for &required in abi_enable_set.iter() {
+                        let implied =
+                            sess.target.implied_target_features(std::iter::once(required));
+                        if implied.contains(feature) {
+                            sess.dcx().emit_warn(ForbiddenCTargetFeature {
+                                feature,
+                                enabled: "disabled",
+                                reason: "this feature is required by the target ABI",
+                            });
+                        }
                     }
                 }
 
diff --git a/compiler/rustc_target/src/target_features.rs b/compiler/rustc_target/src/target_features.rs
index 31e2cabed62..75055144c8f 100644
--- a/compiler/rustc_target/src/target_features.rs
+++ b/compiler/rustc_target/src/target_features.rs
@@ -753,7 +753,7 @@ impl Target {
         // "forbidden" in the list above to ensure that there is a consistent answer to the
         // questions "which ABI is used".
         match &*self.arch {
-            "x86" | "x86_64" => {
+            "x86" => {
                 // We support 2 ABIs, hardfloat (default) and softfloat.
                 if self.has_feature("soft-float") {
                     NOTHING
@@ -762,6 +762,15 @@ impl Target {
                     (&["x87"], &[])
                 }
             }
+            "x86_64" => {
+                // We support 2 ABIs, hardfloat (default) and softfloat.
+                if self.has_feature("soft-float") {
+                    NOTHING
+                } else {
+                    // Hardfloat ABI. x87 and SSE2 must be enabled.
+                    (&["x87", "sse2"], &[])
+                }
+            }
             "arm" => {
                 // We support 2 ABIs, hardfloat (default) and softfloat.
                 if self.has_feature("soft-float") {
diff --git a/tests/codegen/target-feature-overrides.rs b/tests/codegen/target-feature-overrides.rs
index f38a1ae72de..c4f9a8898a1 100644
--- a/tests/codegen/target-feature-overrides.rs
+++ b/tests/codegen/target-feature-overrides.rs
@@ -40,7 +40,7 @@ pub unsafe fn banana() -> u32 {
 
 // CHECK: attributes [[APPLEATTRS]]
 // COMPAT-SAME: "target-features"="+avx,+avx2,{{.*}}"
-// INCOMPAT-SAME: "target-features"="-avx2,-avx,+avx,{{.*}}"
+// INCOMPAT-SAME: "target-features"="-avx2,-avx,+x87,+sse2,+avx,{{.*}}"
 // CHECK: attributes [[BANANAATTRS]]
 // COMPAT-SAME: "target-features"="+avx,+avx2,{{.*}}"
-// INCOMPAT-SAME: "target-features"="-avx2,-avx"
+// INCOMPAT-SAME: "target-features"="-avx2,-avx,+x87,+sse2"
diff --git a/tests/ui/target-feature/forbidden-hardfloat-target-feature-flag-disable-implied.rs b/tests/ui/target-feature/forbidden-hardfloat-target-feature-flag-disable-implied.rs
new file mode 100644
index 00000000000..3d09217327a
--- /dev/null
+++ b/tests/ui/target-feature/forbidden-hardfloat-target-feature-flag-disable-implied.rs
@@ -0,0 +1,10 @@
+//@ compile-flags: --target=x86_64-unknown-linux-gnu --crate-type=lib
+//@ needs-llvm-components: x86
+//@ compile-flags: -Ctarget-feature=-sse
+// For now this is just a warning.
+//@ build-pass
+#![feature(no_core, lang_items)]
+#![no_core]
+
+#[lang = "sized"]
+pub trait Sized {}
diff --git a/tests/ui/target-feature/forbidden-hardfloat-target-feature-flag-disable-implied.stderr b/tests/ui/target-feature/forbidden-hardfloat-target-feature-flag-disable-implied.stderr
new file mode 100644
index 00000000000..72b2d03fe20
--- /dev/null
+++ b/tests/ui/target-feature/forbidden-hardfloat-target-feature-flag-disable-implied.stderr
@@ -0,0 +1,7 @@
+warning: target feature `sse` cannot be disabled with `-Ctarget-feature`: this feature is required by the target ABI
+   |
+   = note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+   = note: for more information, see issue #116344 <https://github.com/rust-lang/rust/issues/116344>
+
+warning: 1 warning emitted
+