|
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::layout::LayoutCx;
|
@@ -152,6 +152,12 @@ fn do_check_wasm_abi<'tcx>(
|
152 | 152 | /// or return values for which the corresponding target feature is not enabled.
|
153 | 153 | fn check_instance_abi<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) {
|
154 | 154 | 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 | + } |
155 | 161 | let Ok(abi) = tcx.fn_abi_of_instance(typing_env.as_query_input((instance, ty::List::empty())))
|
156 | 162 | else {
|
157 | 163 | // 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>(
|
184 | 190 | caller: InstanceKind<'tcx>,
|
185 | 191 | loc: impl Fn() -> (Span, HirId) + Copy,
|
186 | 192 | ) {
|
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 { |
188 | 195 | // We directly handle the soundness of Rust ABIs -- so let's skip the majority of
|
189 | 196 | // call sites to avoid a perf regression.
|
| 197 | + // We disable all checks for the unadjusted abi to allow linking to arbitrary LLVM |
| 198 | + // intrinsics |
190 | 199 | return;
|
191 | 200 | }
|
192 | 201 | let typing_env = ty::TypingEnv::fully_monomorphized();
|
|
0 commit comments