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 aacc97d

Browse files
authoredNov 14, 2024··
Unrolled build for rust-lang#132842
Rollup merge of rust-lang#132842 - veluca93:abi-checks-tier2, r=workingjubilee ABI checks: add support for tier2 arches See rust-lang#131800 for the data collection behind this change. r? RalfJung
2 parents 8adb4b3 + 295cffc commit aacc97d

10 files changed

+136
-41
lines changed
 

‎compiler/rustc_monomorphize/messages.ftl

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
monomorphize_abi_error_disabled_vector_type_call =
2-
ABI error: this function call uses a vector type that requires the `{$required_feature}` target feature, which is not enabled in the caller
2+
this function call uses a SIMD vector type that (with the chosen ABI) requires the `{$required_feature}` target feature, which is not enabled in the caller
33
.label = function called here
44
.help = consider enabling it globally (`-C target-feature=+{$required_feature}`) or locally (`#[target_feature(enable="{$required_feature}")]`)
55
monomorphize_abi_error_disabled_vector_type_def =
6-
ABI error: this function definition uses a vector type that requires the `{$required_feature}` target feature, which is not enabled
6+
this function definition uses a SIMD vector type that (with the chosen ABI) requires the `{$required_feature}` target feature, which is not enabled
77
.label = function defined here
88
.help = consider enabling it globally (`-C target-feature=+{$required_feature}`) or locally (`#[target_feature(enable="{$required_feature}")]`)
99
10+
monomorphize_abi_error_unsupported_vector_type_call =
11+
this function call uses a SIMD vector type that is not currently supported with the chosen ABI
12+
.label = function called here
13+
monomorphize_abi_error_unsupported_vector_type_def =
14+
this function definition uses a SIMD vector type that is not currently supported with the chosen ABI
15+
.label = function defined here
16+
1017
monomorphize_couldnt_dump_mono_stats =
1118
unexpected error occurred while dumping monomorphization stats: {$error}
1219

‎compiler/rustc_monomorphize/src/errors.rs

+14
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,17 @@ pub(crate) struct AbiErrorDisabledVectorTypeCall<'a> {
110110
pub span: Span,
111111
pub required_feature: &'a str,
112112
}
113+
114+
#[derive(LintDiagnostic)]
115+
#[diag(monomorphize_abi_error_unsupported_vector_type_def)]
116+
pub(crate) struct AbiErrorUnsupportedVectorTypeDef {
117+
#[label]
118+
pub span: Span,
119+
}
120+
121+
#[derive(LintDiagnostic)]
122+
#[diag(monomorphize_abi_error_unsupported_vector_type_call)]
123+
pub(crate) struct AbiErrorUnsupportedVectorTypeCall {
124+
#[label]
125+
pub span: Span,
126+
}

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

+41-16
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ use rustc_span::{DUMMY_SP, Span, Symbol};
1010
use rustc_target::abi::call::{FnAbi, PassMode};
1111
use rustc_target::abi::{BackendRepr, RegKind};
1212

13-
use crate::errors::{AbiErrorDisabledVectorTypeCall, AbiErrorDisabledVectorTypeDef};
13+
use crate::errors::{
14+
AbiErrorDisabledVectorTypeCall, AbiErrorDisabledVectorTypeDef,
15+
AbiErrorUnsupportedVectorTypeCall, AbiErrorUnsupportedVectorTypeDef,
16+
};
1417

1518
fn uses_vector_registers(mode: &PassMode, repr: &BackendRepr) -> bool {
1619
match mode {
@@ -23,11 +26,15 @@ fn uses_vector_registers(mode: &PassMode, repr: &BackendRepr) -> bool {
2326
}
2427
}
2528

29+
/// Checks whether a certain function ABI is compatible with the target features currently enabled
30+
/// for a certain function.
31+
/// If not, `emit_err` is called, with `Some(feature)` if a certain feature should be enabled and
32+
/// with `None` if no feature is known that would make the ABI compatible.
2633
fn do_check_abi<'tcx>(
2734
tcx: TyCtxt<'tcx>,
2835
abi: &FnAbi<'tcx, Ty<'tcx>>,
2936
target_feature_def: DefId,
30-
mut emit_err: impl FnMut(&'static str),
37+
mut emit_err: impl FnMut(Option<&'static str>),
3138
) {
3239
let Some(feature_def) = tcx.sess.target.features_for_correct_vector_abi() else {
3340
return;
@@ -40,15 +47,15 @@ fn do_check_abi<'tcx>(
4047
let feature = match feature_def.iter().find(|(bits, _)| size.bits() <= *bits) {
4148
Some((_, feature)) => feature,
4249
None => {
43-
emit_err("<no available feature for this size>");
50+
emit_err(None);
4451
continue;
4552
}
4653
};
4754
let feature_sym = Symbol::intern(feature);
4855
if !tcx.sess.unstable_target_features.contains(&feature_sym)
4956
&& !codegen_attrs.target_features.iter().any(|x| x.name == feature_sym)
5057
{
51-
emit_err(feature);
58+
emit_err(Some(&feature));
5259
}
5360
}
5461
}
@@ -65,12 +72,21 @@ fn check_instance_abi<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) {
6572
};
6673
do_check_abi(tcx, abi, instance.def_id(), |required_feature| {
6774
let span = tcx.def_span(instance.def_id());
68-
tcx.emit_node_span_lint(
69-
ABI_UNSUPPORTED_VECTOR_TYPES,
70-
CRATE_HIR_ID,
71-
span,
72-
AbiErrorDisabledVectorTypeDef { span, required_feature },
73-
);
75+
if let Some(required_feature) = required_feature {
76+
tcx.emit_node_span_lint(
77+
ABI_UNSUPPORTED_VECTOR_TYPES,
78+
CRATE_HIR_ID,
79+
span,
80+
AbiErrorDisabledVectorTypeDef { span, required_feature },
81+
);
82+
} else {
83+
tcx.emit_node_span_lint(
84+
ABI_UNSUPPORTED_VECTOR_TYPES,
85+
CRATE_HIR_ID,
86+
span,
87+
AbiErrorUnsupportedVectorTypeDef { span },
88+
);
89+
}
7490
})
7591
}
7692

@@ -109,12 +125,21 @@ fn check_call_site_abi<'tcx>(
109125
return;
110126
};
111127
do_check_abi(tcx, callee_abi, caller.def_id(), |required_feature| {
112-
tcx.emit_node_span_lint(
113-
ABI_UNSUPPORTED_VECTOR_TYPES,
114-
CRATE_HIR_ID,
115-
span,
116-
AbiErrorDisabledVectorTypeCall { span, required_feature },
117-
);
128+
if let Some(required_feature) = required_feature {
129+
tcx.emit_node_span_lint(
130+
ABI_UNSUPPORTED_VECTOR_TYPES,
131+
CRATE_HIR_ID,
132+
span,
133+
AbiErrorDisabledVectorTypeCall { span, required_feature },
134+
);
135+
} else {
136+
tcx.emit_node_span_lint(
137+
ABI_UNSUPPORTED_VECTOR_TYPES,
138+
CRATE_HIR_ID,
139+
span,
140+
AbiErrorUnsupportedVectorTypeCall { span },
141+
);
142+
}
118143
});
119144
}
120145

‎compiler/rustc_target/src/target_features.rs

+21-3
Original file line numberDiff line numberDiff line change
@@ -586,9 +586,20 @@ pub fn all_rust_features() -> impl Iterator<Item = (&'static str, Stability)> {
586586
// certain size to have their "proper" ABI on each architecture.
587587
// Note that they must be kept sorted by vector size.
588588
const X86_FEATURES_FOR_CORRECT_VECTOR_ABI: &'static [(u64, &'static str)] =
589-
&[(128, "sse"), (256, "avx"), (512, "avx512f")];
589+
&[(128, "sse"), (256, "avx"), (512, "avx512f")]; // FIXME: might need changes for AVX10.
590590
const AARCH64_FEATURES_FOR_CORRECT_VECTOR_ABI: &'static [(u64, &'static str)] = &[(128, "neon")];
591591

592+
// We might want to add "helium" too.
593+
const ARM_FEATURES_FOR_CORRECT_VECTOR_ABI: &'static [(u64, &'static str)] = &[(128, "neon")];
594+
595+
const POWERPC_FEATURES_FOR_CORRECT_VECTOR_ABI: &'static [(u64, &'static str)] = &[(128, "altivec")];
596+
const WASM_FEATURES_FOR_CORRECT_VECTOR_ABI: &'static [(u64, &'static str)] = &[(128, "simd128")];
597+
const S390X_FEATURES_FOR_CORRECT_VECTOR_ABI: &'static [(u64, &'static str)] = &[(128, "vector")];
598+
const RISCV_FEATURES_FOR_CORRECT_VECTOR_ABI: &'static [(u64, &'static str)] =
599+
&[/*(64, "zvl64b"), */ (128, "v")];
600+
// Always warn on SPARC, as the necessary target features cannot be enabled in Rust at the moment.
601+
const SPARC_FEATURES_FOR_CORRECT_VECTOR_ABI: &'static [(u64, &'static str)] = &[/*(128, "vis")*/];
602+
592603
impl super::spec::Target {
593604
pub fn rust_target_features(&self) -> &'static [(&'static str, Stability, ImpliedFeatures)] {
594605
match &*self.arch {
@@ -613,8 +624,15 @@ impl super::spec::Target {
613624
pub fn features_for_correct_vector_abi(&self) -> Option<&'static [(u64, &'static str)]> {
614625
match &*self.arch {
615626
"x86" | "x86_64" => Some(X86_FEATURES_FOR_CORRECT_VECTOR_ABI),
616-
"aarch64" => Some(AARCH64_FEATURES_FOR_CORRECT_VECTOR_ABI),
617-
// FIXME: add support for non-tier1 architectures
627+
"aarch64" | "arm64ec" => Some(AARCH64_FEATURES_FOR_CORRECT_VECTOR_ABI),
628+
"arm" => Some(ARM_FEATURES_FOR_CORRECT_VECTOR_ABI),
629+
"powerpc" | "powerpc64" => Some(POWERPC_FEATURES_FOR_CORRECT_VECTOR_ABI),
630+
"loongarch64" => Some(&[]), // on-stack ABI, so we complain about all by-val vectors
631+
"riscv32" | "riscv64" => Some(RISCV_FEATURES_FOR_CORRECT_VECTOR_ABI),
632+
"wasm32" | "wasm64" => Some(WASM_FEATURES_FOR_CORRECT_VECTOR_ABI),
633+
"s390x" => Some(S390X_FEATURES_FOR_CORRECT_VECTOR_ABI),
634+
"sparc" | "sparc64" => Some(SPARC_FEATURES_FOR_CORRECT_VECTOR_ABI),
635+
// FIXME: add support for non-tier2 architectures
618636
_ => None,
619637
}
620638
}
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//@ needs-llvm-components: sparc
2+
//@ compile-flags: --target=sparc-unknown-none-elf --crate-type=rlib
3+
//@ build-pass
4+
//@ ignore-pass (test emits codegen-time warnings)
5+
#![no_core]
6+
#![feature(no_core, lang_items, repr_simd)]
7+
#![allow(improper_ctypes_definitions)]
8+
#[lang = "sized"]
9+
trait Sized {}
10+
11+
#[lang = "copy"]
12+
trait Copy {}
13+
14+
#[repr(simd)]
15+
pub struct SimdVec([i32; 4]);
16+
17+
pub extern "C" fn pass_by_vec(_: SimdVec) {}
18+
//~^ this function definition uses a SIMD vector type that is not currently supported with the chosen ABI
19+
//~| WARNING this was previously accepted by the compiler
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
warning: this function definition uses a SIMD vector type that is not currently supported with the chosen ABI
2+
--> $DIR/simd-abi-checks-empty-list.rs:17:1
3+
|
4+
LL | pub extern "C" fn pass_by_vec(_: SimdVec) {}
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
6+
|
7+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8+
= note: for more information, see issue #116558 <https://github.com/rust-lang/rust/issues/116558>
9+
= note: `#[warn(abi_unsupported_vector_types)]` on by default
10+
11+
warning: 1 warning emitted
12+

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

+9-9
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ use std::arch::x86_64::*;
1212
struct Wrapper(__m256);
1313

1414
unsafe extern "C" fn w(_: Wrapper) {
15-
//~^ ABI error: this function definition uses a vector type that requires the `avx` target feature, which is not enabled
15+
//~^ this function definition uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled
1616
//~| WARNING this was previously accepted by the compiler
1717
todo!()
1818
}
1919

2020
unsafe extern "C" fn f(_: __m256) {
21-
//~^ ABI error: this function definition uses a vector type that requires the `avx` target feature, which is not enabled
21+
//~^ this function definition uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled
2222
//~| WARNING this was previously accepted by the compiler
2323
todo!()
2424
}
2525

2626
unsafe extern "C" fn g() -> __m256 {
27-
//~^ ABI error: this function definition uses a vector type that requires the `avx` target feature, which is not enabled
27+
//~^ this function definition uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled
2828
//~| WARNING this was previously accepted by the compiler
2929
todo!()
3030
}
@@ -53,16 +53,16 @@ unsafe fn test() {
5353
fn main() {
5454
unsafe {
5555
f(g());
56-
//~^ WARNING ABI error: this function call uses a vector type that requires the `avx` target feature, which is not enabled in the caller
57-
//~| WARNING ABI error: this function call uses a vector type that requires the `avx` target feature, which is not enabled in the caller
56+
//~^ 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
57+
//~| 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
5858
//~| WARNING this was previously accepted by the compiler
5959
//~| WARNING this was previously accepted by the compiler
6060
}
6161

6262
unsafe {
6363
gavx(favx());
64-
//~^ WARNING ABI error: this function call uses a vector type that requires the `avx` target feature, which is not enabled in the caller
65-
//~| WARNING ABI error: this function call uses a vector type that requires the `avx` target feature, which is not enabled in the caller
64+
//~^ 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
65+
//~| 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
6666
//~| WARNING this was previously accepted by the compiler
6767
//~| WARNING this was previously accepted by the compiler
6868
}
@@ -73,8 +73,8 @@ fn main() {
7373

7474
unsafe {
7575
w(Wrapper(g()));
76-
//~^ WARNING ABI error: this function call uses a vector type that requires the `avx` target feature, which is not enabled in the caller
77-
//~| WARNING ABI error: this function call uses a vector type that requires the `avx` target feature, which is not enabled in the caller
76+
//~^ 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
77+
//~| 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
7878
//~| WARNING this was previously accepted by the compiler
7979
//~| WARNING this was previously accepted by the compiler
8080
}

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

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
warning: ABI error: this function call uses a vector type that requires the `avx` target feature, which is not enabled in the caller
1+
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
22
--> $DIR/simd-abi-checks.rs:55:11
33
|
44
LL | f(g());
@@ -9,7 +9,7 @@ LL | f(g());
99
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)
1010
= note: `#[warn(abi_unsupported_vector_types)]` on by default
1111

12-
warning: ABI error: this function call uses a vector type that requires the `avx` target feature, which is not enabled in the caller
12+
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
1313
--> $DIR/simd-abi-checks.rs:55:9
1414
|
1515
LL | f(g());
@@ -19,7 +19,7 @@ LL | f(g());
1919
= note: for more information, see issue #116558 <https://github.com/rust-lang/rust/issues/116558>
2020
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)
2121

22-
warning: ABI error: this function call uses a vector type that requires the `avx` target feature, which is not enabled in the caller
22+
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
2323
--> $DIR/simd-abi-checks.rs:63:14
2424
|
2525
LL | gavx(favx());
@@ -29,7 +29,7 @@ LL | gavx(favx());
2929
= note: for more information, see issue #116558 <https://github.com/rust-lang/rust/issues/116558>
3030
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)
3131

32-
warning: ABI error: this function call uses a vector type that requires the `avx` target feature, which is not enabled in the caller
32+
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
3333
--> $DIR/simd-abi-checks.rs:63:9
3434
|
3535
LL | gavx(favx());
@@ -39,7 +39,7 @@ LL | gavx(favx());
3939
= note: for more information, see issue #116558 <https://github.com/rust-lang/rust/issues/116558>
4040
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)
4141

42-
warning: ABI error: this function call uses a vector type that requires the `avx` target feature, which is not enabled in the caller
42+
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
4343
--> $DIR/simd-abi-checks.rs:75:19
4444
|
4545
LL | w(Wrapper(g()));
@@ -49,7 +49,7 @@ LL | w(Wrapper(g()));
4949
= note: for more information, see issue #116558 <https://github.com/rust-lang/rust/issues/116558>
5050
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)
5151

52-
warning: ABI error: this function call uses a vector type that requires the `avx` target feature, which is not enabled in the caller
52+
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
5353
--> $DIR/simd-abi-checks.rs:75:9
5454
|
5555
LL | w(Wrapper(g()));
@@ -59,7 +59,7 @@ LL | w(Wrapper(g()));
5959
= note: for more information, see issue #116558 <https://github.com/rust-lang/rust/issues/116558>
6060
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)
6161

62-
warning: ABI error: this function definition uses a vector type that requires the `avx` target feature, which is not enabled
62+
warning: this function definition uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled
6363
--> $DIR/simd-abi-checks.rs:26:1
6464
|
6565
LL | unsafe extern "C" fn g() -> __m256 {
@@ -69,7 +69,7 @@ LL | unsafe extern "C" fn g() -> __m256 {
6969
= note: for more information, see issue #116558 <https://github.com/rust-lang/rust/issues/116558>
7070
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)
7171

72-
warning: ABI error: this function definition uses a vector type that requires the `avx` target feature, which is not enabled
72+
warning: this function definition uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled
7373
--> $DIR/simd-abi-checks.rs:20:1
7474
|
7575
LL | unsafe extern "C" fn f(_: __m256) {
@@ -79,7 +79,7 @@ LL | unsafe extern "C" fn f(_: __m256) {
7979
= note: for more information, see issue #116558 <https://github.com/rust-lang/rust/issues/116558>
8080
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)
8181

82-
warning: ABI error: this function definition uses a vector type that requires the `avx` target feature, which is not enabled
82+
warning: this function definition uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled
8383
--> $DIR/simd-abi-checks.rs:14:1
8484
|
8585
LL | unsafe extern "C" fn w(_: Wrapper) {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ pub struct SseVector([i64; 2]);
1919

2020
#[no_mangle]
2121
pub unsafe extern "C" fn f(_: SseVector) {
22-
//~^ ABI error: this function definition uses a vector type that requires the `sse` target feature, which is not enabled
22+
//~^ this function definition uses a SIMD vector type that (with the chosen ABI) requires the `sse` target feature, which is not enabled
2323
//~| WARNING this was previously accepted by the compiler
2424
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
warning: ABI error: this function definition uses a vector type that requires the `sse` target feature, which is not enabled
1+
warning: this function definition uses a SIMD vector type that (with the chosen ABI) requires the `sse` target feature, which is not enabled
22
--> $DIR/sse-abi-checks.rs:21:1
33
|
44
LL | pub unsafe extern "C" fn f(_: SseVector) {

0 commit comments

Comments
 (0)
Please sign in to comment.