Page MenuHomePhabricator

[WebAssembly] Fix a bug in finding matching EH pad
ClosedPublic

Authored by aheejin on May 26 2020, 9:11 AM.

Details

Summary

getMatchingEHPad() in LateEHPrepare is a function to find the nearest
EH pad that dominates the given instruction. This intends to be
lightweight so it does not use full WebAssemblyException scope analysis
or dominator analysis. It simply does backward BFS to its predecessors
and stops at the first EH pad each search path encounters. All search
should end up at the same EH pad, and if not, it returns null.

But it didn't take into account that when there are inner scopes within
the current scope, some path in BFS can hit an inner EH pad first. For
example, in the given diagram, Inst belongs to the outer scope and
getMathingEHPad() should return 'EHPad 1', but some search path can go
into the inner scope and end up with 'EHPad 2'. The search will return
null because different paths end up with different EH pads.

--- EHPad 1 ---
| - EHPad 2 - |
| |         | |
| ----------- |
|   Inst      |
---------------

So far this was OK because we haven't tested a case in which a given
instruction is far from its EH pad. Also, this bug does not happen when
the inner EH scope is a cleanup scope, because a cleanup scope ends with
a cleanupret whose successor is an EH pad, so the search encounters
that EH pad first before going into the child scope. But this can happen
when the child scope is a catch scope that ends with catchret. So this
patch, when doing backward BFS, does not search predecessors that ends
with catchret. Because catchrets are replaced with brs during this
pass, this records BBs that have catchrets in the beginning, before
doing any other transformations.

Diff Detail

Event Timeline

aheejin created this revision.May 26 2020, 9:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 26 2020, 9:11 AM
aheejin updated this revision to Diff 266245.May 26 2020, 9:15 AM
  • Fix test function name
Harbormaster completed remote builds in B57901: Diff 266242.
dschuff accepted this revision.May 28 2020, 4:02 PM
This revision is now accepted and ready to land.May 28 2020, 4:02 PM
This revision was automatically updated to reflect the committed changes.