Skip to content

Fix binary spans on wrapper blocks in IRBuilder - #8944

Open
tlively wants to merge 3 commits into
mainfrom
fix-8940
Open

Fix binary spans on wrapper blocks in IRBuilder#8944
tlively wants to merge 3 commits 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. Update printing of code offsets to include the end offset to make it more obvious in the test that the bug is fixed.

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?

Comment thread src/wasm/wasm-ir-builder.cpp
@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.

@tlively
tlively requested a review from kripken July 28, 2026 21:42
tlively added 3 commits July 28, 2026 16:09
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.
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