@@ -999,7 +999,20 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
999999 & ' a [ OpTy < ' tcx > ; N ] : TryFrom < & ' a [ OpTy < ' tcx > ] > ,
10001000 {
10011001 self . check_abi_and_shim_symbol_clash ( abi, exp_abi, link_name) ?;
1002- check_arg_count ( args)
1002+
1003+ if abi. c_variadic {
1004+ throw_ub_format ! (
1005+ "calling a non-variadic function with a variadic caller-side signature"
1006+ ) ;
1007+ }
1008+ if let Ok ( ops) = args. try_into ( ) {
1009+ return interp_ok ( ops) ;
1010+ }
1011+ throw_ub_format ! (
1012+ "incorrect number of arguments for `{link_name}`: got {}, expected {}" ,
1013+ args. len( ) ,
1014+ N
1015+ )
10031016 }
10041017
10051018 /// Check shim for variadic function.
@@ -1015,7 +1028,23 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
10151028 & ' a [ OpTy < ' tcx > ; N ] : TryFrom < & ' a [ OpTy < ' tcx > ] > ,
10161029 {
10171030 self . check_abi_and_shim_symbol_clash ( abi, exp_abi, link_name) ?;
1018- check_vargarg_fixed_arg_count ( link_name, abi, args)
1031+
1032+ if !abi. c_variadic {
1033+ throw_ub_format ! (
1034+ "calling a variadic function with a non-variadic caller-side signature"
1035+ ) ;
1036+ }
1037+ if abi. fixed_count != u32:: try_from ( N ) . unwrap ( ) {
1038+ throw_ub_format ! (
1039+ "incorrect number of fixed arguments for variadic function `{}`: got {}, expected {N}" ,
1040+ link_name. as_str( ) ,
1041+ abi. fixed_count
1042+ )
1043+ }
1044+ if let Some ( args) = args. split_first_chunk ( ) {
1045+ return interp_ok ( args) ;
1046+ }
1047+ panic ! ( "mismatch between signature and `args` slice" ) ;
10191048 }
10201049
10211050 /// Mark a machine allocation that was just created as immutable.
@@ -1199,7 +1228,7 @@ impl<'tcx> MiriMachine<'tcx> {
11991228}
12001229
12011230/// Check that the number of args is what we expect.
1202- pub fn check_arg_count < ' a , ' tcx , const N : usize > (
1231+ pub fn check_intrinsic_arg_count < ' a , ' tcx , const N : usize > (
12031232 args : & ' a [ OpTy < ' tcx > ] ,
12041233) -> InterpResult < ' tcx , & ' a [ OpTy < ' tcx > ; N ] >
12051234where
@@ -1208,7 +1237,11 @@ where
12081237 if let Ok ( ops) = args. try_into ( ) {
12091238 return interp_ok ( ops) ;
12101239 }
1211- throw_ub_format ! ( "incorrect number of arguments: got {}, expected {}" , args. len( ) , N )
1240+ throw_ub_format ! (
1241+ "incorrect number of arguments for intrinsic: got {}, expected {}" ,
1242+ args. len( ) ,
1243+ N
1244+ )
12121245}
12131246
12141247/// Check that the number of varargs is at least the minimum what we expect.
@@ -1228,34 +1261,6 @@ pub fn check_min_vararg_count<'a, 'tcx, const N: usize>(
12281261 )
12291262}
12301263
1231- /// Check the number of fixed args of a vararg function.
1232- /// Returns a tuple that consisting of an array of fixed args, and a slice of varargs.
1233- fn check_vargarg_fixed_arg_count < ' a , ' tcx , const N : usize > (
1234- link_name : Symbol ,
1235- abi : & FnAbi < ' tcx , Ty < ' tcx > > ,
1236- args : & ' a [ OpTy < ' tcx > ] ,
1237- ) -> InterpResult < ' tcx , ( & ' a [ OpTy < ' tcx > ; N ] , & ' a [ OpTy < ' tcx > ] ) > {
1238- if !abi. c_variadic {
1239- throw_ub_format ! ( "calling a variadic function with a non-variadic caller-side signature" ) ;
1240- }
1241- if abi. fixed_count != u32:: try_from ( N ) . unwrap ( ) {
1242- throw_ub_format ! (
1243- "incorrect number of fixed arguments for variadic function `{}`: got {}, expected {N}" ,
1244- link_name. as_str( ) ,
1245- abi. fixed_count
1246- )
1247- }
1248- if let Some ( args) = args. split_first_chunk ( ) {
1249- return interp_ok ( args) ;
1250- }
1251- throw_ub_format ! (
1252- "incorrect number of arguments for `{}`: got {}, expected at least {}" ,
1253- link_name. as_str( ) ,
1254- args. len( ) ,
1255- N
1256- )
1257- }
1258-
12591264pub fn isolation_abort_error < ' tcx > ( name : & str ) -> InterpResult < ' tcx > {
12601265 throw_machine_stop ! ( TerminationInfo :: UnsupportedInIsolation ( format!(
12611266 "{name} not available when isolation is enabled" ,
0 commit comments