Skip to content

Heap2Local: Handle unreachable ref.test replacement#8605

Merged
kripken merged 2 commits intoWebAssembly:mainfrom
kripken:h2l.test.unreach
Apr 15, 2026
Merged

Heap2Local: Handle unreachable ref.test replacement#8605
kripken merged 2 commits intoWebAssembly:mainfrom
kripken:h2l.test.unreach

Conversation

@kripken
Copy link
Copy Markdown
Member

@kripken kripken commented Apr 15, 2026

As with local.get in other cases, here we replace with something
concrete (a const), and we can't do that if we became unreachable.

@kripken kripken requested a review from tlively April 15, 2026 17:22
@kripken kripken requested a review from a team as a code owner April 15, 2026 17:22
Comment on lines +1413 to +1415
;; The ref.test's input will become unreachable after we optimize. We should
;; not emit a const for the test result, even though we know it, as this is
;; unreachable code which would not validate.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you be more specific about where the validation failure would be? It looks like the constant would flow into the drop, but that would be perfectly valid.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the usual issue with local.get, like we do in a few other places,

if (curr->type == Type::unreachable) {
// We must not modify unreachable code here, as we will replace it with a
// local.get, which has a concrete type (another option could be to run
// DCE and not only ReFinalize - DCE will propagate an unreachable out of
// a concrete block, like we emit here - but we can just ignore such
// code).
return;
}

If we don't skip this code, we emit a block with an unreachable child followed by a concrete one (here, a const). So yes, there is a drop of the block that ends in the constant, but the problem is that the block has the wrong type.

@kripken kripken merged commit ea98200 into WebAssembly:main Apr 15, 2026
16 checks passed
@kripken kripken deleted the h2l.test.unreach branch April 15, 2026 23:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants