Fix block-nested Pop in GUFA#8747
Open
tlively wants to merge 1 commit into
Open
Conversation
In GUFA, when optimizing RefEq or RefTest expressions, they are replaced by constants if the optimizer can prove the two sides have no intersection. However, if the expression contains side effects (like a Pop), getDroppedChildrenAndAppend is used to preserve them, which wraps the side-effect expressions in a Block. If the Pop is nested inside this Block, it becomes invalidly nested within the catch block, which violates validation rules. GUFA has a fixup pass (EHUtils::handleBlockNestedPops) designed to fix this by spilling the Pop to a local, but it was not being run because visitRefEq and visitRefTest failed to set the `optimized = true` flag. Fix the issue by setting `optimized = true` when RefEq or RefTest are optimized, ensuring the post-optimization cleanups (including the nested pop fixup) are executed. Add a regression test to gufa-cast-all.wast.
| auto* result = Builder(*getModule()).makeConst(Literal(int32_t(0))); | ||
| replaceCurrent(getDroppedChildrenAndAppend( | ||
| curr, *getModule(), getPassOptions(), result)); | ||
| optimized = true; |
Member
There was a problem hiding this comment.
This pass has an override for replaceCurrent, I wonder if we should have that method set optimized by default so that we don't forget other cases? It seems like after this PR, all usages of replaceCurrent set optimized to true. I don't have a strong opinion, I can imagine there might be cases where we don't want to set it to true unintentionally too.
stevenfontanella
approved these changes
May 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In GUFA, when optimizing RefEq or RefTest expressions, they are replaced by constants if the optimizer can prove the two sides have no intersection. However, if the expression contains side effects (like a Pop), getDroppedChildrenAndAppend is used to preserve them, which wraps the side-effect expressions in a Block.
If the Pop is nested inside this Block, it becomes invalidly nested within the catch block, which violates validation rules. GUFA has a fixup pass (EHUtils::handleBlockNestedPops) designed to fix this by spilling the Pop to a local, but it was not being run because visitRefEq and visitRefTest failed to set the
optimized = trueflag.Fix the issue by setting
optimized = truewhen RefEq or RefTest are optimized, ensuring the post-optimization cleanups (including the nested pop fixup) are executed.Add a regression test to gufa-cast-all.wast.