This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] Fix fixEndsAtEndOfFunction for try-catch
ClosedPublic

Authored by aheejin on Sep 6 2020, 12:00 PM.

Details

Summary

When the function return type is non-void and end instructions are at
the very end of a function, CFGStackify's fixEndsAtEndOfFunction
function fixes the corresponding block/loop/try's type to match the
function's return type. This is applied to consecutive end markers at
the end of a function. For example, when the function return type is
i32,

block i32    ;; return type is fixed to i32
  ...
  loop i32   ;; return type is fixed to i32
    ...
  end_loop
end_block
end_function

But try-catch is a little different, because it consists of two parts:
a try part and a catch part, and both parts' return type should satisfy
the function's return type. Which means,

try i32      ;; return type is fixed to i32
  ...
  block i32  ;; this should be changed i32 too!
    ...
  end_block
catch
  ...
end_try
end_function

As you can see in this example, it is not sufficient to only end
instructions at the end of a function; in case of try, we should
check instructions before catches, in case their corresponding try's
type has been fixed.

This changes fixEndsAtEndOfFunction's algorithm to use a worklist
that contains a reverse iterator, each of which is a starting point for
a new backward end instruction search.

Fixes https://bugs.llvm.org/show_bug.cgi?id=47413.

Diff Detail

Event Timeline

aheejin created this revision.Sep 6 2020, 12:00 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 6 2020, 12:00 PM
aheejin requested review of this revision.Sep 6 2020, 12:00 PM
aheejin added inline comments.Sep 6 2020, 12:04 PM
llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp
1105–1109

This comment block is out-of-date; we don't search for 'local.set' or 'drop' anymore. Deleted it while touching this code.

1110–1121

This is extracted as findCatch method above.

aheejin updated this revision to Diff 290334.Sep 7 2020, 11:26 AM
  • clang-tidy fix
tlively accepted this revision.Sep 7 2020, 4:39 PM

LGTM!

This revision is now accepted and ready to land.Sep 7 2020, 4:39 PM
dschuff accepted this revision.Sep 8 2020, 9:17 AM
This revision was automatically updated to reflect the committed changes.