Skip to content

Commit 7231e61

Browse files
committed
fix merge-blocks bug with replacing an unreachable block with a concrete final element (which is never reached)
1 parent cc193a4 commit 7231e61

3 files changed

Lines changed: 33 additions & 4 deletions

File tree

src/passes/MergeBlocks.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,12 @@ struct MergeBlocks : public WalkerPass<PostWalker<MergeBlocks>> {
294294
// here
295295
return outer;
296296
}
297+
// we are going to replace the block with the final element, so they should
298+
// be identically typed
299+
if (block->type != back->type) {
300+
return outer;
301+
}
297302
child = back;
298-
// we modified child (which is a reference to a pointer), which modifies curr, which might change its type
299-
// (e.g. (drop (block (result i32) .. (unreachable)))
300-
// the child was a block of i32, and is being replaced with an unreachable, so the
301-
// parent will likely need to be unreachable too
302303
if (outer == nullptr) {
303304
// reuse the block, move it out
304305
block->list.back() = curr;

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,4 +892,18 @@
892892
)
893893
)
894894
)
895+
(func $drop-unreachable-block-with-concrete-final (type $3)
896+
(drop
897+
(block
898+
(drop
899+
(block
900+
(drop
901+
(return)
902+
)
903+
)
904+
)
905+
(i32.const -452)
906+
)
907+
)
908+
)
895909
)

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,4 +1054,18 @@
10541054
)
10551055
)
10561056
)
1057+
(func $drop-unreachable-block-with-concrete-final
1058+
(drop
1059+
(block
1060+
(drop
1061+
(block
1062+
(drop
1063+
(return)
1064+
)
1065+
)
1066+
)
1067+
(i32.const -452)
1068+
)
1069+
)
1070+
)
10571071
)

0 commit comments

Comments
 (0)