From 5594310cd37e0ce944b91641216fdac464be9978 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 31 Jul 2026 21:50:05 +0200 Subject: [PATCH 1/2] target_featurs: avx2 and probably all of sse is incompatible with soft-float ABI --- compiler/rustc_codegen_ssa/src/diagnostics.rs | 6 +++ .../rustc_codegen_ssa/src/target_features.rs | 13 +++++- compiler/rustc_lint_defs/src/builtin.rs | 40 +++++++++++++++++++ compiler/rustc_target/src/target_features.rs | 8 +++- ...rget-feature-attribute-fcw.aarch64.stderr} | 20 +++++----- ...compatible-target-feature-attribute-fcw.rs | 18 ++++++--- ...target-feature-attribute-fcw.x86_64.stderr | 31 ++++++++++++++ 7 files changed, 117 insertions(+), 19 deletions(-) rename tests/ui/target-feature/{abi-incompatible-target-feature-attribute-fcw.stderr => abi-incompatible-target-feature-attribute-fcw.aarch64.stderr} (60%) create mode 100644 tests/ui/target-feature/abi-incompatible-target-feature-attribute-fcw.x86_64.stderr diff --git a/compiler/rustc_codegen_ssa/src/diagnostics.rs b/compiler/rustc_codegen_ssa/src/diagnostics.rs index e6aab553072f2..f79a26ee6f3b8 100644 --- a/compiler/rustc_codegen_ssa/src/diagnostics.rs +++ b/compiler/rustc_codegen_ssa/src/diagnostics.rs @@ -1197,6 +1197,12 @@ pub(crate) struct XcrunSdkPathWarning { #[diag("enabling the `neon` target feature on the current target is unsound due to ABI issues")] pub(crate) struct Aarch64SoftfloatNeon; +#[derive(Diagnostic)] +#[diag( + "enabling the `sse` target feature on the current target is unsupported due to LLVM backend issues" +)] +pub(crate) struct X86SoftfloatSse; + #[derive(Diagnostic)] #[diag("ignoring feature with missing prefix in `-Ctarget-feature`: `{$feature}`")] #[note("features must begin with a `+` to enable or `-` to disable it")] diff --git a/compiler/rustc_codegen_ssa/src/target_features.rs b/compiler/rustc_codegen_ssa/src/target_features.rs index 8f459e5a218d2..5f9a67271b542 100644 --- a/compiler/rustc_codegen_ssa/src/target_features.rs +++ b/compiler/rustc_codegen_ssa/src/target_features.rs @@ -8,7 +8,7 @@ use rustc_middle::query::Providers; use rustc_middle::ty::TyCtxt; use rustc_session::Session; use rustc_session::diagnostics::feature_err; -use rustc_session::lint::builtin::AARCH64_SOFTFLOAT_NEON; +use rustc_session::lint::builtin::{AARCH64_SOFTFLOAT_NEON, X86_SOFTFLOAT_SSE}; use rustc_span::{Span, Symbol, edit_distance, sym}; use rustc_target::spec::{Arch, SanitizerSet}; use rustc_target::target_features::{RUSTC_SPECIFIC_FEATURES, Stability}; @@ -99,6 +99,8 @@ pub(crate) fn from_target_feature_attr( if abi_feature_constraints.incompatible.contains(&name.as_str()) { // For "neon" specifically, we emit an FCW instead of a hard error. // See . + // Similar for "sse" on x86. + // See . if tcx.sess.target.arch == Arch::AArch64 && name.as_str() == "neon" { tcx.emit_node_span_lint( AARCH64_SOFTFLOAT_NEON, @@ -106,6 +108,15 @@ pub(crate) fn from_target_feature_attr( feature_span, diagnostics::Aarch64SoftfloatNeon, ); + } else if matches!(tcx.sess.target.arch, Arch::X86 | Arch::X86_64) + && name.as_str() == "sse" + { + tcx.emit_node_span_lint( + X86_SOFTFLOAT_SSE, + tcx.local_def_id_to_hir_id(did), + feature_span, + diagnostics::X86SoftfloatSse, + ); } else { tcx.dcx().emit_err(diagnostics::ForbiddenTargetFeatureAttr { span: feature_span, diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index da2220cf7a5fd..91bfbd7821a85 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -157,6 +157,7 @@ pub mod hardwired { USELESS_DEPRECATED, VARARGS_WITHOUT_PATTERN, WARNINGS, + X86_SOFTFLOAT_SSE, // tidy-alphabetical-end ] } @@ -5378,6 +5379,45 @@ declare_lint! { }; } +declare_lint! { + /// The `x86_softfloat_sse` lint detects usage of `#[target_feature(enable = "sse")]` or target + /// features that imply SSE on softfloat x86 and x86-64 targets. Enabling this target feature + /// in a soft-float configuration is not supported by LLVM and can lead to crashes. + /// + /// ### Example + /// + /// ```rust,ignore (needs x86_64-unknown-none) + /// #[target_feature(enable = "avx")] + /// fn with_avx() {} + /// ``` + /// + /// This will produce: + /// + /// ```text + /// error: enabling the `sse` target feature on the current target is unsupported due to LLVM backend issues + /// --> $DIR/abi-incompatible-target-feature-attribute-fcw.rs:11:18 + /// | + /// | #[target_feature(enable = "avx")] + /// | ^^^^^^^^^^^^^^^ + /// | + /// = warning: 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 #117938 + /// ``` + /// + /// ### Explanation + /// + /// LLVM does not support combining the `soft-float` target feature (which is implicitly enabled + /// on these targets) with `sse`. This can lead to crashes of the backend. To prevent that, + /// Rust is turning that combination into an error. + pub X86_SOFTFLOAT_SSE, + Warn, + "detects code that could be affected by LLVM backend issues on x86 softfloat targets", + @future_incompatible = FutureIncompatibleInfo { + reason: fcw!(FutureReleaseError #117938), + report_in_deps: true, + }; +} + declare_lint! { /// The `tail_call_track_caller` lint detects usage of `become` attempting to tail call /// a function marked with `#[track_caller]`. diff --git a/compiler/rustc_target/src/target_features.rs b/compiler/rustc_target/src/target_features.rs index ce09972396e56..e37ddffe55314 100644 --- a/compiler/rustc_target/src/target_features.rs +++ b/compiler/rustc_target/src/target_features.rs @@ -1250,7 +1250,9 @@ impl Target { // `x87` and all other FPU features so those do not matter. // Note that this one requirement is the entire implementation of the ABI! // LLVM handles the rest. - FeatureConstraints { required: &["soft-float"], incompatible: &[] } + // We mark "sse" as incompatible since LLVM likes to crash when both + // "soft-float" and "sse" are enabled. + FeatureConstraints { required: &["soft-float"], incompatible: &["sse"] } } _ => unreachable!(), } @@ -1271,7 +1273,9 @@ impl Target { // `x87` and all other FPU features so those do not matter. // Note that this one requirement is the entire implementation of the ABI! // LLVM handles the rest. - FeatureConstraints { required: &["soft-float"], incompatible: &[] } + // We mark "sse" as incompatible since LLVM likes to crash when both + // "soft-float" and "sse" are enabled. + FeatureConstraints { required: &["soft-float"], incompatible: &["sse"] } } _ => unreachable!(), } diff --git a/tests/ui/target-feature/abi-incompatible-target-feature-attribute-fcw.stderr b/tests/ui/target-feature/abi-incompatible-target-feature-attribute-fcw.aarch64.stderr similarity index 60% rename from tests/ui/target-feature/abi-incompatible-target-feature-attribute-fcw.stderr rename to tests/ui/target-feature/abi-incompatible-target-feature-attribute-fcw.aarch64.stderr index 9595d1aba477f..72828f701d66f 100644 --- a/tests/ui/target-feature/abi-incompatible-target-feature-attribute-fcw.stderr +++ b/tests/ui/target-feature/abi-incompatible-target-feature-attribute-fcw.aarch64.stderr @@ -1,31 +1,31 @@ error: enabling the `neon` target feature on the current target is unsound due to ABI issues - --> $DIR/abi-incompatible-target-feature-attribute-fcw.rs:13:18 + --> $DIR/abi-incompatible-target-feature-attribute-fcw.rs:16:36 | -LL | #[target_feature(enable = "neon")] - | ^^^^^^^^^^^^^^^ +LL | #[cfg_attr(aarch64, target_feature(enable = "neon"))] + | ^^^^^^^^^^^^^^^ | = warning: 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 #134375 note: the lint level is defined here - --> $DIR/abi-incompatible-target-feature-attribute-fcw.rs:8:9 + --> $DIR/abi-incompatible-target-feature-attribute-fcw.rs:11:9 | -LL | #![deny(aarch64_softfloat_neon)] +LL | #![deny(aarch64_softfloat_neon, x86_softfloat_sse)] | ^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 1 previous error Future incompatibility report: Future breakage diagnostic: error: enabling the `neon` target feature on the current target is unsound due to ABI issues - --> $DIR/abi-incompatible-target-feature-attribute-fcw.rs:13:18 + --> $DIR/abi-incompatible-target-feature-attribute-fcw.rs:16:36 | -LL | #[target_feature(enable = "neon")] - | ^^^^^^^^^^^^^^^ +LL | #[cfg_attr(aarch64, target_feature(enable = "neon"))] + | ^^^^^^^^^^^^^^^ | = warning: 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 #134375 note: the lint level is defined here - --> $DIR/abi-incompatible-target-feature-attribute-fcw.rs:8:9 + --> $DIR/abi-incompatible-target-feature-attribute-fcw.rs:11:9 | -LL | #![deny(aarch64_softfloat_neon)] +LL | #![deny(aarch64_softfloat_neon, x86_softfloat_sse)] | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/target-feature/abi-incompatible-target-feature-attribute-fcw.rs b/tests/ui/target-feature/abi-incompatible-target-feature-attribute-fcw.rs index dba9e2366d9e9..937c8d93ae940 100644 --- a/tests/ui/target-feature/abi-incompatible-target-feature-attribute-fcw.rs +++ b/tests/ui/target-feature/abi-incompatible-target-feature-attribute-fcw.rs @@ -1,16 +1,22 @@ //@ compile-flags: --crate-type=lib -//@ compile-flags: --target=aarch64-unknown-none-softfloat -//@ needs-llvm-components: aarch64 +//@ revisions: aarch64 x86_64 +//@[aarch64] compile-flags: --target=aarch64-unknown-none-softfloat +//@[aarch64] needs-llvm-components: aarch64 +//@[x86_64] compile-flags: --target=x86_64-unknown-none +//@[x86_64] needs-llvm-components: x86 //@ add-minicore //@ ignore-backends: gcc #![feature(no_core)] #![no_core] -#![deny(aarch64_softfloat_neon)] +#![deny(aarch64_softfloat_neon, x86_softfloat_sse)] extern crate minicore; use minicore::*; -#[target_feature(enable = "neon")] -//~^ERROR: enabling the `neon` target feature on the current target is unsound -//~|WARN: previously accepted +#[cfg_attr(aarch64, target_feature(enable = "neon"))] +//[aarch64]~^ERROR: enabling the `neon` target feature on the current target is unsound +//[aarch64]~|WARN: previously accepted +#[cfg_attr(x86_64, target_feature(enable = "avx"))] +//[x86_64]~^ERROR: enabling the `sse` target feature on the current target is unsupported +//[x86_64]~|WARN: previously accepted pub unsafe fn my_fun() {} diff --git a/tests/ui/target-feature/abi-incompatible-target-feature-attribute-fcw.x86_64.stderr b/tests/ui/target-feature/abi-incompatible-target-feature-attribute-fcw.x86_64.stderr new file mode 100644 index 0000000000000..52f577b02bae7 --- /dev/null +++ b/tests/ui/target-feature/abi-incompatible-target-feature-attribute-fcw.x86_64.stderr @@ -0,0 +1,31 @@ +error: enabling the `sse` target feature on the current target is unsupported due to LLVM backend issues + --> $DIR/abi-incompatible-target-feature-attribute-fcw.rs:19:35 + | +LL | #[cfg_attr(x86_64, target_feature(enable = "avx"))] + | ^^^^^^^^^^^^^^ + | + = warning: 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 #117938 +note: the lint level is defined here + --> $DIR/abi-incompatible-target-feature-attribute-fcw.rs:11:33 + | +LL | #![deny(aarch64_softfloat_neon, x86_softfloat_sse)] + | ^^^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + +Future incompatibility report: Future breakage diagnostic: +error: enabling the `sse` target feature on the current target is unsupported due to LLVM backend issues + --> $DIR/abi-incompatible-target-feature-attribute-fcw.rs:19:35 + | +LL | #[cfg_attr(x86_64, target_feature(enable = "avx"))] + | ^^^^^^^^^^^^^^ + | + = warning: 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 #117938 +note: the lint level is defined here + --> $DIR/abi-incompatible-target-feature-attribute-fcw.rs:11:33 + | +LL | #![deny(aarch64_softfloat_neon, x86_softfloat_sse)] + | ^^^^^^^^^^^^^^^^^ + From 2448058b758ba66e02d88cbc163ce1a945eeaec0 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 5 Aug 2026 09:08:52 +0200 Subject: [PATCH 2/2] make these lints deny-by-default --- compiler/rustc_lint_defs/src/builtin.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index 91bfbd7821a85..24516cdc0b915 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -5371,7 +5371,7 @@ declare_lint! { /// on this target due to this issue, but the problem was not known at the time of /// stabilization. pub AARCH64_SOFTFLOAT_NEON, - Warn, + Deny, "detects code that could be affected by ABI issues on aarch64 softfloat targets", @future_incompatible = FutureIncompatibleInfo { reason: fcw!(FutureReleaseError #134375), @@ -5410,7 +5410,7 @@ declare_lint! { /// on these targets) with `sse`. This can lead to crashes of the backend. To prevent that, /// Rust is turning that combination into an error. pub X86_SOFTFLOAT_SSE, - Warn, + Deny, "detects code that could be affected by LLVM backend issues on x86 softfloat targets", @future_incompatible = FutureIncompatibleInfo { reason: fcw!(FutureReleaseError #117938),