Skip to content

Commit

Permalink
x86-64 hardfloat actually requires sse2
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Dec 26, 2024
1 parent 3065831 commit c221672
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 15 deletions.
18 changes: 12 additions & 6 deletions compiler/rustc_codegen_gcc/src/gcc_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
});
}
}
}

Expand Down
19 changes: 13 additions & 6 deletions compiler/rustc_codegen_llvm/src/llvm_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
});
}
}
}

Expand Down
11 changes: 10 additions & 1 deletion compiler/rustc_target/src/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,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
Expand All @@ -763,6 +763,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") {
Expand Down
4 changes: 2 additions & 2 deletions tests/codegen/target-feature-overrides.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Original file line number Diff line number Diff line change
@@ -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 {}
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c221672

Please sign in to comment.