diff options
author | Alon Zakai <alonzakai@gmail.com> | 2017-08-07 15:42:17 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-07 15:42:17 -0700 |
commit | b93ea39b239052314123d3641df29ff5c5730515 (patch) | |
tree | 0149686671e54158ced8647287f28172782718bf /src/wasm/wasm-binary.cpp | |
parent | 62f6a12c4fa109522229526e9d89969d2fde7399 (diff) | |
parent | e17202e4d20bf79bd285425bac606a31bf3a8131 (diff) | |
download | binaryen-b93ea39b239052314123d3641df29ff5c5730515.tar.gz binaryen-b93ea39b239052314123d3641df29ff5c5730515.tar.bz2 binaryen-b93ea39b239052314123d3641df29ff5c5730515.zip |
Merge pull request #1123 from WebAssembly/fuzz-2
Yet more fuzz fixes
Diffstat (limited to 'src/wasm/wasm-binary.cpp')
-rw-r--r-- | src/wasm/wasm-binary.cpp | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 47bcc8ba5..63dddbdd6 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -583,6 +583,11 @@ void WasmBinaryWriter::recursePossibleBlockContents(Expression* curr) { for (auto* child : block->list) { recurse(child); } + if (block->type == unreachable && block->list.back()->type != unreachable) { + // similar to in visitBlock, here we could skip emitting the block itself, + // but must still end the 'block' (the contents, really) with an unreachable + o << int8_t(BinaryConsts::Unreachable); + } } void WasmBinaryWriter::visitIf(If *curr) { @@ -2073,6 +2078,20 @@ BinaryConsts::ASTNodes WasmBinaryBuilder::readExpression(Expression*& curr) { return BinaryConsts::ASTNodes(code); } +void WasmBinaryBuilder::pushBlockElements(Block* curr, size_t start, size_t end) { + for (size_t i = start; i < end; i++) { + auto* item = expressionStack[i]; + curr->list.push_back(item); + if (i < end - 1) { + // stacky&unreachable code may introduce elements that need to be dropped in non-final positions + if (isConcreteWasmType(item->type)) { + curr->list.back() = Builder(wasm).makeDrop(curr->list.back()); + } + } + } + expressionStack.resize(start); +} + void WasmBinaryBuilder::visitBlock(Block *curr) { if (debug) std::cerr << "zz node: Block" << std::endl; // special-case Block and de-recurse nested blocks in their first position, as that is @@ -2108,18 +2127,7 @@ void WasmBinaryBuilder::visitBlock(Block *curr) { if (end < start) { throw ParseException("block cannot pop from outside"); } - for (size_t i = start; i < end; i++) { - if (debug) std::cerr << " " << size_t(expressionStack[i]) << "\n zz Block element " << curr->list.size() << std::endl; - auto* item = expressionStack[i]; - curr->list.push_back(item); - if (i < end - 1) { - // stacky&unreachable code may introduce elements that need to be dropped in non-final positions - if (isConcreteWasmType(item->type)) { - curr->list.back() = Builder(wasm).makeDrop(curr->list.back()); - } - } - } - expressionStack.resize(start); + pushBlockElements(curr, start, end); curr->finalize(curr->type); breakStack.pop_back(); } @@ -2136,11 +2144,8 @@ Expression* WasmBinaryBuilder::getMaybeBlock(WasmType type) { throw ParseException("block cannot pop from outside"); } auto* block = allocator.alloc<Block>(); - for (size_t i = start; i < end; i++) { - block->list.push_back(expressionStack[i]); - } + pushBlockElements(block, start, end); block->finalize(type); - expressionStack.resize(start); return block; } |