[PATCH] D120678: [WebAssembly] Improve EH/SjLj error messages
Heejin Ahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 28 13:27:16 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.
This includes a function name and a relevant instruction in error
messages when possible, making them more helpful.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D120678
Files:
llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
llvm/test/CodeGen/WebAssembly/wasm-eh-em-sjlj-error.ll
llvm/test/CodeGen/WebAssembly/wasm-eh-sjlj-setjmp-within-catch.ll
Index: llvm/test/CodeGen/WebAssembly/wasm-eh-sjlj-setjmp-within-catch.ll
===================================================================
--- llvm/test/CodeGen/WebAssembly/wasm-eh-sjlj-setjmp-within-catch.ll
+++ llvm/test/CodeGen/WebAssembly/wasm-eh-sjlj-setjmp-within-catch.ll
@@ -28,7 +28,8 @@
%6 = bitcast i8* %5 to i32*
%7 = load i32, i32* %6, align 4
%arraydecay = getelementptr inbounds [1 x %struct.__jmp_buf_tag], [1 x %struct.__jmp_buf_tag]* %buf, i32 0, i32 0
-; CHECK: LLVM ERROR: setjmp within a catch clause is not supported in Wasm EH
+; CHECK: LLVM ERROR: In function setjmp_within_catch: setjmp within a catch clause is not supported in Wasm EH
+; CHECK-NEXT: %call = invoke i32 @setjmp
%call = invoke i32 @setjmp(%struct.__jmp_buf_tag* noundef %arraydecay) #2 [ "funclet"(token %1) ]
to label %invoke.cont1 unwind label %ehcleanup
@@ -49,7 +50,6 @@
cleanupret from %8 unwind to caller
}
-
declare void @foo()
declare i32 @__gxx_wasm_personality_v0(...)
; Function Attrs: nounwind
Index: llvm/test/CodeGen/WebAssembly/wasm-eh-em-sjlj-error.ll
===================================================================
--- llvm/test/CodeGen/WebAssembly/wasm-eh-em-sjlj-error.ll
+++ llvm/test/CodeGen/WebAssembly/wasm-eh-em-sjlj-error.ll
@@ -50,4 +50,6 @@
attributes #1 = { noreturn }
attributes #2 = { nounwind }
-; CHECK: LLVM ERROR: When using Wasm EH with Emscripten SjLj, there is a restriction that `setjmp` function call and exception cannot be used within the same function
+; CHECK: LLVM ERROR: In function wasm_eh_emscripten_sjlj_error: When using Wasm EH with Emscripten SjLj, there is a restriction that `setjmp` function call and exception cannot be used within the same function
+; CHECK-NEXT: invoke void @foo()
+; CHECK-NEXT: to label %try.cont unwind label %catch.dispatch
Index: llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
===================================================================
--- llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
@@ -1314,9 +1314,14 @@
BasicBlock *BB = CB->getParent();
if (BB->getParent() != &F) // in other function
continue;
- if (CB->getOperandBundle(LLVMContext::OB_funclet))
- report_fatal_error(
- "setjmp within a catch clause is not supported in Wasm EH");
+ if (CB->getOperandBundle(LLVMContext::OB_funclet)) {
+ std::string S;
+ raw_string_ostream SS(S);
+ SS << "In function " + F.getName() +
+ ": setjmp within a catch clause is not supported in Wasm EH:\n";
+ SS << *CB;
+ report_fatal_error(StringRef(SS.str()));
+ }
CallInst *CI = nullptr;
// setjmp cannot throw. So if it is an invoke, lower it to a call
@@ -1492,10 +1497,16 @@
for (unsigned I = 0; I < BBs.size(); I++) {
BasicBlock *BB = BBs[I];
for (Instruction &I : *BB) {
- if (isa<InvokeInst>(&I))
- report_fatal_error("When using Wasm EH with Emscripten SjLj, there is "
- "a restriction that `setjmp` function call and "
- "exception cannot be used within the same function");
+ if (isa<InvokeInst>(&I)) {
+ std::string S;
+ raw_string_ostream SS(S);
+ SS << "In function " << F.getName()
+ << ": When using Wasm EH with Emscripten SjLj, there is a "
+ "restriction that `setjmp` function call and exception cannot be "
+ "used within the same function:\n";
+ SS << I;
+ report_fatal_error(StringRef(SS.str()));
+ }
auto *CI = dyn_cast<CallInst>(&I);
if (!CI)
continue;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120678.411876.patch
Type: text/x-patch
Size: 3729 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220228/593121a0/attachment.bin>
More information about the llvm-commits
mailing list