@@ -19,6 +19,10 @@ use rustc_middle::ty::layout::{FnAbiOf, LayoutOf, MaybeResult, TyAndLayout};
1919use rustc_middle:: ty:: { self , FloatTy , IntTy , Ty , TyCtxt , UintTy } ;
2020use rustc_session:: config:: CrateType ;
2121use rustc_span:: { Span , Symbol } ;
22+ use rustc_target:: callconv:: FnAbi ;
23+ use rustc_target:: callconv:: Conv ;
24+
25+
2226
2327use crate :: * ;
2428
@@ -916,13 +920,27 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
916920 }
917921
918922 /// Check that the ABI is what we expect.
919- fn check_abi < ' a > ( & self , abi : ExternAbi , exp_abi : ExternAbi ) -> InterpResult < ' a , ( ) > {
920- if abi != exp_abi {
921- throw_ub_format ! (
922- "calling a function with ABI {} using caller ABI {}" ,
923- exp_abi. name( ) ,
924- abi. name( )
925- )
923+ fn check_abi < ' a > ( & self , fn_abi : & FnAbi < ' tcx , Ty < ' tcx > > , exp_abi : ExternAbi ) -> InterpResult < ' a , ( ) > {
924+ let call_conv;
925+ match fn_abi. conv {
926+ Conv :: C => {
927+ // TODO: unwind what?
928+ call_conv = ExternAbi :: C { unwind : false } ;
929+ } ,
930+ Conv :: Rust => {
931+ call_conv = ExternAbi :: Rust ;
932+ } ,
933+ _=> {
934+ // TODO: What is a better way of doing this?
935+ panic ! ( "Unsupported calling convention" ) ;
936+ }
937+ } ;
938+ if call_conv != exp_abi {
939+ throw_ub_format ! (
940+ "calling a function with ABI {} using caller ABI {}" ,
941+ exp_abi. name( ) ,
942+ call_conv. name( )
943+ )
926944 }
927945 interp_ok ( ( ) )
928946 }
@@ -952,11 +970,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
952970
953971 fn check_abi_and_shim_symbol_clash (
954972 & mut self ,
955- abi : ExternAbi ,
973+ fnabi : & FnAbi < ' tcx , Ty < ' tcx > > ,
956974 exp_abi : ExternAbi ,
957975 link_name : Symbol ,
958976 ) -> InterpResult < ' tcx , ( ) > {
959- self . check_abi ( abi , exp_abi) ?;
977+ self . check_abi ( fnabi , exp_abi) ?;
960978 if let Some ( ( body, instance) ) = self . eval_context_mut ( ) . lookup_exported_symbol ( link_name) ? {
961979 // If compiler-builtins is providing the symbol, then don't treat it as a clash.
962980 // We'll use our built-in implementation in `emulate_foreign_item_inner` for increased
@@ -978,14 +996,15 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
978996 fn check_shim < ' a , const N : usize > (
979997 & mut self ,
980998 abi : ExternAbi ,
999+ _fnabi : & FnAbi < ' tcx , Ty < ' tcx > > ,
9811000 exp_abi : ExternAbi ,
9821001 link_name : Symbol ,
9831002 args : & ' a [ OpTy < ' tcx > ] ,
9841003 ) -> InterpResult < ' tcx , & ' a [ OpTy < ' tcx > ; N ] >
9851004 where
9861005 & ' a [ OpTy < ' tcx > ; N ] : TryFrom < & ' a [ OpTy < ' tcx > ] > ,
9871006 {
988- self . check_abi_and_shim_symbol_clash ( abi , exp_abi, link_name) ?;
1007+ self . check_abi_and_shim_symbol_clash ( _fnabi , exp_abi, link_name) ?;
9891008 check_arg_count ( args)
9901009 }
9911010
0 commit comments