Skip to content

Commit

Permalink
reject aarch64 target feature toggling that would change the float ABI
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Dec 13, 2024
1 parent 097ac77 commit e9967b9
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 1 deletion.
12 changes: 12 additions & 0 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2615,6 +2615,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 {
Expand Down
24 changes: 23 additions & 1 deletion compiler/rustc_target/src/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,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"]),
Expand Down Expand Up @@ -325,7 +326,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)
Expand Down
7 changes: 7 additions & 0 deletions tests/ui/target-feature/feature-hierarchy.aarch64-sve2.stderr
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/rust-lang/rust/issues/116344>

warning: 1 warning emitted

Original file line number Diff line number Diff line change
@@ -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 {}
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/rust-lang/rust/issues/116344>

warning: 1 warning emitted

0 comments on commit e9967b9

Please sign in to comment.