Skip to content

Commit 39fda77

Browse files
authored
Emit unreachable tuple.make properly (#2701)
We previously thought unreachable `tuple.make` instructions did not require special unreachable handling, but consider the following wast: ``` (module (func $foo (tuple.make (unreachable) (i32.const 42) ) ) ) ``` This validates because the only expression in the body is unreachable, but when it is emitted as a binary it becomes ``` unreachable i32.const 42 ``` This does not validate because it ends with an i32, but the function expected an empty stack at the end. The fix is to emit an extra `unreachable` after unreachable `tuple.make` instructions. Unfortunately it is impossible to write a test for this right now because the binary parser silently drops the `i32.const 42`, making the function valid again.
1 parent 5946b9a commit 39fda77

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/wasm-stack.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,8 +809,10 @@ void BinaryenIRWriter<SubType>::visitTupleMake(TupleMake* curr) {
809809
for (auto* operand : curr->operands) {
810810
visit(operand);
811811
}
812-
// No need to handle unreachable since we don't actually emit an instruction
813812
emit(curr);
813+
if (curr->type == Type::unreachable) {
814+
emitUnreachable();
815+
}
814816
}
815817

816818
template<typename SubType>

0 commit comments

Comments
 (0)