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 , RegKind } ;
3
+ use rustc_abi:: { BackendRepr , ExternAbi , RegKind } ;
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 ;
@@ -153,6 +153,13 @@ fn do_check_wasm_abi<'tcx>(
153
153
/// or return values for which the corresponding target feature is not enabled.
154
154
fn check_instance_abi < ' tcx > ( tcx : TyCtxt < ' tcx > , instance : Instance < ' tcx > ) {
155
155
let typing_env = ty:: TypingEnv :: fully_monomorphized ( ) ;
156
+ let ty = instance. ty ( tcx, typing_env) ;
157
+ if ty. is_fn ( ) {
158
+ if ty. fn_sig ( tcx) . abi ( ) == ExternAbi :: Unadjusted {
159
+ // we disable all checks for the unadjusted abi
160
+ return ;
161
+ }
162
+ }
156
163
let Ok ( abi) = tcx. fn_abi_of_instance ( typing_env. as_query_input ( ( instance, ty:: List :: empty ( ) ) ) )
157
164
else {
158
165
// An error will be reported during codegen if we cannot determine the ABI of this
@@ -178,8 +185,10 @@ fn check_call_site_abi<'tcx>(
178
185
caller : InstanceKind < ' tcx > ,
179
186
loc : impl Fn ( ) -> ( Span , HirId ) + Copy ,
180
187
) {
181
- if callee. fn_sig ( tcx) . abi ( ) . is_rustic_abi ( ) {
188
+ let extern_abi = callee. fn_sig ( tcx) . abi ( ) ;
189
+ if extern_abi. is_rustic_abi ( ) || extern_abi == ExternAbi :: Unadjusted {
182
190
// we directly handle the soundness of Rust ABIs
191
+ // we disable all checks for the unadjusted abi
183
192
return ;
184
193
}
185
194
let typing_env = ty:: TypingEnv :: fully_monomorphized ( ) ;
0 commit comments