Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions compiler/rustc_codegen_ssa/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
13 changes: 12 additions & 1 deletion compiler/rustc_codegen_ssa/src/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -99,13 +99,24 @@ 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 <https://github.com/rust-lang/rust/issues/134375>.
// Similar for "sse" on x86.
// See <https://github.com/rust-lang/rust/issues/117938>.
if tcx.sess.target.arch == Arch::AArch64 && name.as_str() == "neon" {
tcx.emit_node_span_lint(
AARCH64_SOFTFLOAT_NEON,
tcx.local_def_id_to_hir_id(did),
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,
Expand Down
40 changes: 40 additions & 0 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ pub mod hardwired {
USELESS_DEPRECATED,
VARARGS_WITHOUT_PATTERN,
WARNINGS,
X86_SOFTFLOAT_SSE,
// tidy-alphabetical-end
]
}
Expand Down Expand Up @@ -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.
Comment thread
workingjubilee marked this conversation as resolved.
///
/// ### 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 <https://github.com/rust-lang/rust/issues/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,
};
Comment thread
traviscross marked this conversation as resolved.
}

declare_lint! {
/// The `tail_call_track_caller` lint detects usage of `become` attempting to tail call
/// a function marked with `#[track_caller]`.
Expand Down
8 changes: 6 additions & 2 deletions compiler/rustc_target/src/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(),
}
Expand All @@ -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!(),
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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)]
| ^^^^^^^^^^^^^^^^^^^^^^

Original file line number Diff line number Diff line change
@@ -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() {}
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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)]
| ^^^^^^^^^^^^^^^^^

Loading