This is an archive of the discontinued LLVM Phabricator instance.

[WebAssemblly] Fix rethrow's argument computation
ClosedPublic

Authored by aheejin on Feb 12 2021, 5:40 AM.

Details

Summary

Previously we assumed rethrow's argument was always 0, but it turned
out rethrow follows the same rule with br or delegate:
https://github.com/WebAssembly/exception-handling/pull/137
https://github.com/WebAssembly/exception-handling/issues/146#issuecomment-777349038

Currently rethrows generated by our backend always rethrow the
exception caught by the innermost enclosing catch, so this adds a
function to compute that and replaces rethrow's argument with its
computed result.

This also renames EHPadStack in InstPrinter to TryStack, because
in CFGStackify we use EHPadStack to mean the range between
catch~end, while in InstPrinter we used it to mean the range
between try~catch, so choosing different names would look clearer.
Doesn't contain any functional changes in InstPrinter.

Diff Detail

Event Timeline

aheejin created this revision.Feb 12 2021, 5:40 AM
aheejin requested review of this revision.Feb 12 2021, 5:40 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 12 2021, 5:40 AM
aheejin edited the summary of this revision. (Show Details)Feb 12 2021, 5:43 AM
aheejin edited the summary of this revision. (Show Details)

This replaces D96532. D96532 didn't correctly handle this case:

try
  ...
catch
  try
    rethrow 1 ;; (1)
  catch
    rethrow 0 ;; (2)
  end
end

D96532 correctly computed the argument for (2) but not (1). Because (1) rethrows the exception caught by the outer catch, its argument shouldn't be 0, but D96532 computed it as 0. This CL correctly handles this case.

llvm/test/CodeGen/WebAssembly/exception.mir
49

These are just drive-by changes and not related to rethrow. (CATCHRET's second argument should be the landingpad BB but this was incorrect before, but because we don't really use the second argument this didn't matter.)

dschuff accepted this revision.Feb 12 2021, 9:53 AM

This replaces D96532. D96532 didn't correctly handle this case:

try
  ...
catch
  try
    rethrow 1 ;; (1)
  catch
    rethrow 0 ;; (2)
  end
end

OK, I think I get the indexing scheme now... I didn't think about 'try' having a label, so if (1) were 'rethrow 0' it would refer to the 'try' (and therefore be invalid)

llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp
1575
llvm/test/CodeGen/WebAssembly/exception.mir
108

this is "RETHROW 0" in the test input because it's just the placeholder from ISel, right?

This revision is now accepted and ready to land.Feb 12 2021, 9:53 AM
aheejin marked an inline comment as done.Feb 12 2021, 12:23 PM

This replaces D96532. D96532 didn't correctly handle this case:

try
  ...
catch
  try
    rethrow 1 ;; (1)
  catch
    rethrow 0 ;; (2)
  end
end

OK, I think I get the indexing scheme now... I didn't think about 'try' having a label, so if (1) were 'rethrow 0' it would refer to the 'try' (and therefore be invalid)

Yes, if (1) were rethrow 0, it will refer to the inner try, so it is a validation failure.

I originally hadn't thought about try having a label as well, but as I wrote in https://github.com/WebAssembly/exception-handling/issues/146, it seems convenient and consistent to allow delegate have a label argument that is computed in the same way as branches, and rethrow seems no different from delegate if we look at the rethrow label rule written in https://github.com/WebAssembly/exception-handling/pull/137. I just copied that rule from the very first version of the spec and I myself was misunderstanding that rule, which I realized after reading Thibaud's comment in https://bugs.chromium.org/p/v8/issues/detail?id=11402.

llvm/test/CodeGen/WebAssembly/exception.mir
108

Yes.

aheejin updated this revision to Diff 323445.Feb 12 2021, 12:24 PM

Address comments

aheejin updated this revision to Diff 323479.Feb 12 2021, 2:17 PM

Remove a stray ; in comment

This revision was landed with ongoing or failed builds.Feb 13 2021, 3:43 AM
This revision was automatically updated to reflect the committed changes.