Skip to content

Commit cd9b5c1

Browse files
committed
vectorcall ABI: error if sse2 is not available
1 parent 7b1d030 commit cd9b5c1

File tree

5 files changed

+77
-2
lines changed

5 files changed

+77
-2
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
@@ -30,12 +30,12 @@ fn uses_vector_registers(mode: &PassMode, repr: &BackendRepr) -> bool {
3030
fn do_check_abi<'tcx>(
3131
tcx: TyCtxt<'tcx>,
3232
abi: &FnAbi<'tcx, Ty<'tcx>>,
33-
target_feature_def: DefId,
33+
def_id: DefId,
3434
is_call: bool,
3535
span: impl Fn() -> Span,
3636
) {
3737
let feature_def = tcx.sess.target.features_for_correct_vector_abi();
38-
let codegen_attrs = tcx.codegen_fn_attrs(target_feature_def);
38+
let codegen_attrs = tcx.codegen_fn_attrs(def_id);
3939
let have_feature = |feat: Symbol| {
4040
tcx.sess.unstable_target_features.contains(&feat)
4141
|| codegen_attrs.target_features.iter().any(|x| x.name == feat)
@@ -78,6 +78,15 @@ fn do_check_abi<'tcx>(
7878
}
7979
}
8080
}
81+
// The `vectorcall` ABI is special in that it requires SSE2 no matter which types are being passed.
82+
if abi.conv == Conv::X86VectorCall && !have_feature(sym::sse2) {
83+
tcx.dcx().emit_err(errors::AbiRequiredTargetFeature {
84+
span: span(),
85+
required_feature: "sse2",
86+
abi: "vectorcall",
87+
is_call,
88+
});
89+
}
8190
}
8291

8392
/// Checks that the ABI of a given instance of a function does not contain vector-passed arguments

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+

0 commit comments

Comments
 (0)