Skip to content

Commit b9a0e57

Browse files
committed
add a test for target-feature-ABI warnings in closures
1 parent 4e4c20d commit b9a0e57

File tree

3 files changed

+36
-13
lines changed

3 files changed

+36
-13
lines changed

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -576,9 +576,9 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
576576
// If this closure is marked `#[inline(always)]`, simply skip adding `#[target_feature]`.
577577
//
578578
// At this point, `unsafe` has already been checked and `#[target_feature]` only affects codegen.
579-
// Emitting both `#[inline(always)]` and `#[target_feature]` can potentially result in an
580-
// ICE, because LLVM errors when the function fails to be inlined due to a target feature
581-
// mismatch.
579+
// Due to LLVM limitations, emitting both `#[inline(always)]` and `#[target_feature]` is *unsound*:
580+
// the function may be inlined into a caller with fewer target features. Also see
581+
// <https://github.com/rust-lang/rust/issues/116573>.
582582
//
583583
// Using `#[inline(always)]` implies that this closure will most likely be inlined into
584584
// its parent function, which effectively inherits the features anyway. Boxing this closure

tests/ui/simd-abi-checks.rs

+13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#![feature(avx512_target_feature)]
66
#![feature(portable_simd)]
7+
#![feature(target_feature_11)]
78
#![allow(improper_ctypes_definitions)]
89

910
use std::arch::x86_64::*;
@@ -50,6 +51,14 @@ unsafe fn test() {
5051
as_f64x8(arg);
5152
}
5253

54+
#[target_feature(enable = "avx")]
55+
unsafe fn in_closure() -> impl FnOnce() -> __m256 {
56+
#[inline(always)] // this disables target-feature inheritance
57+
|| g()
58+
//~^ 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
59+
//~| WARNING this was previously accepted by the compiler
60+
}
61+
5362
fn main() {
5463
unsafe {
5564
f(g());
@@ -78,4 +87,8 @@ fn main() {
7887
//~| WARNING this was previously accepted by the compiler
7988
//~| WARNING this was previously accepted by the compiler
8089
}
90+
91+
unsafe {
92+
in_closure()();
93+
}
8194
}

tests/ui/simd-abi-checks.stderr

+20-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
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
2-
--> $DIR/simd-abi-checks.rs:55:11
2+
--> $DIR/simd-abi-checks.rs:64:11
33
|
44
LL | f(g());
55
| ^^^ function called here
@@ -10,7 +10,7 @@ LL | f(g());
1010
= note: `#[warn(abi_unsupported_vector_types)]` on by default
1111

1212
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
13-
--> $DIR/simd-abi-checks.rs:55:9
13+
--> $DIR/simd-abi-checks.rs:64:9
1414
|
1515
LL | f(g());
1616
| ^^^^^^ function called here
@@ -20,7 +20,7 @@ LL | f(g());
2020
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)
2121

2222
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
23-
--> $DIR/simd-abi-checks.rs:63:14
23+
--> $DIR/simd-abi-checks.rs:72:14
2424
|
2525
LL | gavx(favx());
2626
| ^^^^^^ function called here
@@ -30,7 +30,7 @@ LL | gavx(favx());
3030
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)
3131

3232
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
33-
--> $DIR/simd-abi-checks.rs:63:9
33+
--> $DIR/simd-abi-checks.rs:72:9
3434
|
3535
LL | gavx(favx());
3636
| ^^^^^^^^^^^^ function called here
@@ -40,7 +40,7 @@ LL | gavx(favx());
4040
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)
4141

4242
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
43-
--> $DIR/simd-abi-checks.rs:75:19
43+
--> $DIR/simd-abi-checks.rs:84:19
4444
|
4545
LL | w(Wrapper(g()));
4646
| ^^^ function called here
@@ -50,7 +50,7 @@ LL | w(Wrapper(g()));
5050
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)
5151

5252
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
53-
--> $DIR/simd-abi-checks.rs:75:9
53+
--> $DIR/simd-abi-checks.rs:84:9
5454
|
5555
LL | w(Wrapper(g()));
5656
| ^^^^^^^^^^^^^^^ function called here
@@ -60,7 +60,7 @@ LL | w(Wrapper(g()));
6060
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)
6161

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

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

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

92-
warning: 9 warnings emitted
92+
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
93+
--> $DIR/simd-abi-checks.rs:57:8
94+
|
95+
LL | || g()
96+
| ^^^ function called here
97+
|
98+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
99+
= note: for more information, see issue #116558 <https://github.com/rust-lang/rust/issues/116558>
100+
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)
101+
102+
warning: 10 warnings emitted
93103

94104
Future incompatibility report: Future breakage diagnostic:
95105
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

0 commit comments

Comments
 (0)