Make fn_abi_sanity_check a bit stricter
The Rust ABI must ignore all ZST arguments, all ignored arguments must be either ZST or uninhabited. And finally ScalarPair should never be passed as PassMode::Direct.
This commit is contained in:
parent
fe43131683
commit
c8f0b15a2d
@ -463,21 +463,41 @@ fn fn_arg_sanity_check<'tcx>(
|
|||||||
arg: &ArgAbi<'tcx, Ty<'tcx>>,
|
arg: &ArgAbi<'tcx, Ty<'tcx>>,
|
||||||
) {
|
) {
|
||||||
let tcx = cx.tcx();
|
let tcx = cx.tcx();
|
||||||
|
|
||||||
|
if spec_abi == ExternAbi::Rust
|
||||||
|
|| spec_abi == ExternAbi::RustCall
|
||||||
|
|| spec_abi == ExternAbi::RustCold
|
||||||
|
{
|
||||||
|
if arg.layout.is_zst() {
|
||||||
|
// Casting closures to function pointers depends on ZST closure types being
|
||||||
|
// omitted entirely in the calling convention.
|
||||||
|
assert!(arg.is_ignore());
|
||||||
|
}
|
||||||
|
if let PassMode::Indirect { on_stack, .. } = arg.mode {
|
||||||
|
assert!(!on_stack, "rust abi shouldn't use on_stack");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
match &arg.mode {
|
match &arg.mode {
|
||||||
PassMode::Ignore => {}
|
PassMode::Ignore => {
|
||||||
|
assert!(arg.layout.is_zst() || arg.layout.is_uninhabited());
|
||||||
|
}
|
||||||
PassMode::Direct(_) => {
|
PassMode::Direct(_) => {
|
||||||
// Here the Rust type is used to determine the actual ABI, so we have to be very
|
// Here the Rust type is used to determine the actual ABI, so we have to be very
|
||||||
// careful. Scalar/ScalarPair is fine, since backends will generally use
|
// careful. Scalar/Vector is fine, since backends will generally use
|
||||||
// `layout.abi` and ignore everything else. We should just reject `Aggregate`
|
// `layout.backend_repr` and ignore everything else. We should just reject
|
||||||
// entirely here, but some targets need to be fixed first.
|
//`Aggregate` entirely here, but some targets need to be fixed first.
|
||||||
if matches!(arg.layout.backend_repr, BackendRepr::Memory { .. }) {
|
match arg.layout.backend_repr {
|
||||||
|
BackendRepr::Uninhabited
|
||||||
|
| BackendRepr::Scalar(_)
|
||||||
|
| BackendRepr::Vector { .. } => {}
|
||||||
|
BackendRepr::ScalarPair(..) => {
|
||||||
|
panic!("`PassMode::Direct` used for ScalarPair type {}", arg.layout.ty)
|
||||||
|
}
|
||||||
|
BackendRepr::Memory { sized } => {
|
||||||
// For an unsized type we'd only pass the sized prefix, so there is no universe
|
// For an unsized type we'd only pass the sized prefix, so there is no universe
|
||||||
// in which we ever want to allow this.
|
// in which we ever want to allow this.
|
||||||
assert!(
|
assert!(sized, "`PassMode::Direct` for unsized type in ABI: {:#?}", fn_abi);
|
||||||
arg.layout.is_sized(),
|
|
||||||
"`PassMode::Direct` for unsized type in ABI: {:#?}",
|
|
||||||
fn_abi
|
|
||||||
);
|
|
||||||
// This really shouldn't happen even for sized aggregates, since
|
// This really shouldn't happen even for sized aggregates, since
|
||||||
// `immediate_llvm_type` will use `layout.fields` to turn this Rust type into an
|
// `immediate_llvm_type` will use `layout.fields` to turn this Rust type into an
|
||||||
// LLVM type. This means all sorts of Rust type details leak into the ABI.
|
// LLVM type. This means all sorts of Rust type details leak into the ABI.
|
||||||
@ -497,9 +517,10 @@ fn fn_arg_sanity_check<'tcx>(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
PassMode::Pair(_, _) => {
|
PassMode::Pair(_, _) => {
|
||||||
// Similar to `Direct`, we need to make sure that backends use `layout.abi` and
|
// Similar to `Direct`, we need to make sure that backends use `layout.backend_repr`
|
||||||
// ignore the rest of the layout.
|
// and ignore the rest of the layout.
|
||||||
assert!(
|
assert!(
|
||||||
matches!(arg.layout.backend_repr, BackendRepr::ScalarPair(..)),
|
matches!(arg.layout.backend_repr, BackendRepr::ScalarPair(..)),
|
||||||
"PassMode::Pair for type {}",
|
"PassMode::Pair for type {}",
|
||||||
|
Loading…
Reference in New Issue
Block a user