Skip to content

Commit 3a6d0c2

Browse files
committed
various minor target feature cleanups
1 parent 29a5200 commit 3a6d0c2

File tree

10 files changed

+38
-54
lines changed

10 files changed

+38
-54
lines changed

compiler/rustc_codegen_gcc/src/gcc_util.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use smallvec::{SmallVec, smallvec};
66

77
fn gcc_features_by_flags(sess: &Session, features: &mut Vec<String>) {
88
target_features::retpoline_features_by_flags(sess, features);
9+
// FIXME: LLVM also sets +reserve-x18 here under some conditions.
910
}
1011

1112
/// The list of GCC features computed from CLI flags (`-Ctarget-cpu`, `-Ctarget-feature`,
@@ -59,8 +60,6 @@ pub(crate) fn global_gcc_features(sess: &Session, diagnostics: bool) -> Vec<Stri
5960

6061
gcc_features_by_flags(sess, &mut features);
6162

62-
// FIXME: LLVM also sets +reserve-x18 here under some conditions.
63-
6463
features
6564
}
6665

compiler/rustc_codegen_llvm/src/llvm_util.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,15 @@ pub(crate) fn target_cpu(sess: &Session) -> &str {
625625
/// The target features for compiler flags other than `-Ctarget-features`.
626626
fn llvm_features_by_flags(sess: &Session, features: &mut Vec<String>) {
627627
target_features::retpoline_features_by_flags(sess, features);
628+
629+
// -Zfixed-x18
630+
if sess.opts.unstable_opts.fixed_x18 {
631+
if sess.target.arch != "aarch64" {
632+
sess.dcx().emit_fatal(errors::FixedX18InvalidArch { arch: &sess.target.arch });
633+
} else {
634+
features.push("+reserve-x18".into());
635+
}
636+
}
628637
}
629638

630639
/// The list of LLVM features computed from CLI flags (`-Ctarget-cpu`, `-Ctarget-feature`,
@@ -736,19 +745,10 @@ pub(crate) fn global_llvm_features(
736745
)
737746
},
738747
);
739-
740-
llvm_features_by_flags(sess, &mut features);
741748
}
742749

743-
// -Zfixed-x18
744-
// FIXME: merge with `llvm_features_by_flags`.
745-
if sess.opts.unstable_opts.fixed_x18 {
746-
if sess.target.arch != "aarch64" {
747-
sess.dcx().emit_fatal(errors::FixedX18InvalidArch { arch: &sess.target.arch });
748-
} else {
749-
features.push("+reserve-x18".into());
750-
}
751-
}
750+
// We add this in the "base target" so that these show up in `sess.unstable_target_features`.
751+
llvm_features_by_flags(sess, &mut features);
752752

753753
features
754754
}

compiler/rustc_codegen_ssa/src/target_features.rs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ use rustc_session::Session;
1212
use rustc_session::lint::builtin::AARCH64_SOFTFLOAT_NEON;
1313
use rustc_session::parse::feature_err;
1414
use rustc_span::{Span, Symbol, sym};
15-
use rustc_target::target_features::{
16-
self, RUSTC_SPECIAL_FEATURES, RUSTC_SPECIFIC_FEATURES, Stability,
17-
};
15+
use rustc_target::target_features::{self, RUSTC_SPECIFIC_FEATURES, Stability};
1816
use smallvec::SmallVec;
1917

2018
use crate::errors;
@@ -176,8 +174,18 @@ fn parse_rust_feature_flag<'a>(
176174

177175
for feature in sess.opts.cg.target_feature.split(',') {
178176
if let Some(base_feature) = feature.strip_prefix('+') {
177+
// Skip features that are not target features, but rustc features.
178+
if RUSTC_SPECIFIC_FEATURES.contains(&base_feature) {
179+
return;
180+
}
181+
179182
callback(base_feature, sess.target.implied_target_features(base_feature), true)
180183
} else if let Some(base_feature) = feature.strip_prefix('-') {
184+
// Skip features that are not target features, but rustc features.
185+
if RUSTC_SPECIFIC_FEATURES.contains(&base_feature) {
186+
return;
187+
}
188+
181189
// If `f1` implies `f2`, then `!f2` implies `!f1` -- this is standard logical
182190
// contraposition. So we have to find all the reverse implications of `base_feature` and
183191
// disable them, too.
@@ -229,15 +237,7 @@ pub fn cfg_target_feature(
229237
.target
230238
.rust_target_features()
231239
.iter()
232-
.filter(|(feature, _, _)| {
233-
// Skip checking special features, those are not known to the backend.
234-
if RUSTC_SPECIAL_FEATURES.contains(feature) {
235-
// FIXME: `true` here means we'll always think the feature is enabled.
236-
// Does that really make sense?
237-
return true;
238-
}
239-
target_base_has_feature(feature)
240-
})
240+
.filter(|(feature, _, _)| target_base_has_feature(feature))
241241
.map(|(feature, _, _)| Symbol::intern(feature))
242242
.collect();
243243

@@ -332,11 +332,6 @@ pub fn flag_to_backend_features<'a, const N: usize>(
332332
}
333333
},
334334
|base_feature, new_features, enable| {
335-
// Skip features that are meant for rustc, not the backend.
336-
if RUSTC_SPECIFIC_FEATURES.contains(&base_feature) {
337-
return;
338-
}
339-
340335
rust_features.extend(
341336
UnordSet::from(new_features).to_sorted_stable_ord().iter().map(|&&s| (enable, s)),
342337
);

compiler/rustc_target/src/target_features.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ use crate::spec::{FloatAbi, RustcAbi, Target};
1111
/// These exist globally and are not in the target-specific lists below.
1212
pub const RUSTC_SPECIFIC_FEATURES: &[&str] = &["crt-static"];
1313

14-
/// Features that require special handling when passing to LLVM:
15-
/// these are target-specific (i.e., must also be listed in the target-specific list below)
16-
/// but do not correspond to an LLVM target feature.
17-
pub const RUSTC_SPECIAL_FEATURES: &[&str] = &["backchain"];
18-
1914
/// Stability information for target features.
2015
#[derive(Debug, Copy, Clone)]
2116
pub enum Stability {
@@ -275,12 +270,7 @@ static AARCH64_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
275270
("rcpc3", Unstable(sym::aarch64_unstable_target_feature), &["rcpc2"]),
276271
// FEAT_RDM
277272
("rdm", Stable, &["neon"]),
278-
// This is needed for inline assembly, but shouldn't be stabilized as-is
279-
// since it should be enabled globally using -Zfixed-x18, not
280-
// #[target_feature].
281-
// Note that cfg(target_feature = "reserve-x18") is currently not set for
282-
// targets that reserve x18 by default.
283-
("reserve-x18", Unstable(sym::aarch64_unstable_target_feature), &[]),
273+
("reserve-x18", Forbidden { reason: "use `-Zfixed-x18` compiler flag instead" }, &[]),
284274
// FEAT_SB
285275
("sb", Stable, &[]),
286276
// FEAT_SHA1 & FEAT_SHA256
@@ -455,19 +445,17 @@ static X86_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
455445
("rdseed", Stable, &[]),
456446
(
457447
"retpoline-external-thunk",
458-
Stability::Forbidden {
459-
reason: "use `retpoline-external-thunk` target modifier flag instead",
460-
},
448+
Stability::Forbidden { reason: "use `-Zretpoline-external-thunk` compiler flag instead" },
461449
&[],
462450
),
463451
(
464452
"retpoline-indirect-branches",
465-
Stability::Forbidden { reason: "use `retpoline` target modifier flag instead" },
453+
Stability::Forbidden { reason: "use `-Zretpoline` compiler flag instead" },
466454
&[],
467455
),
468456
(
469457
"retpoline-indirect-calls",
470-
Stability::Forbidden { reason: "use `retpoline` target modifier flag instead" },
458+
Stability::Forbidden { reason: "use `-Zretpoline` compiler flag instead" },
471459
&[],
472460
),
473461
("rtm", Unstable(sym::rtm_target_feature), &[]),

tests/assembly/s390x-backchain-toggle.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//@ add-core-stubs
2-
//@ revisions: enable-backchain disable-backchain
2+
//@ revisions: enable-backchain disable-backchain default-backchain
33
//@ assembly-output: emit-asm
44
//@ compile-flags: -Copt-level=3 --crate-type=lib --target=s390x-unknown-linux-gnu
55
//@ needs-llvm-components: systemz
@@ -26,6 +26,8 @@ extern "C" fn test_backchain() -> i32 {
2626
// enable-backchain: stg [[REG1]], 0(%r15)
2727
// disable-backchain: aghi %r15, -160
2828
// disable-backchain-NOT: stg %r{{.*}}, 0(%r15)
29+
// default-backchain: aghi %r15, -160
30+
// default-backchain-NOT: stg %r{{.*}}, 0(%r15)
2931
unsafe {
3032
extern_func();
3133
}
@@ -35,6 +37,7 @@ extern "C" fn test_backchain() -> i32 {
3537
// Make sure that the expected return value is written into %r2 (return register):
3638
// enable-backchain-NEXT: lghi %r2, 1
3739
// disable-backchain: lghi %r2, 0
40+
// default-backchain: lghi %r2, 0
3841
#[cfg(target_feature = "backchain")]
3942
{
4043
1

tests/ui/check-cfg/target_feature.stderr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ LL | cfg!(target_feature = "_UNEXPECTED_VALUE");
211211
`reference-types`
212212
`relax`
213213
`relaxed-simd`
214-
`reserve-x18`
215214
`rtm`
216215
`sb`
217216
`scq`

tests/ui/target-feature/retpoline-target-feature-flag.by_feature1.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
warning: target feature `retpoline-external-thunk` cannot be enabled with `-Ctarget-feature`: use `retpoline-external-thunk` target modifier flag instead
1+
warning: target feature `retpoline-external-thunk` cannot be enabled with `-Ctarget-feature`: use `-Zretpoline-external-thunk` compiler flag instead
22
|
33
= note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
44
= note: for more information, see issue #116344 <https://github.com/rust-lang/rust/issues/116344>

tests/ui/target-feature/retpoline-target-feature-flag.by_feature2.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
warning: target feature `retpoline-indirect-branches` cannot be enabled with `-Ctarget-feature`: use `retpoline` target modifier flag instead
1+
warning: target feature `retpoline-indirect-branches` cannot be enabled with `-Ctarget-feature`: use `-Zretpoline` compiler flag instead
22
|
33
= note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
44
= note: for more information, see issue #116344 <https://github.com/rust-lang/rust/issues/116344>

tests/ui/target-feature/retpoline-target-feature-flag.by_feature3.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
warning: target feature `retpoline-indirect-calls` cannot be enabled with `-Ctarget-feature`: use `retpoline` target modifier flag instead
1+
warning: target feature `retpoline-indirect-calls` cannot be enabled with `-Ctarget-feature`: use `-Zretpoline` compiler flag instead
22
|
33
= note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
44
= note: for more information, see issue #116344 <https://github.com/rust-lang/rust/issues/116344>

tests/ui/target-feature/retpoline-target-feature-flag.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@
1818
#[lang = "sized"]
1919
pub trait Sized {}
2020

21-
//[by_feature1]~? WARN target feature `retpoline-external-thunk` cannot be enabled with `-Ctarget-feature`: use `retpoline-external-thunk` target modifier flag instead
22-
//[by_feature2]~? WARN target feature `retpoline-indirect-branches` cannot be enabled with `-Ctarget-feature`: use `retpoline` target modifier flag instead
23-
//[by_feature3]~? WARN target feature `retpoline-indirect-calls` cannot be enabled with `-Ctarget-feature`: use `retpoline` target modifier flag instead
21+
//[by_feature1]~? WARN target feature `retpoline-external-thunk` cannot be enabled with `-Ctarget-feature`
22+
//[by_feature2]~? WARN target feature `retpoline-indirect-branches` cannot be enabled with `-Ctarget-feature`
23+
//[by_feature3]~? WARN target feature `retpoline-indirect-calls` cannot be enabled with `-Ctarget-feature`

0 commit comments

Comments
 (0)