[WebAssembly] Fix remapping branch dests in fixCatchUnwindMismatches
authorHeejin Ahn <aheejin@gmail.com>
Thu, 25 Feb 2021 20:50:04 +0000 (12:50 -0800)
committerHeejin Ahn <aheejin@gmail.com>
Fri, 26 Feb 2021 21:38:13 +0000 (13:38 -0800)
commitd8b3dc5a6853467f75cc496ffd03973076d615b5
tree45cffb187c50d1bcd64a84c475fb16e39d86ab6d
parent83bc7815c4235786111aa2abf7193292e4a602f5
[WebAssembly] Fix remapping branch dests in fixCatchUnwindMismatches

This is a case D97178 tried to solve but missed. D97178 could not handle
the case when
multiple consecutive delegates are generated:
- Before:
```
block
  br (a)
  try
  catch
  end_try
end_block
          <- (a)
```

- After
```
block
  br (a)
  try
    ...
    try
      try
      catch
      end_try
            <- (a)
    delegate
  delegate
end_block
          <- (b)
```
(The `br` should point to (b) now)

D97178 assumed `end_block` exists two BBs later than `end_try`, because
it assumed the order as `end_try` BB -> `delegate` BB -> `end_block` BB.
But it turned out there can be multiple `delegate`s in between. This
patch changes the logic so we just search from `end_try` BB until we
find `end_block`.

Fixes https://github.com/emscripten-core/emscripten/issues/13515.
(More precisely, fixes
https://github.com/emscripten-core/emscripten/issues/13515#issuecomment-784711318.)

Reviewed By: dschuff, tlively

Differential Revision: https://reviews.llvm.org/D97569
llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp
llvm/test/CodeGen/WebAssembly/cfg-stackify-eh.ll