Skip to content

Commit e9967b9

Browse files
committed
reject aarch64 target feature toggling that would change the float ABI
1 parent 097ac77 commit e9967b9

5 files changed

+59
-1
lines changed

Diff for: compiler/rustc_target/src/spec/mod.rs

+12
Original file line numberDiff line numberDiff line change
@@ -2615,6 +2615,18 @@ impl TargetOptions {
26152615
}
26162616
})
26172617
}
2618+
2619+
pub(crate) fn has_neg_feature(&self, search_feature: &str) -> bool {
2620+
self.features.split(',').any(|f| {
2621+
if let Some(f) = f.strip_prefix('-')
2622+
&& f == search_feature
2623+
{
2624+
true
2625+
} else {
2626+
false
2627+
}
2628+
})
2629+
}
26182630
}
26192631

26202632
impl Default for TargetOptions {

Diff for: compiler/rustc_target/src/target_features.rs

+23-1
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ const AARCH64_FEATURES: &[(&str, StabilityUncomputed, ImpliedFeatures)] = &[
290290
("flagm", STABLE, &[]),
291291
// FEAT_FLAGM2
292292
("flagm2", unstable(sym::aarch64_unstable_target_feature), &[]),
293+
("fp-armv8", Stability::Forbidden { reason: "Rust ties `fp-armv8` to `neon`" }, &[]),
293294
// FEAT_FP16
294295
// Rust ties FP and Neon: https://github.com/rust-lang/rust/pull/91608
295296
("fp16", STABLE, &["neon"]),
@@ -325,7 +326,28 @@ const AARCH64_FEATURES: &[(&str, StabilityUncomputed, ImpliedFeatures)] = &[
325326
// FEAT_MTE & FEAT_MTE2
326327
("mte", STABLE, &[]),
327328
// FEAT_AdvSimd & FEAT_FP
328-
("neon", STABLE, &[]),
329+
(
330+
"neon",
331+
Stability::Stable {
332+
allow_toggle: |target, enable| {
333+
if target.abi == "softfloat" {
334+
// `neon` has no ABI implications for softfloat targets, we can allow this.
335+
Ok(())
336+
} else if enable
337+
&& !target.has_neg_feature("fp-armv8")
338+
&& !target.has_neg_feature("neon")
339+
{
340+
// neon is enabled by default, and has not been disabled, so enabling it again
341+
// is redundant and we can permit it. Forbidding this would be a breaking change
342+
// since this feature is stable.
343+
Ok(())
344+
} else {
345+
Err("unsound on hard-float targets because it changes float ABI")
346+
}
347+
},
348+
},
349+
&[],
350+
),
329351
// FEAT_PAUTH (address authentication)
330352
("paca", STABLE, &[]),
331353
// 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)