@@ -3,7 +3,10 @@ use std::convert::TryFrom;
33
44use rustc_middle:: ty:: layout:: TyAndLayout ;
55use rustc_middle:: ty:: Instance ;
6- use rustc_middle:: { mir, ty} ;
6+ use rustc_middle:: {
7+ mir,
8+ ty:: { self , Ty } ,
9+ } ;
710use rustc_target:: abi:: { self , LayoutOf as _} ;
811use rustc_target:: spec:: abi:: Abi ;
912
@@ -228,15 +231,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
228231 } ;
229232
230233 // ABI check
231- {
232- let callee_abi = {
233- let instance_ty = instance. ty ( * self . tcx , self . param_env ) ;
234- match instance_ty. kind ( ) {
235- ty:: FnDef ( ..) => instance_ty. fn_sig ( * self . tcx ) . abi ( ) ,
236- ty:: Closure ( ..) => Abi :: RustCall ,
237- ty:: Generator ( ..) => Abi :: Rust ,
238- _ => span_bug ! ( self . cur_span( ) , "unexpected callee ty: {:?}" , instance_ty) ,
239- }
234+ let check_abi = |this : & Self , instance_ty : Ty < ' tcx > | -> InterpResult < ' tcx > {
235+ let callee_abi = match instance_ty. kind ( ) {
236+ ty:: FnDef ( ..) => instance_ty. fn_sig ( * this. tcx ) . abi ( ) ,
237+ ty:: Closure ( ..) => Abi :: RustCall ,
238+ ty:: Generator ( ..) => Abi :: Rust ,
239+ _ => span_bug ! ( this. cur_span( ) , "unexpected callee ty: {:?}" , instance_ty) ,
240240 } ;
241241 let normalize_abi = |abi| match abi {
242242 Abi :: Rust | Abi :: RustCall | Abi :: RustIntrinsic | Abi :: PlatformIntrinsic =>
@@ -253,10 +253,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
253253 caller_abi. name( )
254254 )
255255 }
256- }
256+ Ok ( ( ) )
257+ } ;
257258
258259 match instance. def {
259260 ty:: InstanceDef :: Intrinsic ( ..) => {
261+ check_abi ( self , instance. ty ( * self . tcx , self . param_env ) ) ?;
260262 assert ! ( caller_abi == Abi :: RustIntrinsic || caller_abi == Abi :: PlatformIntrinsic ) ;
261263 M :: call_intrinsic ( self , instance, args, ret, unwind)
262264 }
@@ -274,6 +276,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
274276 None => return Ok ( ( ) ) ,
275277 } ;
276278
279+ // Check against the ABI of the MIR body we are calling (not the ABI of `instance`;
280+ // these can differ when `find_mir_or_eval_fn` does something clever like resolve
281+ // exported symbol names).
282+ check_abi ( self , self . tcx . type_of ( body. source . def_id ( ) ) ) ?;
283+
277284 self . push_stack_frame (
278285 instance,
279286 body,
0 commit comments