Skip to content

Commit 8922d30

Browse files
committed
Only allow PassMode::Direct for aggregates on wasm when using the C ABI
For the Rust ABI we don't have any ABI compat reasons to allow PassMode::Direct for aggregates.
1 parent 0e98766 commit 8922d30

File tree

1 file changed

+20
-10
lines changed
  • compiler/rustc_ty_utils/src

1 file changed

+20
-10
lines changed

compiler/rustc_ty_utils/src/abi.rs

+20-10
Original file line numberDiff line numberDiff line change
@@ -473,20 +473,30 @@ fn fn_abi_sanity_check<'tcx>(
473473
// This really shouldn't happen even for sized aggregates, since
474474
// `immediate_llvm_type` will use `layout.fields` to turn this Rust type into an
475475
// LLVM type. This means all sorts of Rust type details leak into the ABI.
476-
// However wasm sadly *does* currently use this mode so we have to allow it --
477-
// but we absolutely shouldn't let any more targets do that.
478-
// (Also see <https://github.com/rust-lang/rust/issues/115666>.)
476+
// However wasm sadly *does* currently use this mode for it's "C" ABI so we
477+
// have to allow it -- but we absolutely shouldn't let any more targets do
478+
// that. (Also see <https://github.com/rust-lang/rust/issues/115666>.)
479479
//
480480
// The unstable abi `PtxKernel` also uses Direct for now.
481481
// It needs to switch to something else before stabilization can happen.
482482
// (See issue: https://github.com/rust-lang/rust/issues/117271)
483-
assert!(
484-
matches!(&*tcx.sess.target.arch, "wasm32" | "wasm64")
485-
|| matches!(spec_abi, ExternAbi::PtxKernel | ExternAbi::Unadjusted),
486-
"`PassMode::Direct` for aggregates only allowed for \"unadjusted\" and \"ptx-kernel\" functions and on wasm\n\
487-
Problematic type: {:#?}",
488-
arg.layout,
489-
);
483+
//
484+
// And finally the unadjusted ABI is ill specified and uses Direct for all
485+
// args, but unfortunately we need it for calling certain LLVM intrinsics.
486+
487+
match spec_abi {
488+
ExternAbi::Unadjusted => {}
489+
ExternAbi::PtxKernel => {}
490+
ExternAbi::C { unwind: _ }
491+
if matches!(&*tcx.sess.target.arch, "wasm32" | "wasm64") => {}
492+
_ => {
493+
panic!(
494+
"`PassMode::Direct` for aggregates only allowed for \"unadjusted\" and \"ptx-kernel\" functions and on wasm\n\
495+
Problematic type: {:#?}",
496+
arg.layout,
497+
);
498+
}
499+
}
490500
}
491501
}
492502
}

0 commit comments

Comments
 (0)