Skip to content

SubtypingDiscoverer: Handle values flowing out of br_if#8101

Merged
kripken merged 3 commits into
WebAssembly:mainfrom
kripken:se.fix.extracted
Dec 11, 2025
Merged

SubtypingDiscoverer: Handle values flowing out of br_if#8101
kripken merged 3 commits into
WebAssembly:mainfrom
kripken:se.fix.extracted

Conversation

@kripken
Copy link
Copy Markdown
Member

@kripken kripken commented Dec 5, 2025

Consider

(br_if $target
  (value)
  (condition)
)

The value here must be a subtype of the thing the br_if flows into,
and also of the block it targets - the value is sent twice, effectively,
so it has two subtyping constraints. We were missing the value
flowing out.

@kripken kripken requested a review from tlively December 9, 2025 23:51
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.

Can we add an Unsubtyping lit test for this instead? That will be less code and easier to maintain with auto-update scripts.

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.

Unfortunately no. Here is what such a testcase would look like:

(module
 (type $super (sub (struct)))
 (type $sub (sub $super (struct)))

 (func $block-fallthrough
  (local $super (ref $super))
  (drop
   (block $l (result (ref $sub))
    ;; The value flowing out of the br_if requires $sub <: $super
    (local.set $super
     (br_if $l
      (struct.new $sub)
      (i32.const 0)
     )
    )
    (unreachable)
   )
  )
 )
)

This PR adds a subtyping link from the br_if to its value child, but this testcase works without it: Unsubtyping also sees the connection between the local.set to the br_if, using the br_if's type. So the wasm type system helps us here. This is, I assume, why we didn't see this bug without the fuzzer.

The fuzzer hits this issue because it needs to know more than Unsubtyping. Unsubtyping infers we must keep the subtyping in this testcase - it only cares about the type level - while when the fuzzer mutates, it needs to know which types it can replace specific things with. We do need the link between the br_if and its child, for that: That informs us about the child, so we know what types it can contain.

@kripken kripken enabled auto-merge (squash) December 11, 2025 01:10
@kripken kripken merged commit 8e5f757 into WebAssembly:main Dec 11, 2025
17 checks passed
@kripken kripken deleted the se.fix.extracted branch December 11, 2025 16:13
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.

2 participants