summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/passes/MergeBlocks.cpp9
-rw-r--r--test/passes/remove-unused-names_merge-blocks.txt5
-rw-r--r--test/passes/remove-unused-names_merge-blocks.wast9
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)
+ )
+ )
)