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

[EH] Handle nested pops after inlining #4404

Merged
merged 3 commits into from Dec 21, 2021
Merged

Conversation

aheejin
Copy link
Member

@aheejin aheejin commented Dec 20, 2021

Inlining creates additional blocks at inlined call sites, which can be
inside a catch. For example:

(try
  (do)
  (catch $tag
    (call $callee
      (pop i32)
    )
  )
)

After inlining, this becomes

(try
  (do)
  (catch $tag
    (block $__inlined_func$callee
      (local.set $0
        (pop i32) ;; Invalid!!
      )
    (nop)
    )
  )
)

Now the pop is nested in a block, which makes this invalid. This PR
runs EHUtils::handleBlockNestedPops at the end to assign the pop to
a local right after the catch, making the code valid again:

(try
  (do)
  (catch $tag
    (local.set $new ;; New local to store `pop` result
      (pop i32)
    )
    (block $__inlined_func$callee
      (local.set $0
        (local.get $new)
      )
    (nop)
    )
  )
)

Inlining creates additional `block`s at inlined call sites, which can be
inside a `catch`. For example:
```wast
(try
  (do)
  (catch $tag
    (call $callee
      (pop i32)
    )
  )
)
```

After inlining, this becomes
```wast
(try
  (do)
  (catch $tag$0
    (block $__inlined_func$callee
      (local.set $0
        (pop i32) ;; Invalid!!
      )
    (nop)
    )
  )
)
```

Now the `pop` is nested in a `block`, which makes this invalid. This PR
runs `EHUtils::handleBlockNestedPops` at the end to assign the `pop` to
a local right after the `catch`, making the code valid again.
@aheejin aheejin requested review from kripken and tlively Dec 20, 2021
Copy link
Member

@tlively tlively left a comment

LGTM!

@aheejin aheejin merged commit 083ab98 into WebAssembly:main Dec 21, 2021
11 checks passed
@aheejin aheejin deleted the inline_eh_pop branch Dec 21, 2021
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.

None yet

2 participants