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).

Link: RISC-V psABI specification version 1.0
<https://github.com/riscv-non-isa/riscv-elf-psabi-doc/releases/tag/v1.0>
This commit is contained in:
Tsukasa OI 2025-03-24 00:23:46 +00:00
parent 0c33fe2c3d
commit eec6cfb8da
5 changed files with 25 additions and 5 deletions

View file

@ -963,12 +963,12 @@ impl Target {
// about what the intended ABI is.
match &*self.llvm_abiname {
"ilp32d" | "lp64d" => {
// Requires d (which implies f), incompatible with e.
FeatureConstraints { required: &["d"], incompatible: &["e"] }
// Requires d (which implies f), incompatible with e and zfinx.
FeatureConstraints { required: &["d"], incompatible: &["e", "zfinx"] }
}
"ilp32f" | "lp64f" => {
// Requires f, incompatible with e.
FeatureConstraints { required: &["f"], incompatible: &["e"] }
// Requires f, incompatible with e and zfinx.
FeatureConstraints { required: &["f"], incompatible: &["e", "zfinx"] }
}
"ilp32" | "lp64" => {
// Requires nothing, incompatible with e.

View file

@ -1,5 +1,5 @@
error: target feature `d` cannot be enabled with `#[target_feature]`: this feature is incompatible with the target ABI
--> $DIR/forbidden-hardfloat-target-feature-attribute.rs:10:18
--> $DIR/forbidden-hardfloat-target-feature-attribute-e-d.rs:10:18
|
LL | #[target_feature(enable = "d")]
| ^^^^^^^^^^^^

View file

@ -0,0 +1,12 @@
//! Ensure ABI-incompatible features cannot be enabled via `#[target_feature]`.
//@ compile-flags: --target=riscv64gc-unknown-linux-gnu --crate-type=lib
//@ needs-llvm-components: riscv
#![feature(no_core, lang_items, riscv_target_feature)]
#![no_core]
#[lang = "sized"]
pub trait Sized {}
#[target_feature(enable = "zdinx")]
//~^ERROR: cannot be enabled with
pub unsafe fn my_fun() {}

View file

@ -0,0 +1,8 @@
error: target feature `zfinx` cannot be enabled with `#[target_feature]`: this feature is incompatible with the target ABI
--> $DIR/forbidden-hardfloat-target-feature-attribute-f-zfinx.rs:10:18
|
LL | #[target_feature(enable = "zdinx")]
| ^^^^^^^^^^^^^^^^
error: aborting due to 1 previous error