Skip to content

Commit 925028f

Browse files
committed
Disable ABI checks for the unadjusted ABI
1 parent 07bd4e1 commit 925028f

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

compiler/rustc_monomorphize/src/mono_checks/abi_check.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! This module ensures that if a function's ABI requires a particular target feature,
22
//! that target feature is enabled both on the callee and all callers.
3-
use rustc_abi::{BackendRepr, CanonAbi, RegKind, X86Call};
3+
use rustc_abi::{BackendRepr, CanonAbi, ExternAbi, RegKind, X86Call};
44
use rustc_hir::{CRATE_HIR_ID, HirId};
55
use rustc_middle::mir::{self, Location, traversal};
66
use rustc_middle::ty::layout::LayoutCx;
@@ -152,6 +152,12 @@ fn do_check_wasm_abi<'tcx>(
152152
/// or return values for which the corresponding target feature is not enabled.
153153
fn check_instance_abi<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) {
154154
let typing_env = ty::TypingEnv::fully_monomorphized();
155+
let ty = instance.ty(tcx, typing_env);
156+
if ty.is_fn() && ty.fn_sig(tcx).abi() == ExternAbi::Unadjusted {
157+
// We disable all checks for the unadjusted abi to allow linking to arbitrary LLVM
158+
// intrinsics
159+
return;
160+
}
155161
let Ok(abi) = tcx.fn_abi_of_instance(typing_env.as_query_input((instance, ty::List::empty())))
156162
else {
157163
// An error will be reported during codegen if we cannot determine the ABI of this
@@ -184,9 +190,12 @@ fn check_call_site_abi<'tcx>(
184190
caller: InstanceKind<'tcx>,
185191
loc: impl Fn() -> (Span, HirId) + Copy,
186192
) {
187-
if callee.fn_sig(tcx).abi().is_rustic_abi() {
193+
let extern_abi = callee.fn_sig(tcx).abi();
194+
if extern_abi.is_rustic_abi() || extern_abi == ExternAbi::Unadjusted {
188195
// We directly handle the soundness of Rust ABIs -- so let's skip the majority of
189196
// call sites to avoid a perf regression.
197+
// We disable all checks for the unadjusted abi to allow linking to arbitrary LLVM
198+
// intrinsics
190199
return;
191200
}
192201
let typing_env = ty::TypingEnv::fully_monomorphized();

0 commit comments

Comments
 (0)