Skip to content

organize and extend forbidden target feature tests #140395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: target feature `d` cannot be enabled with `#[target_feature]`: this feature is incompatible with the target ABI
--> $DIR/abi-incompatible-target-feature-attribute.rs:15:90
|
LL | #[cfg_attr(x86, target_feature(enable = "soft-float"))] #[cfg_attr(riscv, target_feature(enable = "d"))]
| ^^^^^^^^^^^^

error: aborting due to 1 previous error

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//! Ensure ABI-incompatible features cannot be enabled via `#[target_feature]`.
// ignore-tidy-linelength
//@ compile-flags: --crate-type=lib
//@ revisions: x86 riscv
//@[x86] compile-flags: --target=x86_64-unknown-linux-gnu
//@[x86] needs-llvm-components: x86
//@[riscv] compile-flags: --target=riscv32e-unknown-none-elf
//@[riscv] needs-llvm-components: riscv
#![feature(no_core, lang_items, riscv_target_feature, x87_target_feature)]
#![no_core]

#[lang = "sized"]
pub trait Sized {}

#[cfg_attr(x86, target_feature(enable = "soft-float"))] #[cfg_attr(riscv, target_feature(enable = "d"))]
//~^ERROR: cannot be enabled with
pub unsafe fn my_fun() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: target feature `soft-float` cannot be enabled with `#[target_feature]`: this feature is incompatible with the target ABI
--> $DIR/abi-incompatible-target-feature-attribute.rs:15:32
|
LL | #[cfg_attr(x86, target_feature(enable = "soft-float"))] #[cfg_attr(riscv, target_feature(enable = "d"))]
| ^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
warning: target feature `d` must be disabled to ensure that the ABI of the current target can be implemented correctly
|
= note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #116344 <https://github.com/rust-lang/rust/issues/116344>

warning: unstable feature specified for `-Ctarget-feature`: `d`
|
= note: this feature is not stably supported; its behavior can change in the future

warning: unstable feature specified for `-Ctarget-feature`: `f`
|
= note: this feature is not stably supported; its behavior can change in the future

warning: unstable feature specified for `-Ctarget-feature`: `zicsr`
|
= note: this feature is not stably supported; its behavior can change in the future

warning: 4 warnings emitted

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//! Ensure ABI-incompatible features cannot be enabled via `-Ctarget-feature`.
// These are just warnings for now.
//@ check-pass
//@ compile-flags: --crate-type=lib
//@ revisions: x86 riscv
//@[x86] compile-flags: --target=x86_64-unknown-linux-gnu -Ctarget-feature=+soft-float
//@[x86] needs-llvm-components: x86
//@[riscv] compile-flags: --target=riscv32e-unknown-none-elf -Ctarget-feature=+d
//@[riscv] needs-llvm-components: riscv

#![feature(no_core, lang_items, riscv_target_feature)]
#![no_core]

#[lang = "sized"]
pub trait Sized {}
#[lang = "freeze"]
pub trait Freeze {}

//~? WARN must be disabled to ensure that the ABI of the current target can be implemented correctly
//~? WARN unstable feature specified for `-Ctarget-feature`
//[riscv]~? WARN unstable feature specified for `-Ctarget-feature`
//[riscv]~? WARN unstable feature specified for `-Ctarget-feature`
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//! `x87` is a required target feature on some x86 targets, but not on this one as this one
//! uses soft-floats. So ensure disabling the target feature here (which is a NOP) does
//! not trigger a warning.
//@ compile-flags: --target=x86_64-unknown-none --crate-type=lib
//@ needs-llvm-components: x86
//@ compile-flags: -Ctarget-feature=-x87
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Enabling a target feature that is anyway required changes nothing, so this is allowed
//! for `#[target_feature]`.
//@ compile-flags: --target=x86_64-unknown-none --crate-type=lib
//@ needs-llvm-components: x86
//@ build-pass
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
warning: target feature `d` must be enabled to ensure that the ABI of the current target can be implemented correctly
|
= note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #116344 <https://github.com/rust-lang/rust/issues/116344>

warning: unstable feature specified for `-Ctarget-feature`: `d`
|
= note: this feature is not stably supported; its behavior can change in the future

warning: 2 warnings emitted

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
warning: target feature `d` must be enabled to ensure that the ABI of the current target can be implemented correctly
|
= note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #116344 <https://github.com/rust-lang/rust/issues/116344>

warning: unstable feature specified for `-Ctarget-feature`: `d`
|
= note: this feature is not stably supported; its behavior can change in the future

warning: 2 warnings emitted

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//! Ensure ABI-required features cannot be disabled via `-Ctarget-feature`.
//! Also covers the case of a feature indirectly disabling another via feature implications.
//@ compile-flags: --crate-type=lib
//@ revisions: x86 x86-implied aarch64 riscv loongarch
//@[x86] compile-flags: --target=x86_64-unknown-linux-gnu -Ctarget-feature=-x87
//@[x86] needs-llvm-components: x86
//@[x86-implied] compile-flags: --target=x86_64-unknown-linux-gnu -Ctarget-feature=-sse
//@[x86-implied] needs-llvm-components: x86
//@[aarch64] compile-flags: --target=aarch64-unknown-linux-gnu -Ctarget-feature=-neon
//@[aarch64] needs-llvm-components: aarch64
//@[riscv] compile-flags: --target=riscv64gc-unknown-none-elf -Ctarget-feature=-d
//@[riscv] needs-llvm-components: riscv
//@[loongarch] compile-flags: --target=loongarch64-unknown-none -Ctarget-feature=-d
//@[loongarch] needs-llvm-components: loongarch
// For now this is just a warning.
//@ build-pass
// Remove some LLVM warnings that only show up sometimes.
//@ normalize-stderr: "\n[^\n]*(target-abi|lp64f)[^\n]*" -> ""

#![feature(no_core, lang_items)]
#![no_core]

#[lang = "sized"]
pub trait Sized {}

//~? WARN must be enabled to ensure that the ABI of the current target can be implemented correctly
//[x86,riscv,loongarch]~? WARN unstable feature specified for `-Ctarget-feature`

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

15 changes: 0 additions & 15 deletions tests/ui/target-feature/forbidden-hardfloat-target-feature-flag.rs

This file was deleted.

Loading