c8b76bcf58
On some architectures, vector types may have a different ABI depending on whether the relevant target features are enabled. (The ABI when the feature is disabled is often not specified, but LLVM implements some de-facto ABI.) As discussed in rust-lang/lang-team#235, this turns out to very easily lead to unsound code. This commit makes it a post-monomorphization future-incompat warning to declare or call functions using those vector types in a context in which the corresponding target features are disabled, if using an ABI for which the difference is relevant. This ensures that these functions are always called with a consistent ABI. See the [nomination comment](https://github.com/rust-lang/rust/pull/127731#issuecomment-2288558187) for more discussion. Part of #116558
82 lines
2.8 KiB
Rust
82 lines
2.8 KiB
Rust
//@ only-x86_64
|
|
//@ build-pass
|
|
//@ ignore-pass (test emits codegen-time warnings)
|
|
|
|
#![feature(avx512_target_feature)]
|
|
#![feature(portable_simd)]
|
|
#![allow(improper_ctypes_definitions)]
|
|
|
|
use std::arch::x86_64::*;
|
|
|
|
#[repr(transparent)]
|
|
struct Wrapper(__m256);
|
|
|
|
unsafe extern "C" fn w(_: Wrapper) {
|
|
//~^ ABI error: this function definition uses a vector type that requires the `avx` target feature, which is not enabled
|
|
//~| WARNING this was previously accepted by the compiler
|
|
todo!()
|
|
}
|
|
|
|
unsafe extern "C" fn f(_: __m256) {
|
|
//~^ ABI error: this function definition uses a vector type that requires the `avx` target feature, which is not enabled
|
|
//~| WARNING this was previously accepted by the compiler
|
|
todo!()
|
|
}
|
|
|
|
unsafe extern "C" fn g() -> __m256 {
|
|
//~^ ABI error: this function definition uses a vector type that requires the `avx` target feature, which is not enabled
|
|
//~| WARNING this was previously accepted by the compiler
|
|
todo!()
|
|
}
|
|
|
|
#[target_feature(enable = "avx")]
|
|
unsafe extern "C" fn favx() -> __m256 {
|
|
todo!()
|
|
}
|
|
|
|
// avx2 implies avx, so no error here.
|
|
#[target_feature(enable = "avx2")]
|
|
unsafe extern "C" fn gavx(_: __m256) {
|
|
todo!()
|
|
}
|
|
|
|
// No error because of "Rust" ABI.
|
|
fn as_f64x8(d: __m512d) -> std::simd::f64x8 {
|
|
unsafe { std::mem::transmute(d) }
|
|
}
|
|
|
|
unsafe fn test() {
|
|
let arg = std::mem::transmute([0.0f64; 8]);
|
|
as_f64x8(arg);
|
|
}
|
|
|
|
fn main() {
|
|
unsafe {
|
|
f(g());
|
|
//~^ WARNING ABI error: this function call uses a vector type that requires the `avx` target feature, which is not enabled in the caller
|
|
//~| WARNING ABI error: this function call uses a vector type that requires the `avx` target feature, which is not enabled in the caller
|
|
//~| WARNING this was previously accepted by the compiler
|
|
//~| WARNING this was previously accepted by the compiler
|
|
}
|
|
|
|
unsafe {
|
|
gavx(favx());
|
|
//~^ WARNING ABI error: this function call uses a vector type that requires the `avx` target feature, which is not enabled in the caller
|
|
//~| WARNING ABI error: this function call uses a vector type that requires the `avx` target feature, which is not enabled in the caller
|
|
//~| WARNING this was previously accepted by the compiler
|
|
//~| WARNING this was previously accepted by the compiler
|
|
}
|
|
|
|
unsafe {
|
|
test();
|
|
}
|
|
|
|
unsafe {
|
|
w(Wrapper(g()));
|
|
//~^ WARNING ABI error: this function call uses a vector type that requires the `avx` target feature, which is not enabled in the caller
|
|
//~| WARNING ABI error: this function call uses a vector type that requires the `avx` target feature, which is not enabled in the caller
|
|
//~| WARNING this was previously accepted by the compiler
|
|
//~| WARNING this was previously accepted by the compiler
|
|
}
|
|
}
|