This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] Fix PHI when relaying longjmps
ClosedPublic

Authored by aheejin on Aug 26 2021, 12:55 PM.

Details

Summary

When doing Emscritpen EH, if SjLj is also enabled and used and if the
thrown exception has a possiblity being a longjmp instead of an
exception, we shouldn't swallow it; we should rethrow, or relay it. It
was done in D106525 and the code is here:
https://github.com/llvm/llvm-project/blob/8441a8eea8007b9eaaaabf76055949180a702d6d/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp#L858-L898

Here is the pseudocode of that part: (copied from comments)

if (%__THREW__.val == 0 || %__THREW__.val == 1)
  goto %tail
else
  goto %longjmp.rethrow

longjmp.rethrow: ;; This is longjmp. Rethrow it
  %__threwValue.val = __threwValue
  emscripten_longjmp(%__THREW__.val, %__threwValue.val);

tail: ;; Nothing happened or an exception is thrown
  ... Continue exception handling ...

If the current BB (where the invoke is created) has successors that
has the current BB as its PHI incoming node, now that has to change to
tail in the pseudocode, because tail is the latest BB that is
connected with the next BB, but this was missing.

Diff Detail

Event Timeline

aheejin created this revision.Aug 26 2021, 12:55 PM
aheejin requested review of this revision.Aug 26 2021, 12:55 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 26 2021, 12:55 PM
aheejin retitled this revision from [WebAssembly] Fix PHI when bypassing longjmps to [WebAssembly] Fix PHI when relaying longjmps.Aug 26 2021, 4:44 PM
tlively accepted this revision.Aug 26 2021, 4:54 PM

"shoudln't" => "shouldn't" in the PR description.

This revision is now accepted and ready to land.Aug 26 2021, 4:54 PM
aheejin edited the summary of this revision. (Show Details)Aug 26 2021, 5:21 PM
This revision was landed with ongoing or failed builds.Aug 26 2021, 5:25 PM
This revision was automatically updated to reflect the committed changes.