diff options
author | Thomas Lively <7121787+tlively@users.noreply.github.com> | 2020-03-18 10:09:14 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-18 10:09:14 -0700 |
commit | 39fda77da51f83b200fc63bbfbc4dd2ccbfc2388 (patch) | |
tree | 93520dc09c04c181a62c0023a9d7b25eb3442a51 | |
parent | 5946b9aa75c8257b8741f0786ebd21f37929cb36 (diff) | |
download | binaryen-39fda77da51f83b200fc63bbfbc4dd2ccbfc2388.tar.gz binaryen-39fda77da51f83b200fc63bbfbc4dd2ccbfc2388.tar.bz2 binaryen-39fda77da51f83b200fc63bbfbc4dd2ccbfc2388.zip |
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.
-rw-r--r-- | src/wasm-stack.h | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/wasm-stack.h b/src/wasm-stack.h index 8662e7835..e00fde5eb 100644 --- a/src/wasm-stack.h +++ b/src/wasm-stack.h @@ -809,8 +809,10 @@ void BinaryenIRWriter<SubType>::visitTupleMake(TupleMake* curr) { for (auto* operand : curr->operands) { visit(operand); } - // No need to handle unreachable since we don't actually emit an instruction emit(curr); + if (curr->type == Type::unreachable) { + emitUnreachable(); + } } template<typename SubType> |