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 ThrowRef execution semantics #330

Merged

Conversation

CharlieTap
Copy link
Contributor

This is another one I found whilst implementing the spec. A rather confusing one to be honest 😓

Effectively if you take the frame at the beginning of the instruction, you may be executing inside an imported function and thus have a different module instance in your stack frame. As part of finding the handler, you unwind the stack and exit this imported function but you are still referencing its module instance. When you then perform the check that attempts to match the tag you would be looking up tag within the wrong module instance.

This test helped me find it:

(module
  (func $imported-throw (import "test" "throw"))
  (tag $e0)

  (func (export "imported-mismatch") (result i32)
    (block $h
      (try_table (result i32) (catch_all $h)
        (block $h0
          (try_table (result i32) (catch $e0 $h0)
            (i32.const 1)
            (call $imported-throw)
          )
          (return)
        )
        (i32.const 2)
      )
      (return)
    )
    (i32.const 3)
  )
)

Copy link
Member

@rossberg rossberg left a comment

Choose a reason for hiding this comment

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

Good catch!

@rossberg rossberg merged commit 24f0819 into WebAssembly:main Sep 13, 2024
6 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