Skip to content

Commit 30a21b5

Browse files
committed
ABI checks: add support for tier2 arches
See #131800 for the data collection behind this change. Also adds a test that exercise the "empty list of features" path.
1 parent 6689597 commit 30a21b5

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

compiler/rustc_target/src/target_features.rs

+19-1
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,14 @@ pub fn all_rust_features() -> impl Iterator<Item = (&'static str, Stability)> {
582582
const X86_FEATURES_FOR_CORRECT_VECTOR_ABI: &'static [(u64, &'static str)] =
583583
&[(128, "sse"), (256, "avx"), (512, "avx512f")];
584584
const AARCH64_FEATURES_FOR_CORRECT_VECTOR_ABI: &'static [(u64, &'static str)] = &[(128, "neon")];
585+
const ARM_FEATURES_FOR_CORRECT_VECTOR_ABI: &'static [(u64, &'static str)] = &[(128, "neon")];
586+
const POWERPC_FEATURES_FOR_CORRECT_VECTOR_ABI: &'static [(u64, &'static str)] = &[(128, "altivec")];
587+
const WASM_FEATURES_FOR_CORRECT_VECTOR_ABI: &'static [(u64, &'static str)] = &[(128, "simd128")];
588+
const S390X_FEATURES_FOR_CORRECT_VECTOR_ABI: &'static [(u64, &'static str)] = &[(128, "vector")];
589+
// Always warn on RISCV and SPARC, as the necessary target features cannot be enabled in Rust at
590+
// the moment.
591+
const RISCV_FEATURES_FOR_CORRECT_VECTOR_ABI: &'static [(u64, &'static str)] = &[];
592+
const SPARC_FEATURES_FOR_CORRECT_VECTOR_ABI: &'static [(u64, &'static str)] = &[];
585593

586594
impl super::spec::Target {
587595
pub fn rust_target_features(&self) -> &'static [(&'static str, Stability, ImpliedFeatures)] {
@@ -606,9 +614,19 @@ impl super::spec::Target {
606614
// Returns None if we do not support ABI checks on the given target yet.
607615
pub fn features_for_correct_vector_abi(&self) -> Option<&'static [(u64, &'static str)]> {
608616
match &*self.arch {
617+
// Tier 1
609618
"x86" | "x86_64" => Some(X86_FEATURES_FOR_CORRECT_VECTOR_ABI),
610619
"aarch64" => Some(AARCH64_FEATURES_FOR_CORRECT_VECTOR_ABI),
611-
// FIXME: add support for non-tier1 architectures
620+
// Tier 2
621+
"arm64ec" => Some(AARCH64_FEATURES_FOR_CORRECT_VECTOR_ABI),
622+
"arm" => Some(ARM_FEATURES_FOR_CORRECT_VECTOR_ABI),
623+
"powerpc" | "powerpc64" => Some(POWERPC_FEATURES_FOR_CORRECT_VECTOR_ABI),
624+
"loongarch64" => Some(&[]), // on-stack ABI, so we complain about all by-val vectors
625+
"riscv32" | "riscv64" => Some(RISCV_FEATURES_FOR_CORRECT_VECTOR_ABI),
626+
"wasm32" | "wasm64" => Some(WASM_FEATURES_FOR_CORRECT_VECTOR_ABI),
627+
"s390x" => Some(S390X_FEATURES_FOR_CORRECT_VECTOR_ABI),
628+
"sparc" | "sparc64" => Some(SPARC_FEATURES_FOR_CORRECT_VECTOR_ABI),
629+
// FIXME: add support for non-tier2 architectures
612630
_ => None,
613631
}
614632
}
+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+
//~^ ABI error: this function definition uses a vector type that requires the `<no available feature for this size>` target feature, which is not enabled
19+
//~| WARNING this was previously accepted by the compiler
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
warning: ABI error: this function definition uses a vector type that requires the `<no available feature for this size>` target feature, which is not enabled
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+
= help: consider enabling it globally (`-C target-feature=+<no available feature for this size>`) or locally (`#[target_feature(enable="<no available feature for this size>")]`)
10+
= note: `#[warn(abi_unsupported_vector_types)]` on by default
11+
12+
warning: 1 warning emitted
13+

0 commit comments

Comments
 (0)