Skip to content

Commit 912b729

Browse files
committed
add ABI target features *before* -Ctarget-features
1 parent eb52742 commit 912b729

File tree

4 files changed

+19
-16
lines changed

4 files changed

+19
-16
lines changed

compiler/rustc_codegen_gcc/src/gcc_util.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,12 @@ pub(crate) fn global_gcc_features(sess: &Session, diagnostics: bool) -> Vec<Stri
154154
// we will silently correct them rather than silently producing wrong code.
155155
// (The target sanity check tries to catch this, but we can't know which features are
156156
// enabled in GCC by default so we can't be fully sure about that check.)
157-
for feature in abi_enable {
158-
all_rust_features.push((true, feature));
159-
}
160-
for feature in abi_disable {
161-
all_rust_features.push((false, feature));
162-
}
157+
// We add these at the beginning of the list so that `-Ctarget-features` can
158+
// still override it... that's unsound, but more compatible with past behavior.
159+
all_rust_features.splice(
160+
0..0,
161+
abi_enable.iter().map(|&f| (true, f)).chain(abi_disable.iter().map(|&f| (false, f))),
162+
);
163163

164164
// Translate this into GCC features.
165165
let feats = all_rust_features

compiler/rustc_codegen_llvm/src/llvm_util.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -779,12 +779,12 @@ pub(crate) fn global_llvm_features(
779779
// we will silently correct them rather than silently producing wrong code.
780780
// (The target sanity check tries to catch this, but we can't know which features are
781781
// enabled in LLVM by default so we can't be fully sure about that check.)
782-
for feature in abi_enable {
783-
all_rust_features.push((true, feature));
784-
}
785-
for feature in abi_disable {
786-
all_rust_features.push((false, feature));
787-
}
782+
// We add these at the beginning of the list so that `-Ctarget-features` can
783+
// still override it... that's unsound, but more compatible with past behavior.
784+
all_rust_features.splice(
785+
0..0,
786+
abi_enable.iter().map(|&f| (true, f)).chain(abi_disable.iter().map(|&f| (false, f))),
787+
);
788788

789789
// Translate this into LLVM features.
790790
let feats = all_rust_features

compiler/rustc_target/src/target_features.rs

+3
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,9 @@ impl Target {
743743
/// the first list contains target features that must be enabled for ABI reasons,
744744
/// and the second list contains target feature that must be disabled for ABI reasons.
745745
///
746+
/// These features are automatically appended to whatever the target spec sats as default
747+
/// features for the target.
748+
///
746749
/// All features enabled/disabled via `-Ctarget-features` and `#[target_features]` are checked
747750
/// against this. We also check any implied features, based on the information above. If LLVM
748751
/// implicitly enables more implied features than we do, that could bypass this check!

tests/codegen/target-feature-overrides.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ pub unsafe fn banana() -> u32 {
3939
}
4040

4141
// CHECK: attributes [[APPLEATTRS]]
42-
// COMPAT-SAME: "target-features"="+avx,+avx2,{{.*}}"
43-
// INCOMPAT-SAME: "target-features"="-avx2,-avx,+x87,+sse2,+avx,{{.*}}"
42+
// COMPAT-SAME: "target-features"="+x87,+sse2,+avx,+avx2,{{.*}}"
43+
// INCOMPAT-SAME: "target-features"="+x87,+sse2,-avx2,-avx,+avx,{{.*}}"
4444
// CHECK: attributes [[BANANAATTRS]]
45-
// COMPAT-SAME: "target-features"="+avx,+avx2,{{.*}}"
46-
// INCOMPAT-SAME: "target-features"="-avx2,-avx,+x87,+sse2"
45+
// COMPAT-SAME: "target-features"="+x87,+sse2,+avx,+avx2,{{.*}}"
46+
// INCOMPAT-SAME: "target-features"="+x87,+sse2,-avx2,-avx"

0 commit comments

Comments
 (0)