Skip to content

[Flatten] Use target block type for Switch temps - #9312

Merged
tlively merged 1 commit into
mainfrom
flatten-switch-target-type
Oct 28, 2026
Merged

tlively merged 1 commit into
mainfrom
flatten-switch-target-type

Conversation

@tlively

@tlively tlively commented Oct 26, 2026

Copy link
Copy Markdown
Member

When lowering a Switch with a concrete value, Flatten previously passed the switch value's type rather than the target block's type to getTempForBreakTarget. When the switch value had a narrower subtype than the target block (such as nullfuncref flowing to a funcref block), the break temp local was allocated with the narrower subtype, failing validation when the block read the local at the block's result type or when another branch wrote a supertype value. Look up findBreakTarget(name)->type for each Switch target, matching Break.

When lowering a Switch with a concrete value, Flatten previously passed the switch value's type rather than the target block's type to getTempForBreakTarget. When the switch value had a narrower subtype than the target block (such as nullfuncref flowing to a funcref block), the break temp local was allocated with the narrower subtype, failing validation when the block read the local at the block's result type or when another branch wrote a supertype value. Look up findBreakTarget(name)->type for each Switch target, matching Break.
@tlively
tlively requested a review from a team as a code owner October 26, 2026 23:39
@tlively
tlively requested review from aheejin and removed request for a team October 26, 2026 23:39

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request fixes an issue in the Flatten pass where a br_table sending a subtype of its target block's result type would incorrectly allocate the break target local with the narrower sent value type instead of the target block's type. The fix retrieves the actual target block's type to allocate the local correctly. A corresponding test case switch_subtype has been added to verify this behavior. I have no further feedback to provide.

@tlively

tlively commented Oct 26, 2026

Copy link
Copy Markdown
Member Author

Found relatively quickly by the fuzzer after #9303 landed.

@kripken kripken left a comment •

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.

Indeed my PR is a dupe, sorry for not noticing

@tlively
tlively merged commit bceec92 into main Oct 28, 2026
17 checks passed
@tlively
tlively deleted the flatten-switch-target-type branch October 28, 2026 23:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants