@@ -999,7 +999,20 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
999
999
& ' a [ OpTy < ' tcx > ; N ] : TryFrom < & ' a [ OpTy < ' tcx > ] > ,
1000
1000
{
1001
1001
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
+ )
1003
1016
}
1004
1017
1005
1018
/// Check shim for variadic function.
@@ -1015,7 +1028,23 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
1015
1028
& ' a [ OpTy < ' tcx > ; N ] : TryFrom < & ' a [ OpTy < ' tcx > ] > ,
1016
1029
{
1017
1030
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" ) ;
1019
1048
}
1020
1049
1021
1050
/// Mark a machine allocation that was just created as immutable.
@@ -1199,7 +1228,7 @@ impl<'tcx> MiriMachine<'tcx> {
1199
1228
}
1200
1229
1201
1230
/// 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 > (
1203
1232
args : & ' a [ OpTy < ' tcx > ] ,
1204
1233
) -> InterpResult < ' tcx , & ' a [ OpTy < ' tcx > ; N ] >
1205
1234
where
@@ -1208,7 +1237,11 @@ where
1208
1237
if let Ok ( ops) = args. try_into ( ) {
1209
1238
return interp_ok ( ops) ;
1210
1239
}
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
+ )
1212
1245
}
1213
1246
1214
1247
/// 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>(
1228
1261
)
1229
1262
}
1230
1263
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
-
1259
1264
pub fn isolation_abort_error < ' tcx > ( name : & str ) -> InterpResult < ' tcx > {
1260
1265
throw_machine_stop ! ( TerminationInfo :: UnsupportedInIsolation ( format!(
1261
1266
"{name} not available when isolation is enabled" ,
0 commit comments