[PATCH] D80571: [WebAssembly] Fix a bug in finding matching EH pad

Heejin Ahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 26 09:11:49 PDT 2020


aheejin created this revision.
aheejin added a reviewer: dschuff.
Herald added subscribers: llvm-commits, sunfish, hiraditya, jgravelle-google, sbc100.
Herald added a project: LLVM.

`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 `catchret`s are replaced with `br`s during this
pass, this records BBs that have `catchret`s in the beginning, before
doing any other transformations.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80571

Files:
  llvm/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp
  llvm/test/CodeGen/WebAssembly/exception.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80571.266242.patch
Type: text/x-patch
Size: 5931 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200526/9d47047d/attachment.bin>


More information about the llvm-commits mailing list