diff options
author | Alon Zakai (kripken) <alonzakai@gmail.com> | 2017-07-14 16:27:17 -0700 |
---|---|---|
committer | Alon Zakai (kripken) <alonzakai@gmail.com> | 2017-07-14 16:27:17 -0700 |
commit | 908a74b7db6c51e6ca450a3f68a5ffe4c011f316 (patch) | |
tree | 1235247e187eb37a360191adc5fc027693818aaf | |
parent | 9792a40a8704cbae0ee515126c0b63eb9879d626 (diff) | |
download | binaryen-908a74b7db6c51e6ca450a3f68a5ffe4c011f316.tar.gz binaryen-908a74b7db6c51e6ca450a3f68a5ffe4c011f316.tar.bz2 binaryen-908a74b7db6c51e6ca450a3f68a5ffe4c011f316.zip |
handle an unreachable block with a reachable final element in merge-blocks
-rw-r--r-- | src/passes/MergeBlocks.cpp | 9 | ||||
-rw-r--r-- | test/passes/remove-unused-names_merge-blocks.txt | 5 | ||||
-rw-r--r-- | test/passes/remove-unused-names_merge-blocks.wast | 9 |
3 files changed, 23 insertions, 0 deletions
diff --git a/src/passes/MergeBlocks.cpp b/src/passes/MergeBlocks.cpp index 2c983d991..bce5798a5 100644 --- a/src/passes/MergeBlocks.cpp +++ b/src/passes/MergeBlocks.cpp @@ -188,6 +188,15 @@ static void optimizeBlock(Block* curr, Module* module) { } if (!child) continue; if (child->name.is()) continue; // named blocks can have breaks to them (and certainly do, if we ran RemoveUnusedNames and RemoveUnusedBrs) + if (child->type == unreachable) { + // an unreachable block can have a concrete final element (which is never reached) + if (!child->list.empty()) { + if (isConcreteWasmType(child->list.back()->type)) { + // just remove it + child->list.pop_back(); + } + } + } ExpressionList merged(module->allocator); for (size_t j = 0; j < i; j++) { merged.push_back(curr->list[j]); diff --git a/test/passes/remove-unused-names_merge-blocks.txt b/test/passes/remove-unused-names_merge-blocks.txt index ed448607d..d9186a46e 100644 --- a/test/passes/remove-unused-names_merge-blocks.txt +++ b/test/passes/remove-unused-names_merge-blocks.txt @@ -4,6 +4,7 @@ (type $iii (func (param i32 i32 i32))) (type $3 (func)) (type $4 (func (result i32))) + (type $5 (func (result f64))) (table 1 1 anyfunc) (elem (i32.const 0) $call-i) (memory $0 256 256) @@ -748,4 +749,8 @@ ) (unreachable) ) + (func $concrete_finale_in_unreachable (type $5) (result f64) + (unreachable) + (f64.const -1) + ) ) diff --git a/test/passes/remove-unused-names_merge-blocks.wast b/test/passes/remove-unused-names_merge-blocks.wast index 5cefa357e..f301bbc2e 100644 --- a/test/passes/remove-unused-names_merge-blocks.wast +++ b/test/passes/remove-unused-names_merge-blocks.wast @@ -926,4 +926,13 @@ (unreachable) ) ) + (func $concrete_finale_in_unreachable (result f64) + (block $label$0 (result f64) + (block ;; this block is unreachable + (unreachable) + (f64.const 6.322092475576799e-96) + ) + (f64.const -1) + ) + ) ) |