Skip to content

Fix br_on_cast parsing with non-nullable extra values - #9036

Open
pttydou wants to merge 2 commits into
WebAssembly:mainfrom
pttydou:fix-br-on-cast-extra-values
Open

Fix br_on_cast parsing with non-nullable extra values#9036
pttydou wants to merge 2 commits into
WebAssembly:mainfrom
pttydou:fix-br-on-cast-extra-values

Conversation

@pttydou

@pttydou pttydou commented Aug 23, 2026

Copy link
Copy Markdown

Fixes #8949.

Text parsing did not normalize synthesized non-defaultable scratch locals after finishing each function, unlike binary reading. This applies the existing fixup and preserves exact reference types when building nullable-output br_on_cast fallthrough values.

Tests:

  • python out/bin/binaryen-lit -vv test/lit/basic/br-on-cast-extra-values.wast test/lit/basic/scratch-local-roundtrip.wast test/lit/basic/extra-branch-values.wast test/lit/basic/unreachable-br-on-cast-desc.wast test/lit/basic/exact-references.wast test/lit/cast-to-basic.wast
  • ruff check

@pttydou
pttydou requested a review from a team as a code owner August 23, 2026 15:22
@pttydou
pttydou requested review from kripken and removed request for a team August 23, 2026 15:22

@tlively tlively 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.

Thanks! LGTM with the test updated.

Comment on lines +1 to +2
;; RUN: wasm-opt %s -all -S -o %t
;; RUN: wasm-opt %s -all --roundtrip -S -o %t.roundtrip

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.

Please update the test to include the expected output. After updating the RUN line, you can use scripts/update_lit_checks.py to generate the expectations.

Suggested change
;; RUN: wasm-opt %s -all -S -o %t
;; RUN: wasm-opt %s -all --roundtrip -S -o %t.roundtrip
;; RUN: wasm-opt %s -all --roundtrip -S -o - | filecheck %s

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Updated the test to pipe the roundtrip output through FileCheck and generated the expected output with scripts/update_lit_checks.py. The focused lit tests pass locally.

Comment on lines +69 to +70
TypeUpdating::handleNonDefaultableLocals(
f, decls.wasm, firstScratchLocal);

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.

Let's not worry about the firstScratchLocal optimization and just call handleNonDefaultableLocals as-is. It's ok if it fixes locals that were used invalidly in the input; there are a few similar cases where we end up parsing and accepting invalid modules.

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.

Parse bug with extra non-nullable br_on_cast values

2 participants