@@ -3,7 +3,10 @@ use std::convert::TryFrom;
3
3
4
4
use rustc_middle:: ty:: layout:: TyAndLayout ;
5
5
use rustc_middle:: ty:: Instance ;
6
- use rustc_middle:: { mir, ty} ;
6
+ use rustc_middle:: {
7
+ mir,
8
+ ty:: { self , Ty } ,
9
+ } ;
7
10
use rustc_target:: abi:: { self , LayoutOf as _} ;
8
11
use rustc_target:: spec:: abi:: Abi ;
9
12
@@ -228,15 +231,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
228
231
} ;
229
232
230
233
// 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) ,
240
240
} ;
241
241
let normalize_abi = |abi| match abi {
242
242
Abi :: Rust | Abi :: RustCall | Abi :: RustIntrinsic | Abi :: PlatformIntrinsic =>
@@ -253,10 +253,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
253
253
caller_abi. name( )
254
254
)
255
255
}
256
- }
256
+ Ok ( ( ) )
257
+ } ;
257
258
258
259
match instance. def {
259
260
ty:: InstanceDef :: Intrinsic ( ..) => {
261
+ check_abi ( self , instance. ty ( * self . tcx , self . param_env ) ) ?;
260
262
assert ! ( caller_abi == Abi :: RustIntrinsic || caller_abi == Abi :: PlatformIntrinsic ) ;
261
263
M :: call_intrinsic ( self , instance, args, ret, unwind)
262
264
}
@@ -274,6 +276,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
274
276
None => return Ok ( ( ) ) ,
275
277
} ;
276
278
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
+
277
284
self . push_stack_frame (
278
285
instance,
279
286
body,
0 commit comments