Skip to content

Commit 6cd9e62

Browse files
committed
reject aarch64 target feature toggling that would change the float ABI
1 parent 236d73e commit 6cd9e62

5 files changed

+59
-1
lines changed

compiler/rustc_target/src/spec/mod.rs

+12
Original file line numberDiff line numberDiff line change
@@ -2604,6 +2604,18 @@ impl TargetOptions {
26042604
}
26052605
})
26062606
}
2607+
2608+
pub(crate) fn has_neg_feature(&self, search_feature: &str) -> bool {
2609+
self.features.split(',').any(|f| {
2610+
if let Some(f) = f.strip_prefix('-')
2611+
&& f == search_feature
2612+
{
2613+
true
2614+
} else {
2615+
false
2616+
}
2617+
})
2618+
}
26072619
}
26082620

26092621
impl Default for TargetOptions {

compiler/rustc_target/src/target_features.rs

+23-1
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ const AARCH64_FEATURES: &[(&str, StabilityUncomputed, ImpliedFeatures)] = &[
280280
("flagm", STABLE, &[]),
281281
// FEAT_FLAGM2
282282
("flagm2", unstable(sym::aarch64_unstable_target_feature), &[]),
283+
("fp-armv8", Stability::Forbidden { reason: "Rust ties `fp-armv8` to `neon`" }, &[]),
283284
// FEAT_FP16
284285
// Rust ties FP and Neon: https://github.com/rust-lang/rust/pull/91608
285286
("fp16", STABLE, &["neon"]),
@@ -315,7 +316,28 @@ const AARCH64_FEATURES: &[(&str, StabilityUncomputed, ImpliedFeatures)] = &[
315316
// FEAT_MTE & FEAT_MTE2
316317
("mte", STABLE, &[]),
317318
// FEAT_AdvSimd & FEAT_FP
318-
("neon", STABLE, &[]),
319+
(
320+
"neon",
321+
Stability::Stable {
322+
allow_toggle: |target, enable| {
323+
if target.abi == "softfloat" {
324+
// `neon` has no ABI implications for softfloat targets, we can allow this.
325+
Ok(())
326+
} else if enable
327+
&& !target.has_neg_feature("fp-armv8")
328+
&& !target.has_neg_feature("neon")
329+
{
330+
// neon is enabled by default, and has not been disabled, so enabling it again
331+
// is redundant and we can permit it. Forbidding this would be a breaking change
332+
// since this feature is stable.
333+
Ok(())
334+
} else {
335+
Err("unsound on hard-float targets because it changes float ABI")
336+
}
337+
},
338+
},
339+
&[],
340+
),
319341
// FEAT_PAUTH (address authentication)
320342
("paca", STABLE, &[]),
321343
// FEAT_PAUTH (generic authentication)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
warning: target feature `neon` cannot be toggled with `-Ctarget-feature`: unsound on hard-float targets because it changes float ABI
2+
|
3+
= note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
4+
= note: for more information, see issue #116344 <https://github.com/rust-lang/rust/issues/116344>
5+
6+
warning: 1 warning emitted
7+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//@ compile-flags: --target=aarch64-unknown-linux-gnu --crate-type=lib
2+
//@ needs-llvm-components: aarch64
3+
//@ compile-flags: -Ctarget-feature=-neon
4+
// For now this is just a warning.
5+
//@ build-pass
6+
#![feature(no_core, lang_items)]
7+
#![no_core]
8+
9+
#[lang = "sized"]
10+
pub trait Sized {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
warning: target feature `neon` cannot be toggled with `-Ctarget-feature`: unsound on hard-float targets because it changes float ABI
2+
|
3+
= note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
4+
= note: for more information, see issue #116344 <https://github.com/rust-lang/rust/issues/116344>
5+
6+
warning: 1 warning emitted
7+

0 commit comments

Comments
 (0)