Skip to content

Commit b24288b

Browse files
authored
Rollup merge of #138872 - a4lg:riscv-fix-incompatible-abi-zfinx, r=workingjubilee
rustc_target: RISC-V `Zfinx` is incompatible with `{ILP32,LP64}[FD]` ABIs Because RISC-V Calling Conventions note that: > This means code targeting the `Zfinx` extension always uses the ILP32, ILP32E or LP64 integer calling-convention only ABIs as there is no dedicated hardware floating-point register file. `{ILP32,LP64}[FD]` ABIs with hardware floating-point calling conventions are incompatible with the `Zfinx` extension. This commit adds `"zfinx"` to the incompatible feature list to those ABIs and tests whether trying to add `"zdinx"` (that is analogous to `"zfinx"` but in double-precision) on a LP64D ABI configuration results in an error (it also tests extension implication; `Zdinx` requires `Zfinx` extension). Links: RISC-V psABI specification version 1.0 <https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/v1.0/riscv-cc.adoc#named-abis> <https://github.com/riscv-non-isa/riscv-elf-psabi-doc/releases/tag/v1.0>
2 parents 8619438 + eec6cfb commit b24288b

5 files changed

+25
-5
lines changed

compiler/rustc_target/src/target_features.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -966,12 +966,12 @@ impl Target {
966966
// about what the intended ABI is.
967967
match &*self.llvm_abiname {
968968
"ilp32d" | "lp64d" => {
969-
// Requires d (which implies f), incompatible with e.
970-
FeatureConstraints { required: &["d"], incompatible: &["e"] }
969+
// Requires d (which implies f), incompatible with e and zfinx.
970+
FeatureConstraints { required: &["d"], incompatible: &["e", "zfinx"] }
971971
}
972972
"ilp32f" | "lp64f" => {
973-
// Requires f, incompatible with e.
974-
FeatureConstraints { required: &["f"], incompatible: &["e"] }
973+
// Requires f, incompatible with e and zfinx.
974+
FeatureConstraints { required: &["f"], incompatible: &["e", "zfinx"] }
975975
}
976976
"ilp32" | "lp64" => {
977977
// Requires nothing, incompatible with e.

tests/ui/target-feature/forbidden-hardfloat-target-feature-attribute.stderr renamed to tests/ui/target-feature/forbidden-hardfloat-target-feature-attribute-e-d.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: target feature `d` cannot be enabled with `#[target_feature]`: this feature is incompatible with the target ABI
2-
--> $DIR/forbidden-hardfloat-target-feature-attribute.rs:10:18
2+
--> $DIR/forbidden-hardfloat-target-feature-attribute-e-d.rs:10:18
33
|
44
LL | #[target_feature(enable = "d")]
55
| ^^^^^^^^^^^^
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//! Ensure ABI-incompatible features cannot be enabled via `#[target_feature]`.
2+
//@ compile-flags: --target=riscv64gc-unknown-linux-gnu --crate-type=lib
3+
//@ needs-llvm-components: riscv
4+
#![feature(no_core, lang_items, riscv_target_feature)]
5+
#![no_core]
6+
7+
#[lang = "sized"]
8+
pub trait Sized {}
9+
10+
#[target_feature(enable = "zdinx")]
11+
//~^ERROR: cannot be enabled with
12+
pub unsafe fn my_fun() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: target feature `zfinx` cannot be enabled with `#[target_feature]`: this feature is incompatible with the target ABI
2+
--> $DIR/forbidden-hardfloat-target-feature-attribute-f-zfinx.rs:10:18
3+
|
4+
LL | #[target_feature(enable = "zdinx")]
5+
| ^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to 1 previous error
8+

0 commit comments

Comments
 (0)