Skip to content

Commit a72f0b0

Browse files
committed
powerpc: warn against incorrect values for ABI-relevant target features
1 parent cced03b commit a72f0b0

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

compiler/rustc_target/src/target_features.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,11 @@ const HEXAGON_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
572572
static POWERPC_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
573573
// tidy-alphabetical-start
574574
("altivec", Unstable(sym::powerpc_target_feature), &[]),
575+
(
576+
"hard-float",
577+
Forbidden { reason: "unsupported ABI-configuration feature", hard_error: false },
578+
&[],
579+
),
575580
("msync", Unstable(sym::powerpc_target_feature), &[]),
576581
("partword-atomics", Unstable(sym::powerpc_target_feature), &[]),
577582
("power8-altivec", Unstable(sym::powerpc_target_feature), &["altivec"]),
@@ -581,6 +586,7 @@ static POWERPC_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
581586
("power9-vector", Unstable(sym::powerpc_target_feature), &["power8-vector", "power9-altivec"]),
582587
("power10-vector", Unstable(sym::powerpc_target_feature), &["power9-vector"]),
583588
("quadword-atomics", Unstable(sym::powerpc_target_feature), &[]),
589+
("spe", Forbidden { reason: "unsupported ABI-configuration feature", hard_error: false }, &[]),
584590
("vsx", Unstable(sym::powerpc_target_feature), &["altivec"]),
585591
// tidy-alphabetical-end
586592
];
@@ -1136,12 +1142,12 @@ impl Target {
11361142
/// the first list contains target features that must be enabled for ABI reasons,
11371143
/// and the second list contains target feature that must be disabled for ABI reasons.
11381144
///
1139-
/// These features are automatically appended to whatever the target spec sets as default
1140-
/// features for the target.
1145+
/// These features are checked against the target features reported by LLVM based on
1146+
/// `-Ctarget-cpu` and `-Ctarget-features`. Constraint violations result in a warning.
11411147
///
1142-
/// All features enabled/disabled via `-Ctarget-features` and `#[target_features]` are checked
1143-
/// against this. We also check any implied features, based on the information above. If LLVM
1144-
/// implicitly enables more implied features than we do, that could bypass this check!
1148+
/// We also check features enabled via `#[target_features]` (and here, constraint violations
1149+
/// emit a hard error), including features enabled indirectly via implications -- but if LLVM
1150+
/// considers more features to be implied than we do, that could bypass this check!
11451151
pub fn abi_required_features(&self) -> FeatureConstraints {
11461152
const NOTHING: FeatureConstraints = FeatureConstraints { required: &[], incompatible: &[] };
11471153
// Some architectures don't have a clean explicit ABI designation; instead, the ABI is
@@ -1311,7 +1317,16 @@ impl Target {
13111317
}
13121318
}
13131319
}
1320+
Arch::PowerPC | Arch::PowerPC64 => {
1321+
// The main ABI-relevant target features are "hard-float" and "spe". There is also
1322+
// "efpu2" but that seems only relevant when "spe" is enabled. If we ever add a
1323+
// soft-float variant, it looks like we have to mark "altivec" as incompatible --
1324+
// unlike other targets, it looks like enabling "altivec" will have LLVM use
1325+
// different registers for float types even if "hard-float" is off.
1326+
FeatureConstraints { required: &["hard-float"], incompatible: &["spe"] }
1327+
}
13141328
Arch::Avr => {
1329+
// We only support one ABI on AVR at the moment.
13151330
// SRAM is minimum requirement for C/C++ in both avr-gcc and Clang,
13161331
// and backends of them only support assembly for devices have no SRAM.
13171332
// See the discussion in https://github.com/rust-lang/rust/pull/146900 for more.

0 commit comments

Comments
 (0)