Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 83fd16f

Browse files
committedFeb 20, 2025
vectorcall ABI: error if sse2 is not available
1 parent 79b2360 commit 83fd16f

12 files changed

+102
-74
lines changed
 

‎compiler/rustc_monomorphize/messages.ftl

+14
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@ monomorphize_abi_error_unsupported_vector_type =
2222
*[false] defined
2323
} here
2424
25+
monomorphize_abi_required_target_feature =
26+
this function {$is_call ->
27+
[true] call
28+
*[false] definition
29+
} uses ABI "{$abi}" which requires the `{$required_feature}` target feature, which is not enabled{$is_call ->
30+
[true] {" "}in the caller
31+
*[false] {""}
32+
}
33+
.label = function {$is_call ->
34+
[true] called
35+
*[false] defined
36+
} here
37+
.help = consider enabling it globally (`-C target-feature=+{$required_feature}`) or locally (`#[target_feature(enable="{$required_feature}")]`)
38+
2539
monomorphize_couldnt_dump_mono_stats =
2640
unexpected error occurred while dumping monomorphization stats: {$error}
2741

‎compiler/rustc_monomorphize/src/errors.rs

+13
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,16 @@ pub(crate) struct AbiErrorUnsupportedVectorType<'a> {
9090
/// Whether this is a problem at a call site or at a declaration.
9191
pub is_call: bool,
9292
}
93+
94+
#[derive(Diagnostic)]
95+
#[diag(monomorphize_abi_required_target_feature)]
96+
#[help]
97+
pub(crate) struct AbiRequiredTargetFeature<'a> {
98+
#[primary_span]
99+
#[label]
100+
pub span: Span,
101+
pub required_feature: &'a str,
102+
pub abi: &'a str,
103+
/// Whether this is a problem at a call site or at a declaration.
104+
pub is_call: bool,
105+
}

‎compiler/rustc_monomorphize/src/mono_checks/abi_check.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ fn uses_vector_registers(mode: &PassMode, repr: &BackendRepr) -> bool {
2929
fn do_check_abi<'tcx>(
3030
tcx: TyCtxt<'tcx>,
3131
abi: &FnAbi<'tcx, Ty<'tcx>>,
32-
target_feature_def: DefId,
32+
def_id: DefId,
3333
is_call: bool,
3434
span: impl Fn() -> Span,
3535
) {
3636
let feature_def = tcx.sess.target.features_for_correct_vector_abi();
37-
let codegen_attrs = tcx.codegen_fn_attrs(target_feature_def);
37+
let codegen_attrs = tcx.codegen_fn_attrs(def_id);
3838
let have_feature = |feat: Symbol| {
3939
tcx.sess.unstable_target_features.contains(&feat)
4040
|| codegen_attrs.target_features.iter().any(|x| x.name == feat)
@@ -77,6 +77,15 @@ fn do_check_abi<'tcx>(
7777
}
7878
}
7979
}
80+
// The `vectorcall` ABI is special in that it requires SSE2 no matter which types are being passed.
81+
if abi.conv == Conv::X86VectorCall && !have_feature(sym::sse2) {
82+
tcx.dcx().emit_err(errors::AbiRequiredTargetFeature {
83+
span: span(),
84+
required_feature: "sse2",
85+
abi: "vectorcall",
86+
is_call,
87+
});
88+
}
8089
}
8190

8291
/// Checks that the ABI of a given instance of a function does not contain vector-passed arguments
File renamed without changes.

‎tests/ui/abi/simd-abi-checks.stderr ‎tests/ui/abi/simd-abi-checks-avx.stderr

+22-22
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: this function call uses SIMD vector type `std::arch::x86_64::__m256` which (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
2-
--> $DIR/simd-abi-checks.rs:64:11
2+
--> $DIR/simd-abi-checks-avx.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 SIMD vector type `std::arch::x86_64::__m256` which (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
13-
--> $DIR/simd-abi-checks.rs:64:9
13+
--> $DIR/simd-abi-checks-avx.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 SIMD vector type `std::arch::x86_64::__m256` which (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
23-
--> $DIR/simd-abi-checks.rs:72:14
23+
--> $DIR/simd-abi-checks-avx.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 SIMD vector type `std::arch::x86_64::__m256` which (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
33-
--> $DIR/simd-abi-checks.rs:72:9
33+
--> $DIR/simd-abi-checks-avx.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 SIMD vector type `std::arch::x86_64::__m256` which (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
43-
--> $DIR/simd-abi-checks.rs:84:19
43+
--> $DIR/simd-abi-checks-avx.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 SIMD vector type `Wrapper` which (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
53-
--> $DIR/simd-abi-checks.rs:84:9
53+
--> $DIR/simd-abi-checks-avx.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 call uses SIMD vector type `std::arch::x86_64::__m256` which (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
63-
--> $DIR/simd-abi-checks.rs:100:9
63+
--> $DIR/simd-abi-checks-avx.rs:100:9
6464
|
6565
LL | some_extern();
6666
| ^^^^^^^^^^^^^ function called here
@@ -70,7 +70,7 @@ LL | some_extern();
7070
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)
7171

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

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

9292
warning: this function definition uses SIMD vector type `Wrapper` which (with the chosen ABI) requires the `avx` target feature, which is not enabled
93-
--> $DIR/simd-abi-checks.rs:15:1
93+
--> $DIR/simd-abi-checks-avx.rs:15:1
9494
|
9595
LL | unsafe extern "C" fn w(_: Wrapper) {
9696
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -100,7 +100,7 @@ LL | unsafe extern "C" fn w(_: Wrapper) {
100100
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)
101101

102102
warning: this function call uses SIMD vector type `std::arch::x86_64::__m256` which (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
103-
--> $DIR/simd-abi-checks.rs:57:8
103+
--> $DIR/simd-abi-checks-avx.rs:57:8
104104
|
105105
LL | || g()
106106
| ^^^ function called here
@@ -113,7 +113,7 @@ warning: 11 warnings emitted
113113

114114
Future incompatibility report: Future breakage diagnostic:
115115
warning: this function call uses SIMD vector type `std::arch::x86_64::__m256` which (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
116-
--> $DIR/simd-abi-checks.rs:64:11
116+
--> $DIR/simd-abi-checks-avx.rs:64:11
117117
|
118118
LL | f(g());
119119
| ^^^ function called here
@@ -125,7 +125,7 @@ LL | f(g());
125125

126126
Future breakage diagnostic:
127127
warning: this function call uses SIMD vector type `std::arch::x86_64::__m256` which (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
128-
--> $DIR/simd-abi-checks.rs:64:9
128+
--> $DIR/simd-abi-checks-avx.rs:64:9
129129
|
130130
LL | f(g());
131131
| ^^^^^^ function called here
@@ -137,7 +137,7 @@ LL | f(g());
137137

138138
Future breakage diagnostic:
139139
warning: this function call uses SIMD vector type `std::arch::x86_64::__m256` which (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
140-
--> $DIR/simd-abi-checks.rs:72:14
140+
--> $DIR/simd-abi-checks-avx.rs:72:14
141141
|
142142
LL | gavx(favx());
143143
| ^^^^^^ function called here
@@ -149,7 +149,7 @@ LL | gavx(favx());
149149

150150
Future breakage diagnostic:
151151
warning: this function call uses SIMD vector type `std::arch::x86_64::__m256` which (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
152-
--> $DIR/simd-abi-checks.rs:72:9
152+
--> $DIR/simd-abi-checks-avx.rs:72:9
153153
|
154154
LL | gavx(favx());
155155
| ^^^^^^^^^^^^ function called here
@@ -161,7 +161,7 @@ LL | gavx(favx());
161161

162162
Future breakage diagnostic:
163163
warning: this function call uses SIMD vector type `std::arch::x86_64::__m256` which (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
164-
--> $DIR/simd-abi-checks.rs:84:19
164+
--> $DIR/simd-abi-checks-avx.rs:84:19
165165
|
166166
LL | w(Wrapper(g()));
167167
| ^^^ function called here
@@ -173,7 +173,7 @@ LL | w(Wrapper(g()));
173173

174174
Future breakage diagnostic:
175175
warning: this function call uses SIMD vector type `Wrapper` which (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
176-
--> $DIR/simd-abi-checks.rs:84:9
176+
--> $DIR/simd-abi-checks-avx.rs:84:9
177177
|
178178
LL | w(Wrapper(g()));
179179
| ^^^^^^^^^^^^^^^ function called here
@@ -185,7 +185,7 @@ LL | w(Wrapper(g()));
185185

186186
Future breakage diagnostic:
187187
warning: this function call uses SIMD vector type `std::arch::x86_64::__m256` which (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
188-
--> $DIR/simd-abi-checks.rs:100:9
188+
--> $DIR/simd-abi-checks-avx.rs:100:9
189189
|
190190
LL | some_extern();
191191
| ^^^^^^^^^^^^^ function called here
@@ -197,7 +197,7 @@ LL | some_extern();
197197

198198
Future breakage diagnostic:
199199
warning: this function definition uses SIMD vector type `std::arch::x86_64::__m256` which (with the chosen ABI) requires the `avx` target feature, which is not enabled
200-
--> $DIR/simd-abi-checks.rs:27:1
200+
--> $DIR/simd-abi-checks-avx.rs:27:1
201201
|
202202
LL | unsafe extern "C" fn g() -> __m256 {
203203
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -209,7 +209,7 @@ LL | unsafe extern "C" fn g() -> __m256 {
209209

210210
Future breakage diagnostic:
211211
warning: this function definition uses SIMD vector type `std::arch::x86_64::__m256` which (with the chosen ABI) requires the `avx` target feature, which is not enabled
212-
--> $DIR/simd-abi-checks.rs:21:1
212+
--> $DIR/simd-abi-checks-avx.rs:21:1
213213
|
214214
LL | unsafe extern "C" fn f(_: __m256) {
215215
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -221,7 +221,7 @@ LL | unsafe extern "C" fn f(_: __m256) {
221221

222222
Future breakage diagnostic:
223223
warning: this function definition uses SIMD vector type `Wrapper` which (with the chosen ABI) requires the `avx` target feature, which is not enabled
224-
--> $DIR/simd-abi-checks.rs:15:1
224+
--> $DIR/simd-abi-checks-avx.rs:15:1
225225
|
226226
LL | unsafe extern "C" fn w(_: Wrapper) {
227227
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -233,7 +233,7 @@ LL | unsafe extern "C" fn w(_: Wrapper) {
233233

234234
Future breakage diagnostic:
235235
warning: this function call uses SIMD vector type `std::arch::x86_64::__m256` which (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
236-
--> $DIR/simd-abi-checks.rs:57:8
236+
--> $DIR/simd-abi-checks-avx.rs:57:8
237237
|
238238
LL | || g()
239239
| ^^^ function called here
File renamed without changes.

‎tests/ui/abi/sse-abi-checks.stderr ‎tests/ui/abi/simd-abi-checks-sse.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: this function definition uses SIMD vector type `SseVector` which (with the chosen ABI) requires the `sse` target feature, which is not enabled
2-
--> $DIR/sse-simd-abi-checks.rs:20:1
2+
--> $DIR/simd-abi-checks-sse.rs:20:1
33
|
44
LL | pub unsafe extern "C" fn f(_: SseVector) {
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
@@ -13,7 +13,7 @@ warning: 1 warning emitted
1313

1414
Future incompatibility report: Future breakage diagnostic:
1515
warning: this function definition uses SIMD vector type `SseVector` which (with the chosen ABI) requires the `sse` target feature, which is not enabled
16-
--> $DIR/sse-simd-abi-checks.rs:20:1
16+
--> $DIR/simd-abi-checks-sse.rs:20:1
1717
|
1818
LL | pub unsafe extern "C" fn f(_: SseVector) {
1919
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here

‎tests/ui/abi/vectorcall-abi-checks.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//@ add-core-stubs
2+
//@ compile-flags: --crate-type=rlib --target=i586-unknown-linux-gnu -C target-feature=-sse,-sse2
3+
//@ build-fail
4+
//@ ignore-pass (test emits codegen-time errors)
5+
//@ needs-llvm-components: x86
6+
#![feature(no_core, abi_vectorcall)]
7+
#![no_core]
8+
9+
extern crate minicore;
10+
use minicore::*;
11+
12+
#[no_mangle]
13+
pub extern "vectorcall" fn f() {
14+
//~^ ABI "vectorcall" which requires the `sse2` target feature
15+
}
16+
17+
#[no_mangle]
18+
pub fn call_site() {
19+
f();
20+
//~^ ABI "vectorcall" which requires the `sse2` target feature
21+
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error: this function definition uses ABI "vectorcall" which requires the `sse2` target feature, which is not enabled
2+
--> $DIR/vectorcall-abi-checks.rs:13:1
3+
|
4+
LL | pub extern "vectorcall" fn f() {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
6+
|
7+
= help: consider enabling it globally (`-C target-feature=+sse2`) or locally (`#[target_feature(enable="sse2")]`)
8+
9+
error: this function call uses ABI "vectorcall" which requires the `sse2` target feature, which is not enabled in the caller
10+
--> $DIR/vectorcall-abi-checks.rs:19:5
11+
|
12+
LL | f();
13+
| ^^^ function called here
14+
|
15+
= help: consider enabling it globally (`-C target-feature=+sse2`) or locally (`#[target_feature(enable="sse2")]`)
16+
17+
error: aborting due to 2 previous errors
18+

‎tests/ui/extern/extern-vectorcall.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//@ revisions: x64 x32
33
//@ [x64]only-x86_64
44
//@ [x32]only-x86
5+
//@ [x32]compile-flags: -Ctarget-feature=+sse2
56

67
#![feature(abi_vectorcall)]
78

‎tests/ui/sse-simd-abi-checks.rs

-23
This file was deleted.

‎tests/ui/sse-simd-abi-checks.stderr

-25
This file was deleted.

0 commit comments

Comments
 (0)
Failed to load comments.