Skip to content

Commit 908a74b

Browse files
committed
handle an unreachable block with a reachable final element in merge-blocks
1 parent 9792a40 commit 908a74b

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

src/passes/MergeBlocks.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,15 @@ static void optimizeBlock(Block* curr, Module* module) {
188188
}
189189
if (!child) continue;
190190
if (child->name.is()) continue; // named blocks can have breaks to them (and certainly do, if we ran RemoveUnusedNames and RemoveUnusedBrs)
191+
if (child->type == unreachable) {
192+
// an unreachable block can have a concrete final element (which is never reached)
193+
if (!child->list.empty()) {
194+
if (isConcreteWasmType(child->list.back()->type)) {
195+
// just remove it
196+
child->list.pop_back();
197+
}
198+
}
199+
}
191200
ExpressionList merged(module->allocator);
192201
for (size_t j = 0; j < i; j++) {
193202
merged.push_back(curr->list[j]);

test/passes/remove-unused-names_merge-blocks.txt

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
(type $iii (func (param i32 i32 i32)))
55
(type $3 (func))
66
(type $4 (func (result i32)))
7+
(type $5 (func (result f64)))
78
(table 1 1 anyfunc)
89
(elem (i32.const 0) $call-i)
910
(memory $0 256 256)
@@ -748,4 +749,8 @@
748749
)
749750
(unreachable)
750751
)
752+
(func $concrete_finale_in_unreachable (type $5) (result f64)
753+
(unreachable)
754+
(f64.const -1)
755+
)
751756
)

test/passes/remove-unused-names_merge-blocks.wast

+9
Original file line numberDiff line numberDiff line change
@@ -926,4 +926,13 @@
926926
(unreachable)
927927
)
928928
)
929+
(func $concrete_finale_in_unreachable (result f64)
930+
(block $label$0 (result f64)
931+
(block ;; this block is unreachable
932+
(unreachable)
933+
(f64.const 6.322092475576799e-96)
934+
)
935+
(f64.const -1)
936+
)
937+
)
929938
)

0 commit comments

Comments
 (0)