Skip to content
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

add a test for target-feature-ABI warnings in closures and when calling extern fn #133384

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_ssa/src/codegen_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,9 +576,9 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
// If this closure is marked `#[inline(always)]`, simply skip adding `#[target_feature]`.
//
// At this point, `unsafe` has already been checked and `#[target_feature]` only affects codegen.
// Emitting both `#[inline(always)]` and `#[target_feature]` can potentially result in an
// ICE, because LLVM errors when the function fails to be inlined due to a target feature
// mismatch.
// Due to LLVM limitations, emitting both `#[inline(always)]` and `#[target_feature]` is *unsound*:
// the function may be inlined into a caller with fewer target features. Also see
// <https://github.com/rust-lang/rust/issues/116573>.
//
// Using `#[inline(always)]` implies that this closure will most likely be inlined into
// its parent function, which effectively inherits the features anyway. Boxing this closure
Expand Down
29 changes: 29 additions & 0 deletions tests/ui/simd-abi-checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#![feature(avx512_target_feature)]
#![feature(portable_simd)]
#![feature(target_feature_11, simd_ffi)]
#![allow(improper_ctypes_definitions)]

use std::arch::x86_64::*;
Expand Down Expand Up @@ -50,6 +51,14 @@ unsafe fn test() {
as_f64x8(arg);
}

#[target_feature(enable = "avx")]
unsafe fn in_closure() -> impl FnOnce() -> __m256 {
#[inline(always)] // this disables target-feature inheritance
|| g()
//~^ WARNING this function call uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
//~| WARNING this was previously accepted by the compiler
}

fn main() {
unsafe {
f(g());
Expand Down Expand Up @@ -78,4 +87,24 @@ fn main() {
//~| WARNING this was previously accepted by the compiler
//~| WARNING this was previously accepted by the compiler
}

unsafe {
in_closure()();
}

unsafe {
#[expect(improper_ctypes)]
extern "C" {
fn some_extern() -> __m256;
}
some_extern();
//~^ WARNING this function call uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
//~| WARNING this was previously accepted by the compiler
}
}

#[no_mangle]
#[target_feature(enable = "avx")]
fn some_extern() -> __m256 {
todo!()
}
82 changes: 63 additions & 19 deletions tests/ui/simd-abi-checks.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: this function call uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
--> $DIR/simd-abi-checks.rs:55:11
--> $DIR/simd-abi-checks.rs:64:11
|
LL | f(g());
| ^^^ function called here
Expand All @@ -10,7 +10,7 @@ LL | f(g());
= note: `#[warn(abi_unsupported_vector_types)]` on by default

warning: this function call uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
--> $DIR/simd-abi-checks.rs:55:9
--> $DIR/simd-abi-checks.rs:64:9
|
LL | f(g());
| ^^^^^^ function called here
Expand All @@ -20,7 +20,7 @@ LL | f(g());
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)

warning: this function call uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
--> $DIR/simd-abi-checks.rs:63:14
--> $DIR/simd-abi-checks.rs:72:14
|
LL | gavx(favx());
| ^^^^^^ function called here
Expand All @@ -30,7 +30,7 @@ LL | gavx(favx());
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)

warning: this function call uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
--> $DIR/simd-abi-checks.rs:63:9
--> $DIR/simd-abi-checks.rs:72:9
|
LL | gavx(favx());
| ^^^^^^^^^^^^ function called here
Expand All @@ -40,7 +40,7 @@ LL | gavx(favx());
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)

warning: this function call uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
--> $DIR/simd-abi-checks.rs:75:19
--> $DIR/simd-abi-checks.rs:84:19
|
LL | w(Wrapper(g()));
| ^^^ function called here
Expand All @@ -50,7 +50,7 @@ LL | w(Wrapper(g()));
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)

warning: this function call uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
--> $DIR/simd-abi-checks.rs:75:9
--> $DIR/simd-abi-checks.rs:84:9
|
LL | w(Wrapper(g()));
| ^^^^^^^^^^^^^^^ function called here
Expand All @@ -59,8 +59,18 @@ LL | w(Wrapper(g()));
= note: for more information, see issue #116558 <https://github.com/rust-lang/rust/issues/116558>
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)

warning: this function call uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
--> $DIR/simd-abi-checks.rs:100:9
|
LL | some_extern();
| ^^^^^^^^^^^^^ function called here
|
= warning: 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 #116558 <https://github.com/rust-lang/rust/issues/116558>
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)

warning: this function definition uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled
--> $DIR/simd-abi-checks.rs:26:1
--> $DIR/simd-abi-checks.rs:27:1
|
LL | unsafe extern "C" fn g() -> __m256 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
Expand All @@ -70,7 +80,7 @@ LL | unsafe extern "C" fn g() -> __m256 {
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)

warning: this function definition uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled
--> $DIR/simd-abi-checks.rs:20:1
--> $DIR/simd-abi-checks.rs:21:1
|
LL | unsafe extern "C" fn f(_: __m256) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
Expand All @@ -80,7 +90,7 @@ LL | unsafe extern "C" fn f(_: __m256) {
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)

warning: this function definition uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled
--> $DIR/simd-abi-checks.rs:14:1
--> $DIR/simd-abi-checks.rs:15:1
|
LL | unsafe extern "C" fn w(_: Wrapper) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
Expand All @@ -89,11 +99,21 @@ LL | unsafe extern "C" fn w(_: Wrapper) {
= note: for more information, see issue #116558 <https://github.com/rust-lang/rust/issues/116558>
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)

warning: 9 warnings emitted
warning: this function call uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
--> $DIR/simd-abi-checks.rs:57:8
|
LL | || g()
| ^^^ function called here
|
= warning: 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 #116558 <https://github.com/rust-lang/rust/issues/116558>
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)

warning: 11 warnings emitted

Future incompatibility report: Future breakage diagnostic:
warning: this function call uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
--> $DIR/simd-abi-checks.rs:55:11
--> $DIR/simd-abi-checks.rs:64:11
|
LL | f(g());
| ^^^ function called here
Expand All @@ -105,7 +125,7 @@ LL | f(g());

Future breakage diagnostic:
warning: this function call uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
--> $DIR/simd-abi-checks.rs:55:9
--> $DIR/simd-abi-checks.rs:64:9
|
LL | f(g());
| ^^^^^^ function called here
Expand All @@ -117,7 +137,7 @@ LL | f(g());

Future breakage diagnostic:
warning: this function call uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
--> $DIR/simd-abi-checks.rs:63:14
--> $DIR/simd-abi-checks.rs:72:14
|
LL | gavx(favx());
| ^^^^^^ function called here
Expand All @@ -129,7 +149,7 @@ LL | gavx(favx());

Future breakage diagnostic:
warning: this function call uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
--> $DIR/simd-abi-checks.rs:63:9
--> $DIR/simd-abi-checks.rs:72:9
|
LL | gavx(favx());
| ^^^^^^^^^^^^ function called here
Expand All @@ -141,7 +161,7 @@ LL | gavx(favx());

Future breakage diagnostic:
warning: this function call uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
--> $DIR/simd-abi-checks.rs:75:19
--> $DIR/simd-abi-checks.rs:84:19
|
LL | w(Wrapper(g()));
| ^^^ function called here
Expand All @@ -153,7 +173,7 @@ LL | w(Wrapper(g()));

Future breakage diagnostic:
warning: this function call uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
--> $DIR/simd-abi-checks.rs:75:9
--> $DIR/simd-abi-checks.rs:84:9
|
LL | w(Wrapper(g()));
| ^^^^^^^^^^^^^^^ function called here
Expand All @@ -163,9 +183,21 @@ LL | w(Wrapper(g()));
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)
= note: `#[warn(abi_unsupported_vector_types)]` on by default

Future breakage diagnostic:
warning: this function call uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
--> $DIR/simd-abi-checks.rs:100:9
|
LL | some_extern();
| ^^^^^^^^^^^^^ function called here
|
= warning: 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 #116558 <https://github.com/rust-lang/rust/issues/116558>
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)
= note: `#[warn(abi_unsupported_vector_types)]` on by default

Future breakage diagnostic:
warning: this function definition uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled
--> $DIR/simd-abi-checks.rs:26:1
--> $DIR/simd-abi-checks.rs:27:1
|
LL | unsafe extern "C" fn g() -> __m256 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
Expand All @@ -177,7 +209,7 @@ LL | unsafe extern "C" fn g() -> __m256 {

Future breakage diagnostic:
warning: this function definition uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled
--> $DIR/simd-abi-checks.rs:20:1
--> $DIR/simd-abi-checks.rs:21:1
|
LL | unsafe extern "C" fn f(_: __m256) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
Expand All @@ -189,7 +221,7 @@ LL | unsafe extern "C" fn f(_: __m256) {

Future breakage diagnostic:
warning: this function definition uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled
--> $DIR/simd-abi-checks.rs:14:1
--> $DIR/simd-abi-checks.rs:15:1
|
LL | unsafe extern "C" fn w(_: Wrapper) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
Expand All @@ -199,3 +231,15 @@ LL | unsafe extern "C" fn w(_: Wrapper) {
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)
= note: `#[warn(abi_unsupported_vector_types)]` on by default

Future breakage diagnostic:
warning: this function call uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
--> $DIR/simd-abi-checks.rs:57:8
|
LL | || g()
| ^^^ function called here
|
= warning: 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 #116558 <https://github.com/rust-lang/rust/issues/116558>
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)
= note: `#[warn(abi_unsupported_vector_types)]` on by default

Loading