Skip to content

Commit 10e4e2c

Browse files
authored
Improve filtering for return_call_indirect with wasm-smith (#1613)
* Improve filtering for `return_call_indirect` with `wasm-smith` Add to the `call_indirect` filter that the selected function type must have the exact same return signature as the function doing the call. Closes #1612 * Add back in tail-call filter
1 parent 2108dfc commit 10e4e2c

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

crates/wasm-smith/src/core/code_builder.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -2044,6 +2044,14 @@ fn call_ref(
20442044

20452045
#[inline]
20462046
fn call_indirect_valid(module: &Module, builder: &mut CodeBuilder) -> bool {
2047+
call_indirect_valid_impl(module, builder, false)
2048+
}
2049+
2050+
fn call_indirect_valid_impl(
2051+
module: &Module,
2052+
builder: &mut CodeBuilder,
2053+
is_return_call: bool,
2054+
) -> bool {
20472055
if module.config.disallow_traps {
20482056
// We have no way to reflect, at run time, on a `funcref` in
20492057
// the `i`th slot in a table and dynamically avoid trapping
@@ -2059,9 +2067,10 @@ fn call_indirect_valid(module: &Module, builder: &mut CodeBuilder) -> bool {
20592067
return false;
20602068
}
20612069
let ty = builder.allocs.operands.pop().unwrap();
2062-
let is_valid = module
2063-
.func_types()
2064-
.any(|(_, ty)| builder.types_on_stack(module, &ty.params));
2070+
let is_valid = module.func_types().any(|(_, ty)| {
2071+
builder.types_on_stack(module, &ty.params)
2072+
&& (!is_return_call || builder.allocs.controls[0].label_types() == &ty.results)
2073+
});
20652074
builder.allocs.operands.push(ty);
20662075
is_valid
20672076
}
@@ -2197,8 +2206,7 @@ fn return_call_indirect_valid(module: &Module, builder: &mut CodeBuilder) -> boo
21972206
if !module.config.tail_call_enabled {
21982207
return false;
21992208
}
2200-
2201-
call_indirect_valid(module, builder)
2209+
call_indirect_valid_impl(module, builder, true)
22022210
}
22032211

22042212
fn return_call_indirect(

0 commit comments

Comments
 (0)