This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] Fix catch unwind mismatches
ClosedPublic

Authored by aheejin on Jan 4 2021, 3:54 PM.

Details

Summary

This fixes unwind destination mismatches caused by 'catch'es, which
occur when a foreign exception is not caught by the nearest catch and
the next outer catch is not the catch it should unwind to, or the next
unwind destination should be the caller instead. This kind of mismatches
didn't exist in the previous version of the spec, because in the
previous spec catch was effectively catch_all, catching all
exceptions.

Diff Detail

Event Timeline

aheejin created this revision.Jan 4 2021, 3:54 PM
aheejin requested review of this revision.Jan 4 2021, 3:54 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 4 2021, 3:54 PM
tlively added inline comments.Jan 15 2021, 9:39 PM
llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp
905–906

What is an example of when the split position could be before catch?

1267–1373
1268
1321–1322

~Is this supposed to be a continue?~ Oh, I see it's just there in service of the else ifs below. I found this confusing when I first saw it (especially without braces). I think it would be clearer if structured a different way.

aheejin marked 2 inline comments as done.Jan 18 2021, 8:54 AM
aheejin added inline comments.
llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp
905–906

When fixing catch mismatches. When an inner try is included in a body of an outer try:

bb0:
  try
    try
      ...
bb1 (ehpad):
    catch ...
      ...
bb2: (ehpad)
    end_try
  catch ...
    ...

Suppose we need to wrap the inner try with try-delegate:

bb0:
  try
    try          ;; new inst
      try
        ...
bb1 (ehpad):
      catch ...
        ...
bb-pre: (ehpad)  ;; new BB
      end_try
bb-delegate:     ;; new BB
    delegate    ;; new inst
bb2 (ehpad):
  catch ...
    ...

The split pos is before the catch in bb2. Because catch's BB should be preserved, because that's what WasmEHFuncInfo remembers.

1321–1322

The reason this is not a continue is it needs to run the common code at the very bottom:

EHPadStack.push_back(EHPad);

I can add the braces. Do you have any other restructuring suggestions?

aheejin updated this revision to Diff 317372.Jan 18 2021, 8:54 AM
  • Address comments
tlively accepted this revision.Jan 28 2021, 1:14 PM

Sorry for dropping this for such a long time!

llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp
905–906

I see, I was thinking that catch would always be at the beginning of a BB, but I hadn't considered that various end markers may precede it.

1321–1322

No, this looks clear now. Thanks!

This revision is now accepted and ready to land.Jan 28 2021, 1:14 PM
This revision was automatically updated to reflect the committed changes.