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 4526613

Browse files
committedOct 26, 2024·
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](#127731 (comment)) for more discussion. Part of #116558
1 parent ae4c6b6 commit 4526613

16 files changed

+448
-53
lines changed
 

‎compiler/rustc_lint_defs/src/builtin.rs

+67
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ declare_lint_pass! {
1616
/// that are used by other parts of the compiler.
1717
HardwiredLints => [
1818
// tidy-alphabetical-start
19+
ABI_UNSUPPORTED_VECTOR_TYPES,
1920
ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
2021
AMBIGUOUS_ASSOCIATED_ITEMS,
2122
AMBIGUOUS_GLOB_IMPORTS,
@@ -5028,3 +5029,69 @@ declare_lint! {
50285029
};
50295030
crate_level_only
50305031
}
5032+
5033+
declare_lint! {
5034+
/// The `abi_unsupported_vector_types` lint detects function definitions and calls
5035+
/// whose ABI depends on enabling certain target features, but those features are not enabled.
5036+
///
5037+
/// ### Example
5038+
///
5039+
/// ```rust,ignore (fails on non-x86_64)
5040+
/// extern "C" fn missing_target_feature(_: std::arch::x86_64::__m256) {
5041+
/// todo!()
5042+
/// }
5043+
///
5044+
/// #[target_feature(enable = "avx")]
5045+
/// unsafe extern "C" fn with_target_feature(_: std::arch::x86_64::__m256) {
5046+
/// todo!()
5047+
/// }
5048+
///
5049+
/// fn main() {
5050+
/// let v = unsafe { std::mem::zeroed() };
5051+
/// unsafe { with_target_feature(v); }
5052+
/// }
5053+
/// ```
5054+
///
5055+
/// ```text
5056+
/// warning: ABI error: this function call uses a avx vector type, which is not enabled in the caller
5057+
/// --> lint_example.rs:18:12
5058+
/// |
5059+
/// | unsafe { with_target_feature(v); }
5060+
/// | ^^^^^^^^^^^^^^^^^^^^^^ function called here
5061+
/// |
5062+
/// = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
5063+
/// = note: for more information, see issue #116558 <https://github.com/rust-lang/rust/issues/116558>
5064+
/// = help: consider enabling it globally (-C target-feature=+avx) or locally (#[target_feature(enable="avx")])
5065+
/// = note: `#[warn(abi_unsupported_vector_types)]` on by default
5066+
///
5067+
///
5068+
/// warning: ABI error: this function definition uses a avx vector type, which is not enabled
5069+
/// --> lint_example.rs:3:1
5070+
/// |
5071+
/// | pub extern "C" fn with_target_feature(_: std::arch::x86_64::__m256) {
5072+
/// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
5073+
/// |
5074+
/// = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
5075+
/// = note: for more information, see issue #116558 <https://github.com/rust-lang/rust/issues/116558>
5076+
/// = help: consider enabling it globally (-C target-feature=+avx) or locally (#[target_feature(enable="avx")])
5077+
/// ```
5078+
///
5079+
///
5080+
///
5081+
/// ### Explanation
5082+
///
5083+
/// The C ABI for `__m256` requires the value to be passed in an AVX register,
5084+
/// which is only possible when the `avx` target feature is enabled.
5085+
/// Therefore, `missing_target_feature` cannot be compiled without that target feature.
5086+
/// A similar (but complementary) message is triggered when `with_target_feature` is called
5087+
/// by a function that does not enable the `avx` target feature.
5088+
///
5089+
/// Note that this lint is very similar to the `-Wpsabi` warning in `gcc`/`clang`.
5090+
pub ABI_UNSUPPORTED_VECTOR_TYPES,
5091+
Warn,
5092+
"this function call or definition uses a vector type which is not enabled",
5093+
@future_incompatible = FutureIncompatibleInfo {
5094+
reason: FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps,
5095+
reference: "issue #116558 <https://github.com/rust-lang/rust/issues/116558>",
5096+
};
5097+
}

‎compiler/rustc_monomorphize/messages.ftl

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
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
3+
.label = function called here
4+
.help = consider enabling it globally (`-C target-feature=+{$required_feature}`) or locally (`#[target_feature(enable="{$required_feature}")]`)
5+
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
7+
.label = function defined here
8+
.help = consider enabling it globally (`-C target-feature=+{$required_feature}`) or locally (`#[target_feature(enable="{$required_feature}")]`)
9+
110
monomorphize_couldnt_dump_mono_stats =
211
unexpected error occurred while dumping monomorphization stats: {$error}
312

‎compiler/rustc_monomorphize/src/collector.rs

+5
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@
205205
//! this is not implemented however: a mono item will be produced
206206
//! regardless of whether it is actually needed or not.
207207
208+
mod abi_check;
208209
mod move_check;
209210

210211
use std::path::PathBuf;
@@ -766,6 +767,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
766767
self.used_mentioned_items.insert(MentionedItem::Fn(callee_ty));
767768
let callee_ty = self.monomorphize(callee_ty);
768769
self.check_fn_args_move_size(callee_ty, args, *fn_span, location);
770+
abi_check::check_call_site_abi(tcx, callee_ty, *fn_span, self.body.source.instance);
769771
visit_fn_use(self.tcx, callee_ty, true, source, &mut self.used_items)
770772
}
771773
mir::TerminatorKind::Drop { ref place, .. } => {
@@ -1207,6 +1209,9 @@ fn collect_items_of_instance<'tcx>(
12071209
mentioned_items: &mut MonoItems<'tcx>,
12081210
mode: CollectionMode,
12091211
) {
1212+
// Check the instance for feature-dependent ABI.
1213+
abi_check::check_instance_abi(tcx, instance);
1214+
12101215
let body = tcx.instance_mir(instance.def);
12111216
// Naively, in "used" collection mode, all functions get added to *both* `used_items` and
12121217
// `mentioned_items`. Mentioned items processing will then notice that they have already been
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
//! This module ensures that if a function's ABI requires a particular target feature,
2+
//! that target feature is enabled both on the callee and all callers.
3+
use rustc_hir::CRATE_HIR_ID;
4+
use rustc_middle::ty::{self, Instance, InstanceKind, ParamEnv, Ty, TyCtxt};
5+
use rustc_session::lint::builtin::ABI_UNSUPPORTED_VECTOR_TYPES;
6+
use rustc_span::def_id::DefId;
7+
use rustc_span::{Span, Symbol};
8+
use rustc_target::abi::call::{FnAbi, PassMode};
9+
use rustc_target::abi::{Abi, RegKind};
10+
11+
use crate::errors::{AbiErrorDisabledVectorTypeCall, AbiErrorDisabledVectorTypeDef};
12+
13+
fn uses_vector_registers(mode: &PassMode, abi: &Abi) -> bool {
14+
match mode {
15+
PassMode::Ignore | PassMode::Indirect { .. } => false,
16+
PassMode::Cast { pad_i32: _, cast } => {
17+
cast.prefix.iter().any(|r| r.is_some_and(|x| x.kind == RegKind::Vector))
18+
|| cast.rest.unit.kind == RegKind::Vector
19+
}
20+
PassMode::Direct(..) | PassMode::Pair(..) => matches!(abi, Abi::Vector { .. }),
21+
}
22+
}
23+
24+
fn do_check_abi<'tcx>(
25+
tcx: TyCtxt<'tcx>,
26+
abi: &FnAbi<'tcx, Ty<'tcx>>,
27+
target_feature_def: DefId,
28+
emit_err: impl Fn(&'static str),
29+
) {
30+
let Some(feature_def) = tcx.sess.target.features_for_correct_vector_abi() else {
31+
return;
32+
};
33+
let codegen_attrs = tcx.codegen_fn_attrs(target_feature_def);
34+
for arg_abi in abi.args.iter().chain(std::iter::once(&abi.ret)) {
35+
let size = arg_abi.layout.size;
36+
if uses_vector_registers(&arg_abi.mode, &arg_abi.layout.abi) {
37+
// Find the first feature that provides at least this vector size.
38+
let feature = match feature_def.iter().find(|(bits, _)| size.bits() <= *bits) {
39+
Some((_, feature)) => feature,
40+
None => {
41+
emit_err("<no available feature for this size>");
42+
continue;
43+
}
44+
};
45+
let feature_sym = Symbol::intern(feature);
46+
if !tcx.sess.unstable_target_features.contains(&feature_sym)
47+
&& !codegen_attrs.target_features.iter().any(|x| x.name == feature_sym)
48+
{
49+
emit_err(feature);
50+
}
51+
}
52+
}
53+
}
54+
55+
/// Checks that the ABI of a given instance of a function does not contain vector-passed arguments
56+
/// or return values for which the corresponding target feature is not enabled.
57+
pub(super) fn check_instance_abi<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) {
58+
let param_env = ParamEnv::reveal_all();
59+
let Ok(abi) = tcx.fn_abi_of_instance(param_env.and((instance, ty::List::empty()))) else {
60+
// An error will be reported during codegen if we cannot determine the ABI of this
61+
// function.
62+
return;
63+
};
64+
do_check_abi(tcx, abi, instance.def_id(), |required_feature| {
65+
let span = tcx.def_span(instance.def_id());
66+
tcx.emit_node_span_lint(
67+
ABI_UNSUPPORTED_VECTOR_TYPES,
68+
CRATE_HIR_ID,
69+
span,
70+
AbiErrorDisabledVectorTypeDef { span, required_feature },
71+
);
72+
})
73+
}
74+
75+
/// Checks that a call expression does not try to pass a vector-passed argument which requires a
76+
/// target feature that the caller does not have, as doing so causes UB because of ABI mismatch.
77+
pub(super) fn check_call_site_abi<'tcx>(
78+
tcx: TyCtxt<'tcx>,
79+
ty: Ty<'tcx>,
80+
span: Span,
81+
caller: InstanceKind<'tcx>,
82+
) {
83+
let param_env = ParamEnv::reveal_all();
84+
let callee_abi = match *ty.kind() {
85+
ty::FnPtr(..) => tcx.fn_abi_of_fn_ptr(param_env.and((ty.fn_sig(tcx), ty::List::empty()))),
86+
ty::FnDef(def_id, args) => {
87+
// Intrinsics are handled separately by the compiler.
88+
if tcx.intrinsic(def_id).is_some() {
89+
return;
90+
}
91+
let instance = ty::Instance::expect_resolve(tcx, param_env, def_id, args, span);
92+
tcx.fn_abi_of_instance(param_env.and((instance, ty::List::empty())))
93+
}
94+
_ => {
95+
panic!("Invalid function call");
96+
}
97+
};
98+
99+
let Ok(callee_abi) = callee_abi else {
100+
// ABI failed to compute; this will not get through codegen.
101+
return;
102+
};
103+
do_check_abi(tcx, callee_abi, caller.def_id(), |required_feature| {
104+
tcx.emit_node_span_lint(
105+
ABI_UNSUPPORTED_VECTOR_TYPES,
106+
CRATE_HIR_ID,
107+
span,
108+
AbiErrorDisabledVectorTypeCall { span, required_feature },
109+
);
110+
})
111+
}

‎compiler/rustc_monomorphize/src/errors.rs

+18
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,21 @@ pub(crate) struct StartNotFound;
9292
pub(crate) struct UnknownCguCollectionMode<'a> {
9393
pub mode: &'a str,
9494
}
95+
96+
#[derive(LintDiagnostic)]
97+
#[diag(monomorphize_abi_error_disabled_vector_type_def)]
98+
#[help]
99+
pub(crate) struct AbiErrorDisabledVectorTypeDef<'a> {
100+
#[label]
101+
pub span: Span,
102+
pub required_feature: &'a str,
103+
}
104+
105+
#[derive(LintDiagnostic)]
106+
#[diag(monomorphize_abi_error_disabled_vector_type_call)]
107+
#[help]
108+
pub(crate) struct AbiErrorDisabledVectorTypeCall<'a> {
109+
#[label]
110+
pub span: Span,
111+
pub required_feature: &'a str,
112+
}

‎compiler/rustc_target/src/target_features.rs

+17
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,13 @@ pub fn all_known_features() -> impl Iterator<Item = (&'static str, Stability)> {
522522
.map(|(f, s, _)| (f, s))
523523
}
524524

525+
// These arrays represent the least-constraining feature that is required for vector types up to a
526+
// certain size to have their "proper" ABI on each architecture.
527+
// Note that they must be kept sorted by vector size.
528+
const X86_FEATURES_FOR_CORRECT_VECTOR_ABI: &'static [(u64, &'static str)] =
529+
&[(128, "sse"), (256, "avx"), (512, "avx512f")];
530+
const AARCH64_FEATURES_FOR_CORRECT_VECTOR_ABI: &'static [(u64, &'static str)] = &[(128, "neon")];
531+
525532
impl super::spec::Target {
526533
pub fn supported_target_features(
527534
&self,
@@ -543,6 +550,16 @@ impl super::spec::Target {
543550
}
544551
}
545552

553+
// Returns None if we do not support ABI checks on the given target yet.
554+
pub fn features_for_correct_vector_abi(&self) -> Option<&'static [(u64, &'static str)]> {
555+
match &*self.arch {
556+
"x86" | "x86_64" => Some(X86_FEATURES_FOR_CORRECT_VECTOR_ABI),
557+
"aarch64" => Some(AARCH64_FEATURES_FOR_CORRECT_VECTOR_ABI),
558+
// FIXME: add support for non-tier1 architectures
559+
_ => None,
560+
}
561+
}
562+
546563
pub fn tied_target_features(&self) -> &'static [&'static [&'static str]] {
547564
match &*self.arch {
548565
"aarch64" | "arm64ec" => AARCH64_TIED_FEATURES,

‎tests/crashes/131342-2.rs

-40
This file was deleted.

‎tests/crashes/131342.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//@ known-bug: #131342
2-
// see also: 131342-2.rs
32

43
fn main() {
54
let mut items = vec![1, 2, 3, 4, 5].into_iter();

‎tests/ui/layout/post-mono-layout-cycle-2.rs

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ where
4545
T: Blah,
4646
{
4747
async fn ice(&mut self) {
48-
//~^ ERROR a cycle occurred during layout computation
4948
let arr: [(); 0] = [];
5049
self.t.iter(arr.into_iter()).await;
5150
}

‎tests/ui/layout/post-mono-layout-cycle-2.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ LL | Blah::iter(self, iterator).await
1212
|
1313
= note: a recursive `async fn` call must introduce indirection such as `Box::pin` to avoid an infinitely sized future
1414

15-
error: a cycle occurred during layout computation
16-
--> $DIR/post-mono-layout-cycle-2.rs:47:5
15+
note: the above error was encountered while instantiating `fn main::{closure#0}`
16+
--> $DIR/post-mono-layout-cycle-2.rs:16:15
1717
|
18-
LL | async fn ice(&mut self) {
19-
| ^^^^^^^^^^^^^^^^^^^^^^^
18+
LL | match fut.as_mut().poll(ctx) {
19+
| ^^^^^^^^^^^^^^^^^^^^^^
2020

21-
error: aborting due to 2 previous errors
21+
error: aborting due to 1 previous error
2222

2323
For more information about this error, try `rustc --explain E0733`.

‎tests/ui/layout/post-mono-layout-cycle.rs

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ struct Wrapper<T: Trait> {
1414
}
1515

1616
fn abi<T: Trait>(_: Option<Wrapper<T>>) {}
17-
//~^ ERROR a cycle occurred during layout computation
1817

1918
fn indirect<T: Trait>() {
2019
abi::<T>(None);

‎tests/ui/layout/post-mono-layout-cycle.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ error[E0391]: cycle detected when computing layout of `Wrapper<()>`
55
= note: cycle used when computing layout of `core::option::Option<Wrapper<()>>`
66
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
77

8-
error: a cycle occurred during layout computation
9-
--> $DIR/post-mono-layout-cycle.rs:16:1
8+
note: the above error was encountered while instantiating `fn indirect::<()>`
9+
--> $DIR/post-mono-layout-cycle.rs:23:5
1010
|
11-
LL | fn abi<T: Trait>(_: Option<Wrapper<T>>) {}
12-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11+
LL | indirect::<()>();
12+
| ^^^^^^^^^^^^^^^^
1313

14-
error: aborting due to 2 previous errors
14+
error: aborting due to 1 previous error
1515

1616
For more information about this error, try `rustc --explain E0391`.

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

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
//@ only-x86_64
2+
//@ build-pass
3+
//@ ignore-pass (test emits codegen-time warnings)
4+
5+
#![feature(avx512_target_feature)]
6+
#![feature(portable_simd)]
7+
#![allow(improper_ctypes_definitions)]
8+
9+
use std::arch::x86_64::*;
10+
11+
#[repr(transparent)]
12+
struct Wrapper(__m256);
13+
14+
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
16+
//~| WARNING this was previously accepted by the compiler
17+
todo!()
18+
}
19+
20+
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
22+
//~| WARNING this was previously accepted by the compiler
23+
todo!()
24+
}
25+
26+
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
28+
//~| WARNING this was previously accepted by the compiler
29+
todo!()
30+
}
31+
32+
#[target_feature(enable = "avx")]
33+
unsafe extern "C" fn favx() -> __m256 {
34+
todo!()
35+
}
36+
37+
// avx2 implies avx, so no error here.
38+
#[target_feature(enable = "avx2")]
39+
unsafe extern "C" fn gavx(_: __m256) {
40+
todo!()
41+
}
42+
43+
// No error because of "Rust" ABI.
44+
fn as_f64x8(d: __m512d) -> std::simd::f64x8 {
45+
unsafe { std::mem::transmute(d) }
46+
}
47+
48+
unsafe fn test() {
49+
let arg = std::mem::transmute([0.0f64; 8]);
50+
as_f64x8(arg);
51+
}
52+
53+
fn main() {
54+
unsafe {
55+
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
58+
//~| WARNING this was previously accepted by the compiler
59+
//~| WARNING this was previously accepted by the compiler
60+
}
61+
62+
unsafe {
63+
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
66+
//~| WARNING this was previously accepted by the compiler
67+
//~| WARNING this was previously accepted by the compiler
68+
}
69+
70+
unsafe {
71+
test();
72+
}
73+
74+
unsafe {
75+
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
78+
//~| WARNING this was previously accepted by the compiler
79+
//~| WARNING this was previously accepted by the compiler
80+
}
81+
}

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

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
warning: ABI error: this function call uses a vector type that requires the `avx` target feature, which is not enabled in the caller
2+
--> $DIR/simd-abi-checks.rs:55:11
3+
|
4+
LL | f(g());
5+
| ^^^ function called 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=+avx`) or locally (`#[target_feature(enable="avx")]`)
10+
= note: `#[warn(abi_unsupported_vector_types)]` on by default
11+
12+
warning: ABI error: this function call uses a vector type that requires the `avx` target feature, which is not enabled in the caller
13+
--> $DIR/simd-abi-checks.rs:55:9
14+
|
15+
LL | f(g());
16+
| ^^^^^^ function called here
17+
|
18+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
19+
= note: for more information, see issue #116558 <https://github.com/rust-lang/rust/issues/116558>
20+
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)
21+
22+
warning: ABI error: this function call uses a vector type that requires the `avx` target feature, which is not enabled in the caller
23+
--> $DIR/simd-abi-checks.rs:63:14
24+
|
25+
LL | gavx(favx());
26+
| ^^^^^^ function called here
27+
|
28+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
29+
= note: for more information, see issue #116558 <https://github.com/rust-lang/rust/issues/116558>
30+
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)
31+
32+
warning: ABI error: this function call uses a vector type that requires the `avx` target feature, which is not enabled in the caller
33+
--> $DIR/simd-abi-checks.rs:63:9
34+
|
35+
LL | gavx(favx());
36+
| ^^^^^^^^^^^^ function called here
37+
|
38+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
39+
= note: for more information, see issue #116558 <https://github.com/rust-lang/rust/issues/116558>
40+
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)
41+
42+
warning: ABI error: this function call uses a vector type that requires the `avx` target feature, which is not enabled in the caller
43+
--> $DIR/simd-abi-checks.rs:75:19
44+
|
45+
LL | w(Wrapper(g()));
46+
| ^^^ function called here
47+
|
48+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
49+
= note: for more information, see issue #116558 <https://github.com/rust-lang/rust/issues/116558>
50+
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)
51+
52+
warning: ABI error: this function call uses a vector type that requires the `avx` target feature, which is not enabled in the caller
53+
--> $DIR/simd-abi-checks.rs:75:9
54+
|
55+
LL | w(Wrapper(g()));
56+
| ^^^^^^^^^^^^^^^ function called here
57+
|
58+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
59+
= note: for more information, see issue #116558 <https://github.com/rust-lang/rust/issues/116558>
60+
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)
61+
62+
warning: ABI error: this function definition uses a vector type that requires the `avx` target feature, which is not enabled
63+
--> $DIR/simd-abi-checks.rs:26:1
64+
|
65+
LL | unsafe extern "C" fn g() -> __m256 {
66+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
67+
|
68+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
69+
= note: for more information, see issue #116558 <https://github.com/rust-lang/rust/issues/116558>
70+
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)
71+
72+
warning: ABI error: this function definition uses a vector type that requires the `avx` target feature, which is not enabled
73+
--> $DIR/simd-abi-checks.rs:20:1
74+
|
75+
LL | unsafe extern "C" fn f(_: __m256) {
76+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
77+
|
78+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
79+
= note: for more information, see issue #116558 <https://github.com/rust-lang/rust/issues/116558>
80+
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)
81+
82+
warning: ABI error: this function definition uses a vector type that requires the `avx` target feature, which is not enabled
83+
--> $DIR/simd-abi-checks.rs:14:1
84+
|
85+
LL | unsafe extern "C" fn w(_: Wrapper) {
86+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
87+
|
88+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
89+
= note: for more information, see issue #116558 <https://github.com/rust-lang/rust/issues/116558>
90+
= help: consider enabling it globally (`-C target-feature=+avx`) or locally (`#[target_feature(enable="avx")]`)
91+
92+
warning: 9 warnings emitted
93+

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

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//! Ensure we trigger abi_unsupported_vector_types for target features that are usually enabled
2+
//! on a target, but disabled in this file via a `-C` flag.
3+
//@ compile-flags: --crate-type=rlib --target=i686-unknown-linux-gnu -C target-feature=-sse,-sse2
4+
//@ build-pass
5+
//@ ignore-pass (test emits codegen-time warnings)
6+
//@ needs-llvm-components: x86
7+
#![feature(no_core, lang_items, repr_simd)]
8+
#![no_core]
9+
#![allow(improper_ctypes_definitions)]
10+
11+
#[lang = "sized"]
12+
trait Sized {}
13+
14+
#[lang = "copy"]
15+
trait Copy {}
16+
17+
#[repr(simd)]
18+
pub struct SseVector([i64; 2]);
19+
20+
#[no_mangle]
21+
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
23+
//~| WARNING this was previously accepted by the compiler
24+
}

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

+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 `sse` target feature, which is not enabled
2+
--> $DIR/sse-abi-checks.rs:21:1
3+
|
4+
LL | pub unsafe extern "C" fn f(_: SseVector) {
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=+sse`) or locally (`#[target_feature(enable="sse")]`)
10+
= note: `#[warn(abi_unsupported_vector_types)]` on by default
11+
12+
warning: 1 warning emitted
13+

0 commit comments

Comments
 (0)
Please sign in to comment.