various minor target feature cleanups

This commit is contained in:
Ralf Jung 2025-06-14 14:11:00 +02:00
parent 0c4b0f5726
commit a50a3b8e31
10 changed files with 38 additions and 54 deletions

View file

@ -6,6 +6,7 @@ use smallvec::{SmallVec, smallvec};
fn gcc_features_by_flags(sess: &Session, features: &mut Vec<String>) {
target_features::retpoline_features_by_flags(sess, features);
// FIXME: LLVM also sets +reserve-x18 here under some conditions.
}
/// 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
gcc_features_by_flags(sess, &mut features);
// FIXME: LLVM also sets +reserve-x18 here under some conditions.
features
}

View file

@ -625,6 +625,15 @@ pub(crate) fn target_cpu(sess: &Session) -> &str {
/// The target features for compiler flags other than `-Ctarget-features`.
fn llvm_features_by_flags(sess: &Session, features: &mut Vec<String>) {
target_features::retpoline_features_by_flags(sess, features);
// -Zfixed-x18
if sess.opts.unstable_opts.fixed_x18 {
if sess.target.arch != "aarch64" {
sess.dcx().emit_fatal(errors::FixedX18InvalidArch { arch: &sess.target.arch });
} else {
features.push("+reserve-x18".into());
}
}
}
/// The list of LLVM features computed from CLI flags (`-Ctarget-cpu`, `-Ctarget-feature`,
@ -736,19 +745,10 @@ pub(crate) fn global_llvm_features(
)
},
);
llvm_features_by_flags(sess, &mut features);
}
// -Zfixed-x18
// FIXME: merge with `llvm_features_by_flags`.
if sess.opts.unstable_opts.fixed_x18 {
if sess.target.arch != "aarch64" {
sess.dcx().emit_fatal(errors::FixedX18InvalidArch { arch: &sess.target.arch });
} else {
features.push("+reserve-x18".into());
}
}
// We add this in the "base target" so that these show up in `sess.unstable_target_features`.
llvm_features_by_flags(sess, &mut features);
features
}

View file

@ -12,9 +12,7 @@ use rustc_session::Session;
use rustc_session::lint::builtin::AARCH64_SOFTFLOAT_NEON;
use rustc_session::parse::feature_err;
use rustc_span::{Span, Symbol, sym};
use rustc_target::target_features::{
self, RUSTC_SPECIAL_FEATURES, RUSTC_SPECIFIC_FEATURES, Stability,
};
use rustc_target::target_features::{self, RUSTC_SPECIFIC_FEATURES, Stability};
use smallvec::SmallVec;
use crate::errors;
@ -176,8 +174,18 @@ fn parse_rust_feature_flag<'a>(
for feature in sess.opts.cg.target_feature.split(',') {
if let Some(base_feature) = feature.strip_prefix('+') {
// Skip features that are not target features, but rustc features.
if RUSTC_SPECIFIC_FEATURES.contains(&base_feature) {
return;
}
callback(base_feature, sess.target.implied_target_features(base_feature), true)
} else if let Some(base_feature) = feature.strip_prefix('-') {
// Skip features that are not target features, but rustc features.
if RUSTC_SPECIFIC_FEATURES.contains(&base_feature) {
return;
}
// If `f1` implies `f2`, then `!f2` implies `!f1` -- this is standard logical
// contraposition. So we have to find all the reverse implications of `base_feature` and
// disable them, too.
@ -229,15 +237,7 @@ pub fn cfg_target_feature(
.target
.rust_target_features()
.iter()
.filter(|(feature, _, _)| {
// Skip checking special features, those are not known to the backend.
if RUSTC_SPECIAL_FEATURES.contains(feature) {
// FIXME: `true` here means we'll always think the feature is enabled.
// Does that really make sense?
return true;
}
target_base_has_feature(feature)
})
.filter(|(feature, _, _)| target_base_has_feature(feature))
.map(|(feature, _, _)| Symbol::intern(feature))
.collect();
@ -332,11 +332,6 @@ pub fn flag_to_backend_features<'a, const N: usize>(
}
},
|base_feature, new_features, enable| {
// Skip features that are meant for rustc, not the backend.
if RUSTC_SPECIFIC_FEATURES.contains(&base_feature) {
return;
}
rust_features.extend(
UnordSet::from(new_features).to_sorted_stable_ord().iter().map(|&&s| (enable, s)),
);

View file

@ -11,11 +11,6 @@ use crate::spec::{FloatAbi, RustcAbi, Target};
/// These exist globally and are not in the target-specific lists below.
pub const RUSTC_SPECIFIC_FEATURES: &[&str] = &["crt-static"];
/// Features that require special handling when passing to LLVM:
/// these are target-specific (i.e., must also be listed in the target-specific list below)
/// but do not correspond to an LLVM target feature.
pub const RUSTC_SPECIAL_FEATURES: &[&str] = &["backchain"];
/// Stability information for target features.
#[derive(Debug, Copy, Clone)]
pub enum Stability {
@ -275,12 +270,7 @@ static AARCH64_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("rcpc3", Unstable(sym::aarch64_unstable_target_feature), &["rcpc2"]),
// FEAT_RDM
("rdm", Stable, &["neon"]),
// This is needed for inline assembly, but shouldn't be stabilized as-is
// since it should be enabled globally using -Zfixed-x18, not
// #[target_feature].
// Note that cfg(target_feature = "reserve-x18") is currently not set for
// targets that reserve x18 by default.
("reserve-x18", Unstable(sym::aarch64_unstable_target_feature), &[]),
("reserve-x18", Forbidden { reason: "use `-Zfixed-x18` compiler flag instead" }, &[]),
// FEAT_SB
("sb", Stable, &[]),
// FEAT_SHA1 & FEAT_SHA256
@ -455,19 +445,17 @@ static X86_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("rdseed", Stable, &[]),
(
"retpoline-external-thunk",
Stability::Forbidden {
reason: "use `retpoline-external-thunk` target modifier flag instead",
},
Stability::Forbidden { reason: "use `-Zretpoline-external-thunk` compiler flag instead" },
&[],
),
(
"retpoline-indirect-branches",
Stability::Forbidden { reason: "use `retpoline` target modifier flag instead" },
Stability::Forbidden { reason: "use `-Zretpoline` compiler flag instead" },
&[],
),
(
"retpoline-indirect-calls",
Stability::Forbidden { reason: "use `retpoline` target modifier flag instead" },
Stability::Forbidden { reason: "use `-Zretpoline` compiler flag instead" },
&[],
),
("rtm", Unstable(sym::rtm_target_feature), &[]),

View file

@ -1,5 +1,5 @@
//@ add-core-stubs
//@ revisions: enable-backchain disable-backchain
//@ revisions: enable-backchain disable-backchain default-backchain
//@ assembly-output: emit-asm
//@ compile-flags: -Copt-level=3 --crate-type=lib --target=s390x-unknown-linux-gnu
//@ needs-llvm-components: systemz
@ -26,6 +26,8 @@ extern "C" fn test_backchain() -> i32 {
// enable-backchain: stg [[REG1]], 0(%r15)
// disable-backchain: aghi %r15, -160
// disable-backchain-NOT: stg %r{{.*}}, 0(%r15)
// default-backchain: aghi %r15, -160
// default-backchain-NOT: stg %r{{.*}}, 0(%r15)
unsafe {
extern_func();
}
@ -35,6 +37,7 @@ extern "C" fn test_backchain() -> i32 {
// Make sure that the expected return value is written into %r2 (return register):
// enable-backchain-NEXT: lghi %r2, 1
// disable-backchain: lghi %r2, 0
// default-backchain: lghi %r2, 0
#[cfg(target_feature = "backchain")]
{
1

View file

@ -211,7 +211,6 @@ LL | cfg!(target_feature = "_UNEXPECTED_VALUE");
`reference-types`
`relax`
`relaxed-simd`
`reserve-x18`
`rtm`
`sb`
`scq`

View file

@ -1,4 +1,4 @@
warning: target feature `retpoline-external-thunk` cannot be enabled with `-Ctarget-feature`: use `retpoline-external-thunk` target modifier flag instead
warning: target feature `retpoline-external-thunk` cannot be enabled with `-Ctarget-feature`: use `-Zretpoline-external-thunk` compiler flag instead
|
= 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>

View file

@ -1,4 +1,4 @@
warning: target feature `retpoline-indirect-branches` cannot be enabled with `-Ctarget-feature`: use `retpoline` target modifier flag instead
warning: target feature `retpoline-indirect-branches` cannot be enabled with `-Ctarget-feature`: use `-Zretpoline` compiler flag instead
|
= 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>

View file

@ -1,4 +1,4 @@
warning: target feature `retpoline-indirect-calls` cannot be enabled with `-Ctarget-feature`: use `retpoline` target modifier flag instead
warning: target feature `retpoline-indirect-calls` cannot be enabled with `-Ctarget-feature`: use `-Zretpoline` compiler flag instead
|
= 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>

View file

@ -16,6 +16,6 @@
#![no_core]
extern crate minicore;
//[by_feature1]~? WARN target feature `retpoline-external-thunk` cannot be enabled with `-Ctarget-feature`: use `retpoline-external-thunk` target modifier flag instead
//[by_feature2]~? WARN target feature `retpoline-indirect-branches` cannot be enabled with `-Ctarget-feature`: use `retpoline` target modifier flag instead
//[by_feature3]~? WARN target feature `retpoline-indirect-calls` cannot be enabled with `-Ctarget-feature`: use `retpoline` target modifier flag instead
//[by_feature1]~? WARN target feature `retpoline-external-thunk` cannot be enabled with `-Ctarget-feature`
//[by_feature2]~? WARN target feature `retpoline-indirect-branches` cannot be enabled with `-Ctarget-feature`
//[by_feature3]~? WARN target feature `retpoline-indirect-calls` cannot be enabled with `-Ctarget-feature`