|
1 | 1 | //! This module ensures that if a function's ABI requires a particular target feature,
|
2 | 2 | //! 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}; |
4 | 4 | use rustc_hir::{CRATE_HIR_ID, HirId};
|
5 | 5 | use rustc_middle::mir::{self, Location, traversal};
|
6 | 6 | use rustc_middle::ty::{self, Instance, InstanceKind, Ty, TyCtxt};
|
@@ -82,6 +82,12 @@ fn do_check_simd_vector_abi<'tcx>(
|
82 | 82 | /// or return values for which the corresponding target feature is not enabled.
|
83 | 83 | fn check_instance_abi<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) {
|
84 | 84 | let typing_env = ty::TypingEnv::fully_monomorphized();
|
| 85 | + let ty = instance.ty(tcx, typing_env); |
| 86 | + if ty.is_fn() && ty.fn_sig(tcx).abi() == ExternAbi::Unadjusted { |
| 87 | + // We disable all checks for the unadjusted abi to allow linking to arbitrary LLVM |
| 88 | + // intrinsics |
| 89 | + return; |
| 90 | + } |
85 | 91 | let Ok(abi) = tcx.fn_abi_of_instance(typing_env.as_query_input((instance, ty::List::empty())))
|
86 | 92 | else {
|
87 | 93 | // An error will be reported during codegen if we cannot determine the ABI of this
|
@@ -113,9 +119,12 @@ fn check_call_site_abi<'tcx>(
|
113 | 119 | caller: InstanceKind<'tcx>,
|
114 | 120 | loc: impl Fn() -> (Span, HirId) + Copy,
|
115 | 121 | ) {
|
116 |
| - if callee.fn_sig(tcx).abi().is_rustic_abi() { |
| 122 | + let extern_abi = callee.fn_sig(tcx).abi(); |
| 123 | + if extern_abi.is_rustic_abi() || extern_abi == ExternAbi::Unadjusted { |
117 | 124 | // We directly handle the soundness of Rust ABIs -- so let's skip the majority of
|
118 | 125 | // call sites to avoid a perf regression.
|
| 126 | + // We disable all checks for the unadjusted abi to allow linking to arbitrary LLVM |
| 127 | + // intrinsics |
119 | 128 | return;
|
120 | 129 | }
|
121 | 130 | let typing_env = ty::TypingEnv::fully_monomorphized();
|
|
0 commit comments