Skip to content

Commit 5143e37

Browse files
committed
Auto merge of #140395 - RalfJung:target-feature-tests, r=<try>
organize and extend forbidden target feature tests In particular this adds some loongarch tests for #135015, Cc `@heiher` Seems like the tests change so much git does not detect the renames; a commit-by-commit review should help. try-job: `x86_64-gnu-llvm-*`
2 parents 251cda5 + e90dafa commit 5143e37

21 files changed

+131
-78
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: target feature `d` cannot be enabled with `#[target_feature]`: this feature is incompatible with the target ABI
2+
--> $DIR/abi-incompatible-target-feature-attribute.rs:15:90
3+
|
4+
LL | #[cfg_attr(x86, target_feature(enable = "soft-float"))] #[cfg_attr(riscv, target_feature(enable = "d"))]
5+
| ^^^^^^^^^^^^
6+
7+
error: aborting due to 1 previous error
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//! Ensure ABI-incompatible features cannot be enabled via `#[target_feature]`.
2+
// ignore-tidy-linelength
3+
//@ compile-flags: --crate-type=lib
4+
//@ revisions: x86 riscv
5+
//@[x86] compile-flags: --target=x86_64-unknown-linux-gnu
6+
//@[x86] needs-llvm-components: x86
7+
//@[riscv] compile-flags: --target=riscv32e-unknown-none-elf
8+
//@[riscv] needs-llvm-components: riscv
9+
#![feature(no_core, lang_items, riscv_target_feature, x87_target_feature)]
10+
#![no_core]
11+
12+
#[lang = "sized"]
13+
pub trait Sized {}
14+
15+
#[cfg_attr(x86, target_feature(enable = "soft-float"))] #[cfg_attr(riscv, target_feature(enable = "d"))]
16+
//~^ERROR: cannot be enabled with
17+
pub unsafe fn my_fun() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: target feature `soft-float` cannot be enabled with `#[target_feature]`: this feature is incompatible with the target ABI
2+
--> $DIR/abi-incompatible-target-feature-attribute.rs:15:32
3+
|
4+
LL | #[cfg_attr(x86, target_feature(enable = "soft-float"))] #[cfg_attr(riscv, target_feature(enable = "d"))]
5+
| ^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to 1 previous error
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
warning: target feature `d` must be disabled to ensure that the ABI of the current target can be implemented correctly
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: unstable feature specified for `-Ctarget-feature`: `d`
7+
|
8+
= note: this feature is not stably supported; its behavior can change in the future
9+
10+
warning: unstable feature specified for `-Ctarget-feature`: `f`
11+
|
12+
= note: this feature is not stably supported; its behavior can change in the future
13+
14+
warning: unstable feature specified for `-Ctarget-feature`: `zicsr`
15+
|
16+
= note: this feature is not stably supported; its behavior can change in the future
17+
18+
warning: 4 warnings emitted
19+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//! Ensure ABI-incompatible features cannot be enabled via `-Ctarget-feature`.
2+
// These are just warnings for now.
3+
//@ check-pass
4+
//@ compile-flags: --crate-type=lib
5+
//@ revisions: x86 riscv
6+
//@[x86] compile-flags: --target=x86_64-unknown-linux-gnu -Ctarget-feature=+soft-float
7+
//@[x86] needs-llvm-components: x86
8+
//@[riscv] compile-flags: --target=riscv32e-unknown-none-elf -Ctarget-feature=+d
9+
//@[riscv] needs-llvm-components: riscv
10+
11+
#![feature(no_core, lang_items, riscv_target_feature)]
12+
#![no_core]
13+
14+
#[lang = "sized"]
15+
pub trait Sized {}
16+
#[lang = "freeze"]
17+
pub trait Freeze {}
18+
19+
//~? WARN must be disabled to ensure that the ABI of the current target can be implemented correctly
20+
//~? WARN unstable feature specified for `-Ctarget-feature`
21+
//[riscv]~? WARN unstable feature specified for `-Ctarget-feature`
22+
//[riscv]~? WARN unstable feature specified for `-Ctarget-feature`

tests/ui/target-feature/allowed-softfloat-target-feature-flag-disable.rs renamed to tests/ui/target-feature/abi-irrelevant-target-feature-flag-disable.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//! `x87` is a required target feature on some x86 targets, but not on this one as this one
2+
//! uses soft-floats. So ensure disabling the target feature here (which is a NOP) does
3+
//! not trigger a warning.
14
//@ compile-flags: --target=x86_64-unknown-none --crate-type=lib
25
//@ needs-llvm-components: x86
36
//@ compile-flags: -Ctarget-feature=-x87

tests/ui/target-feature/allowed-softfloat-target-feature-attribute.rs renamed to tests/ui/target-feature/abi-required-target-feature-attribute.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Enabling a target feature that is anyway required changes nothing, so this is allowed
2+
//! for `#[target_feature]`.
13
//@ compile-flags: --target=x86_64-unknown-none --crate-type=lib
24
//@ needs-llvm-components: x86
35
//@ build-pass
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
warning: target feature `d` must be enabled to ensure that the ABI of the current target can be implemented correctly
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: unstable feature specified for `-Ctarget-feature`: `d`
7+
|
8+
= note: this feature is not stably supported; its behavior can change in the future
9+
10+
warning: both target-abi and the triple-implied ABI are invalid, ignoring and using feature-implied ABI
11+
warning: 'lp64f' has not been standardized
12+
warning: 2 warnings emitted
13+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
warning: target feature `d` must be enabled to ensure that the ABI of the current target can be implemented correctly
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: unstable feature specified for `-Ctarget-feature`: `d`
7+
|
8+
= note: this feature is not stably supported; its behavior can change in the future
9+
10+
Hard-float 'd' ABI can't be used for a target that doesn't support the D instruction set extension (ignoring target-abi)
11+
warning: 2 warnings emitted
12+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//! Ensure ABI-required features cannot be disabled via `-Ctarget-feature`.
2+
//! Also covers the case of a feature indirectly disabling another via feature implications.
3+
//@ compile-flags: --crate-type=lib
4+
//@ revisions: x86 x86-implied aarch64 riscv loongarch
5+
//@[x86] compile-flags: --target=x86_64-unknown-linux-gnu -Ctarget-feature=-x87
6+
//@[x86] needs-llvm-components: x86
7+
//@[x86-implied] compile-flags: --target=x86_64-unknown-linux-gnu -Ctarget-feature=-sse
8+
//@[x86-implied] needs-llvm-components: x86
9+
//@[aarch64] compile-flags: --target=aarch64-unknown-linux-gnu -Ctarget-feature=-neon
10+
//@[aarch64] needs-llvm-components: aarch64
11+
//@[riscv] compile-flags: --target=riscv64gc-unknown-none-elf -Ctarget-feature=-d
12+
//@[riscv] needs-llvm-components: riscv
13+
//@[riscv] min-llvm-version: 20
14+
//@[loongarch] compile-flags: --target=loongarch64-unknown-none -Ctarget-feature=-d
15+
//@[loongarch] needs-llvm-components: loongarch
16+
//@[loongarch] min-llvm-version: 20
17+
// For now this is just a warning.
18+
//@ build-pass
19+
20+
#![feature(no_core, lang_items)]
21+
#![no_core]
22+
23+
#[lang = "sized"]
24+
pub trait Sized {}
25+
26+
//~? WARN must be enabled to ensure that the ABI of the current target can be implemented correctly
27+
//[x86,riscv,loongarch]~? WARN unstable feature specified for `-Ctarget-feature`

tests/ui/target-feature/forbidden-hardfloat-target-feature-attribute.rs

-12
This file was deleted.

tests/ui/target-feature/forbidden-hardfloat-target-feature-attribute.stderr

-8
This file was deleted.

tests/ui/target-feature/forbidden-hardfloat-target-feature-flag-disable-implied.rs

-15
This file was deleted.

tests/ui/target-feature/forbidden-hardfloat-target-feature-flag-disable-neon.rs

-13
This file was deleted.

tests/ui/target-feature/forbidden-hardfloat-target-feature-flag-disable.rs

-15
This file was deleted.

tests/ui/target-feature/forbidden-hardfloat-target-feature-flag.rs

-15
This file was deleted.

0 commit comments

Comments
 (0)