[WebAssembly] Handle indirect uses of longjmp
authorHeejin Ahn <aheejin@gmail.com>
Thu, 8 Oct 2020 09:44:16 +0000 (02:44 -0700)
committerHeejin Ahn <aheejin@gmail.com>
Thu, 8 Oct 2020 18:37:19 +0000 (11:37 -0700)
commit750b3ddd80f15334409ae6890de035634e14aa72
tree14e7b42e36138f43848fa3378c9490a78e6c6162
parentd421e0484afd9a951ddf8c986febaf9c3743dc0c
[WebAssembly] Handle indirect uses of longjmp

In LowerEmscriptenEHSjLj, `longjmp` used to be replaced with
`emscripten_longjmp_jmpbuf(jmp_buf*, i32)`, which will eventually be
lowered to `emscripten_longjmp(i32, i32)`. The reason we used two
different names was because they had different signatures in the IR
pass.

D88697 fixed this by only using `emscripten_longjmp(i32, i32)` and
adding a `ptrtoint` cast to its first argument, so
```
longjmp(buf, 0)
```
becomes
```
emscripten_longjmp((i32)buf, 0)
```

But this assumed all uses of `longjmp` was a direct call to it, which
was not the case. This patch handles indirect uses of `longjmp` by
replacing
```
longjmp
```
with
```
(i32(*)(jmp_buf*, i32))emscripten_longjmp
```

Reviewed By: tlively

Differential Revision: https://reviews.llvm.org/D89032
llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
llvm/test/CodeGen/WebAssembly/lower-em-sjlj.ll