Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs involving the combination of branching and subtyping #1403

Merged

Conversation

fitzgen
Copy link
Member

@fitzgen fitzgen commented Feb 7, 2024

This PR fixes similar bugs in both wasmparser and wasm-smith.

If we are conditionally branching to a label whose type is [a b] and we have [a' b'] on the stack where a' <: a and b' <: b, we need to replace the stack's subtypes with the label's types after processing the instruction.

That is, the following three operations, which used to be (mostly) equivalent before subtyping, are no longer equivalent:

  1. pop_operands(label_types); push_operands(label_types)
  2. push_operands(pop_operands(label_types))
  3. Not pushing or popping, just checking the types on the stack match the label types

We generally have to do (1) to properly erase subtyping, as called for by the spec. (2) is still used for br_table however. (3) should generally be avoided.

See also WebAssembly/gc#516

…ches

When, for example, `[a i32]` is on the stack and we have a `br_if @label` where
`@label`'s type is `[b]` and `a <: b`, then whole `br_if` is typed `[b i32] ->
[b]`. Because `a <: b` the `br_if` is valid. However, `a <: b` does *not* mean
that the instruction results in `[a]`. It "erases" the `a` and pushes a `b`.

This addresses WebAssembly/gc#516 in `wasm-smith`.
@alexcrichton alexcrichton merged commit 7eae522 into bytecodealliance:main Feb 8, 2024
15 checks passed
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