1
Fork 0

mono-time abi_check: unify error paths for call and definition sites

also move the existing tests to a more sensible location
This commit is contained in:
Ralf Jung 2025-02-18 16:51:47 +01:00
parent eeb9035117
commit 79b2360d98
14 changed files with 122 additions and 86 deletions

View file

@ -1,18 +1,26 @@
monomorphize_abi_error_disabled_vector_type_call = monomorphize_abi_error_disabled_vector_type =
this function call uses SIMD vector type `{$ty}` which (with the chosen ABI) requires the `{$required_feature}` target feature, which is not enabled in the caller this function {$is_call ->
.label = function called here [true] call
.help = consider enabling it globally (`-C target-feature=+{$required_feature}`) or locally (`#[target_feature(enable="{$required_feature}")]`) *[false] definition
monomorphize_abi_error_disabled_vector_type_def = } uses SIMD vector type `{$ty}` which (with the chosen ABI) requires the `{$required_feature}` target feature, which is not enabled{$is_call ->
this function definition uses SIMD vector type `{$ty}` which (with the chosen ABI) requires the `{$required_feature}` target feature, which is not enabled [true] {" "}in the caller
.label = function defined here *[false] {""}
}
.label = function {$is_call ->
[true] called
*[false] defined
} here
.help = consider enabling it globally (`-C target-feature=+{$required_feature}`) or locally (`#[target_feature(enable="{$required_feature}")]`) .help = consider enabling it globally (`-C target-feature=+{$required_feature}`) or locally (`#[target_feature(enable="{$required_feature}")]`)
monomorphize_abi_error_unsupported_vector_type_call = monomorphize_abi_error_unsupported_vector_type =
this function call uses SIMD vector type `{$ty}` which is not currently supported with the chosen ABI this function {$is_call ->
.label = function called here [true] call
monomorphize_abi_error_unsupported_vector_type_def = *[false] definition
this function definition uses SIMD vector type `{$ty}` which is not currently supported with the chosen ABI } uses SIMD vector type `{$ty}` which is not currently supported with the chosen ABI
.label = function defined here .label = function {$is_call ->
[true] called
*[false] defined
} here
monomorphize_couldnt_dump_mono_stats = monomorphize_couldnt_dump_mono_stats =
unexpected error occurred while dumping monomorphization stats: {$error} unexpected error occurred while dumping monomorphization stats: {$error}

View file

@ -70,37 +70,23 @@ pub(crate) struct UnknownCguCollectionMode<'a> {
} }
#[derive(LintDiagnostic)] #[derive(LintDiagnostic)]
#[diag(monomorphize_abi_error_disabled_vector_type_def)] #[diag(monomorphize_abi_error_disabled_vector_type)]
#[help] #[help]
pub(crate) struct AbiErrorDisabledVectorTypeDef<'a> { pub(crate) struct AbiErrorDisabledVectorType<'a> {
#[label] #[label]
pub span: Span, pub span: Span,
pub required_feature: &'a str, pub required_feature: &'a str,
pub ty: Ty<'a>, pub ty: Ty<'a>,
/// Whether this is a problem at a call site or at a declaration.
pub is_call: bool,
} }
#[derive(LintDiagnostic)] #[derive(LintDiagnostic)]
#[diag(monomorphize_abi_error_disabled_vector_type_call)] #[diag(monomorphize_abi_error_unsupported_vector_type)]
#[help] pub(crate) struct AbiErrorUnsupportedVectorType<'a> {
pub(crate) struct AbiErrorDisabledVectorTypeCall<'a> {
#[label]
pub span: Span,
pub required_feature: &'a str,
pub ty: Ty<'a>,
}
#[derive(LintDiagnostic)]
#[diag(monomorphize_abi_error_unsupported_vector_type_def)]
pub(crate) struct AbiErrorUnsupportedVectorTypeDef<'a> {
#[label]
pub span: Span,
pub ty: Ty<'a>,
}
#[derive(LintDiagnostic)]
#[diag(monomorphize_abi_error_unsupported_vector_type_call)]
pub(crate) struct AbiErrorUnsupportedVectorTypeCall<'a> {
#[label] #[label]
pub span: Span, pub span: Span,
pub ty: Ty<'a>, pub ty: Ty<'a>,
/// Whether this is a problem at a call site or at a declaration.
pub is_call: bool,
} }

View file

@ -6,13 +6,10 @@ use rustc_middle::mir::{self, traversal};
use rustc_middle::ty::{self, Instance, InstanceKind, Ty, TyCtxt}; use rustc_middle::ty::{self, Instance, InstanceKind, Ty, TyCtxt};
use rustc_session::lint::builtin::ABI_UNSUPPORTED_VECTOR_TYPES; use rustc_session::lint::builtin::ABI_UNSUPPORTED_VECTOR_TYPES;
use rustc_span::def_id::DefId; use rustc_span::def_id::DefId;
use rustc_span::{DUMMY_SP, Span, Symbol}; use rustc_span::{DUMMY_SP, Span, Symbol, sym};
use rustc_target::callconv::{FnAbi, PassMode}; use rustc_target::callconv::{Conv, FnAbi, PassMode};
use crate::errors::{ use crate::errors;
AbiErrorDisabledVectorTypeCall, AbiErrorDisabledVectorTypeDef,
AbiErrorUnsupportedVectorTypeCall, AbiErrorUnsupportedVectorTypeDef,
};
fn uses_vector_registers(mode: &PassMode, repr: &BackendRepr) -> bool { fn uses_vector_registers(mode: &PassMode, repr: &BackendRepr) -> bool {
match mode { match mode {
@ -27,16 +24,21 @@ fn uses_vector_registers(mode: &PassMode, repr: &BackendRepr) -> bool {
/// Checks whether a certain function ABI is compatible with the target features currently enabled /// Checks whether a certain function ABI is compatible with the target features currently enabled
/// for a certain function. /// for a certain function.
/// If not, `emit_err` is called, with `Some(feature)` if a certain feature should be enabled and /// `is_call` indicates whether this is a call-site check or a definition-site check;
/// with `None` if no feature is known that would make the ABI compatible. /// this is only relevant for the wording in the emitted error.
fn do_check_abi<'tcx>( fn do_check_abi<'tcx>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
abi: &FnAbi<'tcx, Ty<'tcx>>, abi: &FnAbi<'tcx, Ty<'tcx>>,
target_feature_def: DefId, target_feature_def: DefId,
mut emit_err: impl FnMut(Ty<'tcx>, Option<&'static str>), is_call: bool,
span: impl Fn() -> Span,
) { ) {
let feature_def = tcx.sess.target.features_for_correct_vector_abi(); let feature_def = tcx.sess.target.features_for_correct_vector_abi();
let codegen_attrs = tcx.codegen_fn_attrs(target_feature_def); let codegen_attrs = tcx.codegen_fn_attrs(target_feature_def);
let have_feature = |feat: Symbol| {
tcx.sess.unstable_target_features.contains(&feat)
|| codegen_attrs.target_features.iter().any(|x| x.name == feat)
};
for arg_abi in abi.args.iter().chain(std::iter::once(&abi.ret)) { for arg_abi in abi.args.iter().chain(std::iter::once(&abi.ret)) {
let size = arg_abi.layout.size; let size = arg_abi.layout.size;
if uses_vector_registers(&arg_abi.mode, &arg_abi.layout.backend_repr) { if uses_vector_registers(&arg_abi.mode, &arg_abi.layout.backend_repr) {
@ -44,15 +46,34 @@ fn do_check_abi<'tcx>(
let feature = match feature_def.iter().find(|(bits, _)| size.bits() <= *bits) { let feature = match feature_def.iter().find(|(bits, _)| size.bits() <= *bits) {
Some((_, feature)) => feature, Some((_, feature)) => feature,
None => { None => {
emit_err(arg_abi.layout.ty, None); let span = span();
tcx.emit_node_span_lint(
ABI_UNSUPPORTED_VECTOR_TYPES,
CRATE_HIR_ID,
span,
errors::AbiErrorUnsupportedVectorType {
span,
ty: arg_abi.layout.ty,
is_call,
},
);
continue; continue;
} }
}; };
let feature_sym = Symbol::intern(feature); if !have_feature(Symbol::intern(feature)) {
if !tcx.sess.unstable_target_features.contains(&feature_sym) // Emit error.
&& !codegen_attrs.target_features.iter().any(|x| x.name == feature_sym) let span = span();
{ tcx.emit_node_span_lint(
emit_err(arg_abi.layout.ty, Some(&feature)); ABI_UNSUPPORTED_VECTOR_TYPES,
CRATE_HIR_ID,
span,
errors::AbiErrorDisabledVectorType {
span,
required_feature: feature,
ty: arg_abi.layout.ty,
is_call,
},
);
} }
} }
} }
@ -68,24 +89,13 @@ fn check_instance_abi<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) {
// function. // function.
return; return;
}; };
do_check_abi(tcx, abi, instance.def_id(), |ty, required_feature| { do_check_abi(
let span = tcx.def_span(instance.def_id()); tcx,
if let Some(required_feature) = required_feature { abi,
tcx.emit_node_span_lint( instance.def_id(),
ABI_UNSUPPORTED_VECTOR_TYPES, /*is_call*/ false,
CRATE_HIR_ID, || tcx.def_span(instance.def_id()),
span, )
AbiErrorDisabledVectorTypeDef { span, required_feature, ty },
);
} else {
tcx.emit_node_span_lint(
ABI_UNSUPPORTED_VECTOR_TYPES,
CRATE_HIR_ID,
span,
AbiErrorUnsupportedVectorTypeDef { span, ty },
);
}
})
} }
/// Checks that a call expression does not try to pass a vector-passed argument which requires a /// Checks that a call expression does not try to pass a vector-passed argument which requires a
@ -122,23 +132,7 @@ fn check_call_site_abi<'tcx>(
// ABI failed to compute; this will not get through codegen. // ABI failed to compute; this will not get through codegen.
return; return;
}; };
do_check_abi(tcx, callee_abi, caller.def_id(), |ty, required_feature| { do_check_abi(tcx, callee_abi, caller.def_id(), /*is_call*/ true, || span);
if let Some(required_feature) = required_feature {
tcx.emit_node_span_lint(
ABI_UNSUPPORTED_VECTOR_TYPES,
CRATE_HIR_ID,
span,
AbiErrorDisabledVectorTypeCall { span, required_feature, ty },
);
} else {
tcx.emit_node_span_lint(
ABI_UNSUPPORTED_VECTOR_TYPES,
CRATE_HIR_ID,
span,
AbiErrorUnsupportedVectorTypeCall { span, ty },
);
}
});
} }
fn check_callees_abi<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>, body: &mir::Body<'tcx>) { fn check_callees_abi<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>, body: &mir::Body<'tcx>) {

View file

@ -0,0 +1,23 @@
//! Ensure we trigger abi_unsupported_vector_types for target features that are usually enabled
//! on a target via the base CPU, but disabled in this file via a `-C` flag.
//@ compile-flags: --crate-type=rlib --target=i586-unknown-linux-gnu
//@ compile-flags: -Ctarget-cpu=pentium4 -C target-feature=-sse,-sse2
//@ add-core-stubs
//@ build-pass
//@ ignore-pass (test emits codegen-time warnings)
//@ needs-llvm-components: x86
#![feature(no_core, repr_simd)]
#![no_core]
#![allow(improper_ctypes_definitions)]
extern crate minicore;
use minicore::*;
#[repr(simd)]
pub struct SseVector([i64; 2]);
#[no_mangle]
pub unsafe extern "C" fn f(_: SseVector) {
//~^ this function definition uses SIMD vector type `SseVector` which (with the chosen ABI) requires the `sse` target feature, which is not enabled
//~| WARNING this was previously accepted by the compiler
}

View file

@ -0,0 +1,25 @@
warning: this function definition uses SIMD vector type `SseVector` which (with the chosen ABI) requires the `sse` target feature, which is not enabled
--> $DIR/sse-simd-abi-checks.rs:20:1
|
LL | pub unsafe extern "C" fn f(_: SseVector) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #116558 <https://github.com/rust-lang/rust/issues/116558>
= help: consider enabling it globally (`-C target-feature=+sse`) or locally (`#[target_feature(enable="sse")]`)
= note: `#[warn(abi_unsupported_vector_types)]` on by default
warning: 1 warning emitted
Future incompatibility report: Future breakage diagnostic:
warning: this function definition uses SIMD vector type `SseVector` which (with the chosen ABI) requires the `sse` target feature, which is not enabled
--> $DIR/sse-simd-abi-checks.rs:20:1
|
LL | pub unsafe extern "C" fn f(_: SseVector) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function defined here
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #116558 <https://github.com/rust-lang/rust/issues/116558>
= help: consider enabling it globally (`-C target-feature=+sse`) or locally (`#[target_feature(enable="sse")]`)
= note: `#[warn(abi_unsupported_vector_types)]` on by default

View file

@ -6,7 +6,7 @@
//@ build-pass //@ build-pass
//@ ignore-pass (test emits codegen-time warnings) //@ ignore-pass (test emits codegen-time warnings)
//@ needs-llvm-components: x86 //@ needs-llvm-components: x86
#![feature(no_core, lang_items, repr_simd)] #![feature(no_core, repr_simd)]
#![no_core] #![no_core]
#![allow(improper_ctypes_definitions)] #![allow(improper_ctypes_definitions)]