srctree

Robin Linden parent 32145798 f59d4e72
wasm: Fix local.tee w/ missing arg incorrectly being valid

inlinesplit
wasm/validation.cpp added: 20, removed: 3, total 17
@@ -408,8 +408,11 @@ tl::expected<void, ValidationError> validate_function(std::uint32_t func_idx,
return tl::unexpected{ValidationError::LocalUndefined};
}
 
if (auto pop_res = v.pop_val_expect(func_code.locals[lt->idx].type); !pop_res.has_value()) {
return tl::unexpected{pop_res.error()};
}
 
v.push_val(func_code.locals[lt->idx].type);
v.pop_val_expect(func_code.locals[lt->idx].type);
}
// https://webassembly.github.io/spec/core/valid/instructions.html#memory-instructions
else if (I32Load const *i32l = std::get_if<I32Load>(&inst)) {
 
wasm/validation_test.cpp added: 20, removed: 3, total 17
@@ -197,5 +197,19 @@ int main() {
a.expect_eq(validate(m), tl::unexpected{ValidationError::ValueStackUnderflow});
});
 
s.add_test("Function: localtee, valid", [=](etest::IActions &a) mutable {
m.code_section->entries[0].code = {I32Const{42}, LocalTee{.idx = 0}};
m.code_section->entries[0].locals = {{.count = 1, .type = ValueType::Int32}};
 
a.expect(validate(m).has_value());
});
 
s.add_test("Function: localtee, missing arg", [=](etest::IActions &a) mutable {
m.code_section->entries[0].code = {LocalTee{.idx = 0}};
m.code_section->entries[0].locals = {{.count = 1, .type = ValueType::Int32}};
 
a.expect_eq(validate(m), tl::unexpected{ValidationError::ValueStackUnderflow});
});
 
return s.run();
}