Auto merge of #132173 - veluca93:abi_checks, r=RalfJung,compiler-errors
Emit warning when calling/declaring functions with unavailable vectors. 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 r? RalfJung
This commit is contained in:
commit
7660aed73d
17 changed files with 514 additions and 61 deletions
|
@ -576,6 +576,13 @@ pub fn all_rust_features() -> impl Iterator<Item = (&'static str, Stability)> {
|
|||
.map(|(f, s, _)| (f, s))
|
||||
}
|
||||
|
||||
// These arrays represent the least-constraining feature that is required for vector types up to a
|
||||
// certain size to have their "proper" ABI on each architecture.
|
||||
// Note that they must be kept sorted by vector size.
|
||||
const X86_FEATURES_FOR_CORRECT_VECTOR_ABI: &'static [(u64, &'static str)] =
|
||||
&[(128, "sse"), (256, "avx"), (512, "avx512f")];
|
||||
const AARCH64_FEATURES_FOR_CORRECT_VECTOR_ABI: &'static [(u64, &'static str)] = &[(128, "neon")];
|
||||
|
||||
impl super::spec::Target {
|
||||
pub fn rust_target_features(&self) -> &'static [(&'static str, Stability, ImpliedFeatures)] {
|
||||
match &*self.arch {
|
||||
|
@ -596,6 +603,16 @@ impl super::spec::Target {
|
|||
}
|
||||
}
|
||||
|
||||
// Returns None if we do not support ABI checks on the given target yet.
|
||||
pub fn features_for_correct_vector_abi(&self) -> Option<&'static [(u64, &'static str)]> {
|
||||
match &*self.arch {
|
||||
"x86" | "x86_64" => Some(X86_FEATURES_FOR_CORRECT_VECTOR_ABI),
|
||||
"aarch64" => Some(AARCH64_FEATURES_FOR_CORRECT_VECTOR_ABI),
|
||||
// FIXME: add support for non-tier1 architectures
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn tied_target_features(&self) -> &'static [&'static [&'static str]] {
|
||||
match &*self.arch {
|
||||
"aarch64" | "arm64ec" => AARCH64_TIED_FEATURES,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue