Skip to content

Fix binary spans on wrapper blocks in IRBuilder - #8944

Open
tlively wants to merge 1 commit into
mainfrom
fix-8940
Open

Fix binary spans on wrapper blocks in IRBuilder#8944
tlively wants to merge 1 commit into
mainfrom
fix-8940

Conversation

@tlively

@tlively tlively commented Jul 28, 2026

Copy link
Copy Markdown
Member

When a parsed module contains branches to control flow structures other than blocks or loops, IRBuilder must create a wrapper block around the control flow structure for those branches to target. When that wrapper block is pushed onto the stack, the current binary position is attached as its end position. But the matching start position was previously still attached to the original control flow structure. The lack of an end position on the original control flow structure could cause an assertion failure later when then debug info was written back out. Fix the bug by moving the start position from the original control flow structure to the wrapper block where the matching end position will be attached.

Fixes #8940.

When a parsed module contains branches to control flow structures other than blocks or loops, IRBuilder must create a wrapper block around the control flow structure for those branches to target. When that wrapper block is pushed onto the stack, the current binary position is attached as its end position. But the matching start position was previously still attached to the original control flow structure. The lack of an end position on the original control flow structure could cause an assertion failure later when then debug info was written back out. Fix the bug by moving the start position from the original control flow structure to the wrapper block where the matching end position will be attached.

Fixes #8940.
@tlively
tlively requested a review from kripken July 28, 2026 18:14
@tlively
tlively requested a review from a team as a code owner July 28, 2026 18:14
@tlively

tlively commented Jul 28, 2026

Copy link
Copy Markdown
Member Author

Any thoughts about how to test this?

// When we wrap an expression then push the wrapper, we would end up with the
// binary start location attached to the original expression and the end
// location attached to the wrapper. Move the binary start location to the
// wrapper to avoid splitting the span information.

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.

Hmm, but do we avoid printing this wrapper block both in the text and binary formats? If so then the debug info would not be shown, and it might be better to put it on the original expression instead?

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.

No, we emit the block in both cases because it has a label. It would be interesting to improve at least the binary parser to elide these blocks as a follow-up.

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.

Ok, sgtm them, and lgtm % other comments

@kripken

kripken commented Jul 28, 2026

Copy link
Copy Markdown
Member

For testing, you can use BINARYEN_PRINT_FULL=1 to print out these wrapper blocks in the IR, and their debug info. Though if my comment above makes sense, that might be moot.

@kripken

kripken commented Jul 28, 2026

Copy link
Copy Markdown
Member

Also, can we perhaps document this wrapping process somewhere? That neither AI nor I could figure it out in a reasonable time is unfortunate, as I wrote in the other issue.

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.

wasm-opt crash with module with try + dwarf since emcc 6.0.2

2 participants