From 6cd9e62ecc5f02359bedfb2718b8378f0693fe0a Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 24 Nov 2024 12:35:50 +0100 Subject: [PATCH] reject aarch64 target feature toggling that would change the float ABI --- compiler/rustc_target/src/spec/mod.rs | 12 ++++++++++ compiler/rustc_target/src/target_features.rs | 24 ++++++++++++++++++- .../feature-hierarchy.aarch64-sve2.stderr | 7 ++++++ ...dfloat-target-feature-flag-disable-neon.rs | 10 ++++++++ ...at-target-feature-flag-disable-neon.stderr | 7 ++++++ 5 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 tests/ui/target-feature/feature-hierarchy.aarch64-sve2.stderr create mode 100644 tests/ui/target-feature/forbidden-hardfloat-target-feature-flag-disable-neon.rs create mode 100644 tests/ui/target-feature/forbidden-hardfloat-target-feature-flag-disable-neon.stderr diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 5d3c693876c54..820855baa42c0 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -2604,6 +2604,18 @@ impl TargetOptions { } }) } + + pub(crate) fn has_neg_feature(&self, search_feature: &str) -> bool { + self.features.split(',').any(|f| { + if let Some(f) = f.strip_prefix('-') + && f == search_feature + { + true + } else { + false + } + }) + } } impl Default for TargetOptions { diff --git a/compiler/rustc_target/src/target_features.rs b/compiler/rustc_target/src/target_features.rs index 4b9c7bcd5c5d1..c0bb528f304ff 100644 --- a/compiler/rustc_target/src/target_features.rs +++ b/compiler/rustc_target/src/target_features.rs @@ -280,6 +280,7 @@ const AARCH64_FEATURES: &[(&str, StabilityUncomputed, ImpliedFeatures)] = &[ ("flagm", STABLE, &[]), // FEAT_FLAGM2 ("flagm2", unstable(sym::aarch64_unstable_target_feature), &[]), + ("fp-armv8", Stability::Forbidden { reason: "Rust ties `fp-armv8` to `neon`" }, &[]), // FEAT_FP16 // Rust ties FP and Neon: https://github.com/rust-lang/rust/pull/91608 ("fp16", STABLE, &["neon"]), @@ -315,7 +316,28 @@ const AARCH64_FEATURES: &[(&str, StabilityUncomputed, ImpliedFeatures)] = &[ // FEAT_MTE & FEAT_MTE2 ("mte", STABLE, &[]), // FEAT_AdvSimd & FEAT_FP - ("neon", STABLE, &[]), + ( + "neon", + Stability::Stable { + allow_toggle: |target, enable| { + if target.abi == "softfloat" { + // `neon` has no ABI implications for softfloat targets, we can allow this. + Ok(()) + } else if enable + && !target.has_neg_feature("fp-armv8") + && !target.has_neg_feature("neon") + { + // neon is enabled by default, and has not been disabled, so enabling it again + // is redundant and we can permit it. Forbidding this would be a breaking change + // since this feature is stable. + Ok(()) + } else { + Err("unsound on hard-float targets because it changes float ABI") + } + }, + }, + &[], + ), // FEAT_PAUTH (address authentication) ("paca", STABLE, &[]), // FEAT_PAUTH (generic authentication) diff --git a/tests/ui/target-feature/feature-hierarchy.aarch64-sve2.stderr b/tests/ui/target-feature/feature-hierarchy.aarch64-sve2.stderr new file mode 100644 index 0000000000000..d5d7d7aa627ba --- /dev/null +++ b/tests/ui/target-feature/feature-hierarchy.aarch64-sve2.stderr @@ -0,0 +1,7 @@ +warning: target feature `neon` cannot be toggled with `-Ctarget-feature`: unsound on hard-float targets because it changes float 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 + +warning: 1 warning emitted + diff --git a/tests/ui/target-feature/forbidden-hardfloat-target-feature-flag-disable-neon.rs b/tests/ui/target-feature/forbidden-hardfloat-target-feature-flag-disable-neon.rs new file mode 100644 index 0000000000000..95c366bb3f5be --- /dev/null +++ b/tests/ui/target-feature/forbidden-hardfloat-target-feature-flag-disable-neon.rs @@ -0,0 +1,10 @@ +//@ compile-flags: --target=aarch64-unknown-linux-gnu --crate-type=lib +//@ needs-llvm-components: aarch64 +//@ compile-flags: -Ctarget-feature=-neon +// For now this is just a warning. +//@ build-pass +#![feature(no_core, lang_items)] +#![no_core] + +#[lang = "sized"] +pub trait Sized {} diff --git a/tests/ui/target-feature/forbidden-hardfloat-target-feature-flag-disable-neon.stderr b/tests/ui/target-feature/forbidden-hardfloat-target-feature-flag-disable-neon.stderr new file mode 100644 index 0000000000000..d5d7d7aa627ba --- /dev/null +++ b/tests/ui/target-feature/forbidden-hardfloat-target-feature-flag-disable-neon.stderr @@ -0,0 +1,7 @@ +warning: target feature `neon` cannot be toggled with `-Ctarget-feature`: unsound on hard-float targets because it changes float 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 + +warning: 1 warning emitted +