@@ -274,9 +274,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
274274
275275 /// Call this function -- pushing the stack frame and initializing the arguments.
276276 ///
277- /// For now, we require *both* the `Abi` and `FnAbi` of the caller. In principle, however,
278- /// `FnAbi` should be enough -- if they are sufficiently compatible, it's probably okay for
279- /// `Abi` to differ.
277+ /// `caller_fn_abi` is used to determine if all the arguments are passed the proper way.
278+ /// However, we also need `caller_abi` to determine if we need to do untupling of arguments.
280279 ///
281280 /// `with_caller_location` indicates whether the caller passed a caller location. Miri
282281 /// implements caller locations without argument passing, but to match `FnAbi` we need to know
@@ -299,40 +298,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
299298 }
300299 } ;
301300
302- let get_abi = |this : & Self , instance_ty : Ty < ' tcx > | match instance_ty. kind ( ) {
303- ty:: FnDef ( ..) => instance_ty. fn_sig ( * this. tcx ) . abi ( ) ,
304- // Even after lowering closures and generators away, the *callee* can still have this
305- // kind of type.
306- ty:: Closure ( ..) => Abi :: RustCall ,
307- ty:: Generator ( ..) => Abi :: Rust ,
308- _ => span_bug ! ( this. cur_span( ) , "unexpected callee ty: {:?}" , instance_ty) ,
309- } ;
310-
311- // ABI check
312- let check_abi = |callee_abi : Abi | -> InterpResult < ' tcx > {
313- let normalize_abi = |abi| match abi {
314- Abi :: Rust | Abi :: RustCall | Abi :: RustIntrinsic | Abi :: PlatformIntrinsic =>
315- // These are all the same ABI, really.
316- {
317- Abi :: Rust
318- }
319- abi => abi,
320- } ;
321- if normalize_abi ( caller_abi) != normalize_abi ( callee_abi) {
322- throw_ub_format ! (
323- "calling a function with ABI {} using caller ABI {}" ,
324- callee_abi. name( ) ,
325- caller_abi. name( )
326- )
327- }
328- Ok ( ( ) )
329- } ;
330-
331301 match instance. def {
332302 ty:: InstanceDef :: Intrinsic ( ..) => {
333- if M :: enforce_abi ( self ) {
334- check_abi ( get_abi ( self , instance. ty ( * self . tcx , self . param_env ) ) ) ?;
335- }
336303 assert ! ( caller_abi == Abi :: RustIntrinsic || caller_abi == Abi :: PlatformIntrinsic ) ;
337304 // caller_fn_abi is not relevant here, we interpret the arguments directly for each intrinsic.
338305 M :: call_intrinsic ( self , instance, args, ret, unwind)
@@ -353,14 +320,19 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
353320
354321 // Compute callee information using the `instance` returned by
355322 // `find_mir_or_eval_fn`.
356- let callee_abi = get_abi ( self , instance. ty ( * self . tcx , self . param_env ) ) ;
357323 // FIXME: for variadic support, do we have to somehow determine calle's extra_args?
358324 let callee_fn_abi = self . fn_abi_of_instance ( instance, ty:: List :: empty ( ) ) ?;
359325 assert ! ( !callee_fn_abi. c_variadic) ;
360326 assert ! ( !caller_fn_abi. c_variadic) ;
361327
362328 if M :: enforce_abi ( self ) {
363- check_abi ( callee_abi) ?;
329+ if caller_fn_abi. conv != callee_fn_abi. conv {
330+ throw_ub_format ! (
331+ "calling a function with calling convention {:?} using calling convention {:?}" ,
332+ callee_fn_abi. conv,
333+ caller_fn_abi. conv
334+ )
335+ }
364336 }
365337
366338 if !matches ! ( unwind, StackPopUnwind :: NotAllowed ) && !callee_fn_abi. can_unwind {
0 commit comments