diff options
author | Alon Zakai <alonzakai@gmail.com> | 2018-04-07 10:19:58 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-07 10:19:58 -0700 |
commit | e42e1e3d4a5c67c0c066fe397b456ab8d41a78fd (patch) | |
tree | 6f833f2ede0b626840e2b7b76fec0e712ff0680b /src/wasm-binary.h | |
parent | 5b5789495a97602869f18d552b2a9e1814edefae (diff) | |
download | binaryen-e42e1e3d4a5c67c0c066fe397b456ab8d41a78fd.tar.gz binaryen-e42e1e3d4a5c67c0c066fe397b456ab8d41a78fd.tar.bz2 binaryen-e42e1e3d4a5c67c0c066fe397b456ab8d41a78fd.zip |
Handle literally unreachable brs (#1497)
The optimization in #1495 had a bug which was found by the fuzzer: our binary format parsing will not emit unreachable code (it may be stacky, so we ignore it). However, while parsing it we note breaks that are taken there, and then we removed that code, leading to a state where a break was not taken in the code, but we thought it was.
This PR clarifies the difference between unreachable code in the wasm sense (anything from the start of a block til an unreachable is "reachable") and the literal sense (even that code at the start may not be literally reachable if the block is not reachable), and then we use literal unreachability to know what code will be ignored and therefore we should ignore breaks in.
Diffstat (limited to 'src/wasm-binary.h')
-rw-r--r-- | src/wasm-binary.h | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/wasm-binary.h b/src/wasm-binary.h index b8eb86d31..4b4a37888 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -895,8 +895,22 @@ public: std::vector<Expression*> expressionStack; - bool definitelyUnreachable; // set when we know code is definitely unreachable. this helps parse - // stacky wasm code, which can be unsuitable for our IR when unreachable + // set when we know code is unreachable in the sense of the wasm spec: we are in a block + // and after an unreachable element. + // this helps parse stacky wasm code, which can be unsuitable for our IR when unreachable. + bool unreachableInTheWasmSense; + + // set when the current code being processed will not be emitted in the output, which is the + // case when it is literally unreachable, for example, + // (block $a + // (unreachable) + // (block $b + // ;; code here is reachable in the wasm sense, even though $b as a whole is not + // (unreachable) + // ;; code here is unreachable in the wasm sense + // ) + // ) + bool willBeIgnored; BinaryConsts::ASTNodes lastSeparator = BinaryConsts::End; |