[PATCH] D65475: Fix __clang_call_termiante's argument for foreign exceptions
Heejin Ahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 30 13:12:14 PDT 2019
aheejin created this revision.
aheejin added a reviewer: dschuff.
Herald added subscribers: llvm-commits, hiraditya, jgravelle-google, sbc100.
Herald added a project: LLVM.
When exceptions are repeatedly thrown in the middle of handling another
exception, we call `__clang_call_terminate` with the exception pointer
(i32) as an argument. But in case of foreign exceptions, we don't have
the pointer, so we call the function with 0. (This requires
`__clang_call_terminate` can deal with 0 argument, which will be done
later)
But previously the 0 argument was not added as a `i32.const 0` but an
immediate by mistake, causing the `call` instruction to take not an i32
but rather an exnref, because an `exnref` is left on top of the value
stack if `br_on_exn` is not taken.
block i32
br_on_exn 0, __cpp_exception
;; exnref is on top of stack now
i32.const 0 ;; This was missing!
call __clang_call_terminate
unreachable
end
call __clang_call_terminate ;; This takes i32 extracted by br_on_exn
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D65475
Files:
llvm/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp
llvm/test/CodeGen/WebAssembly/exception.ll
Index: llvm/test/CodeGen/WebAssembly/exception.ll
===================================================================
--- llvm/test/CodeGen/WebAssembly/exception.ll
+++ llvm/test/CodeGen/WebAssembly/exception.ll
@@ -138,7 +138,8 @@
; CHECK: catch
; CHECK: block i32
; CHECK: br_on_exn 0, __cpp_exception
-; CHECK: call __clang_call_terminate, 0
+; CHECK: i32.const ${{.*}}=, 0
+; CHECK: call __clang_call_terminate
; CHECK: unreachable
; CHECK: end_block
; CHECK: call __clang_call_terminate
Index: llvm/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp
===================================================================
--- llvm/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp
@@ -233,6 +233,7 @@
// it. The pseudo instruction will be deleted later.
bool WebAssemblyLateEHPrepare::addExceptionExtraction(MachineFunction &MF) {
const auto &TII = *MF.getSubtarget<WebAssemblySubtarget>().getInstrInfo();
+ MachineRegisterInfo &MRI = MF.getRegInfo();
auto *EHInfo = MF.getWasmEHFuncInfo();
SmallVector<MachineInstr *, 16> ExtractInstrs;
SmallVector<MachineInstr *, 8> ToDelete;
@@ -339,9 +340,11 @@
WebAssembly::ClangCallTerminateFn);
assert(ClangCallTerminateFn &&
"There is no __clang_call_terminate() function");
+ unsigned Reg = MRI.createVirtualRegister(&WebAssembly::I32RegClass);
+ BuildMI(ElseMBB, DL, TII.get(WebAssembly::CONST_I32), Reg).addImm(0);
BuildMI(ElseMBB, DL, TII.get(WebAssembly::CALL_VOID))
.addGlobalAddress(ClangCallTerminateFn)
- .addImm(0);
+ .addReg(Reg);
BuildMI(ElseMBB, DL, TII.get(WebAssembly::UNREACHABLE));
} else {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65475.212422.patch
Type: text/x-patch
Size: 1816 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190730/393755d2/attachment.bin>
More information about the llvm-commits
mailing list