[PATCH] D117943: [WebAssembly] Treat __cxa_end_catch not longjmpable in Emscripten SjLj
Heejin Ahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 21 22:44:21 PST 2022
aheejin created this revision.
aheejin added a reviewer: dschuff.
Herald added subscribers: wingo, ecnelises, sunfish, hiraditya, jgravelle-google, sbc100.
aheejin requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
In D117610 <https://reviews.llvm.org/D117610> we maded `__cxa_end_catch` longjmpable even though it was not
to make unwind destination relationships correct. But we only need to do
this in Wasm SjLj, and doing this in Emscripten SjLj does not make the
code incorrect but add unnecessary invokes. This CL treats
`__cxa_end_catch` longjmpable only in Wasm SjLj.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D117943
Files:
llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
llvm/test/CodeGen/WebAssembly/lower-em-ehsjlj.ll
Index: llvm/test/CodeGen/WebAssembly/lower-em-ehsjlj.ll
===================================================================
--- llvm/test/CodeGen/WebAssembly/lower-em-ehsjlj.ll
+++ llvm/test/CodeGen/WebAssembly/lower-em-ehsjlj.ll
@@ -33,21 +33,23 @@
; CHECK-NEXT: %[[CMP:.*]] = icmp eq i32 %__THREW__.val, 1
; CHECK-NEXT: br i1 %[[CMP]], label %lpad, label %try.cont
-; longjmp checking part
-; CHECK: if.then1:
-; CHECK: call i32 @testSetjmp
-
+; CHECK: lpad:
lpad: ; preds = %entry
%0 = landingpad { i8*, i32 }
catch i8* null
%1 = extractvalue { i8*, i32 } %0, 0
%2 = extractvalue { i8*, i32 } %0, 1
+; CHECK-NOT: call {{.*}} void @__invoke_void(void ()* @__cxa_end_catch)
%3 = call i8* @__cxa_begin_catch(i8* %1) #2
call void @__cxa_end_catch()
br label %try.cont
try.cont: ; preds = %lpad, %entry
ret void
+
+; longjmp checking part
+; CHECK: if.then1:
+; CHECK: call i32 @testSetjmp
}
; @foo can either throw an exception or longjmp. Because this function doesn't
Index: llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
===================================================================
--- llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
@@ -630,9 +630,9 @@
// Exception-catching related functions
//
- // We intentionally excluded __cxa_end_catch here even though it surely cannot
- // longjmp, in order to maintain the unwind relationship from all existing
- // catchpads (and calls within them) to catch.dispatch.longjmp.
+ // We intentionally treat __cxa_end_catch longjmpable in Wasm SjLj even though
+ // it surely cannot longjmp, in order to maintain the unwind relationship from
+ // all existing catchpads (and calls within them) to catch.dispatch.longjmp.
//
// In Wasm EH + Wasm SjLj, we
// 1. Make all catchswitch and cleanuppad that unwind to caller unwind to
@@ -663,6 +663,8 @@
//
// The comment block in findWasmUnwindDestinations() in
// SelectionDAGBuilder.cpp is addressing a similar problem.
+ if (CalleeName == "__cxa_end_catch")
+ return WebAssembly::WasmEnableSjLj;
if (CalleeName == "__cxa_begin_catch" ||
CalleeName == "__cxa_allocate_exception" || CalleeName == "__cxa_throw" ||
CalleeName == "__clang_call_terminate")
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117943.402176.patch
Type: text/x-patch
Size: 2455 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220122/5d301261/attachment-0001.bin>
More information about the llvm-commits
mailing list