[llvm] 0ca2132 - [WebAssembly] Improve EH/SjLj error messages

Heejin Ahn via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 16 20:52:02 PDT 2022


Author: Heejin Ahn
Date: 2022-03-16T20:50:34-07:00
New Revision: 0ca21320675dc0997cafd9404de41e5e160cfa02

URL: https://github.com/llvm/llvm-project/commit/0ca21320675dc0997cafd9404de41e5e160cfa02
DIFF: https://github.com/llvm/llvm-project/commit/0ca21320675dc0997cafd9404de41e5e160cfa02.diff

LOG: [WebAssembly] Improve EH/SjLj error messages

This includes a function name and a relevant instruction in error
messages when possible, making them more helpful.

Reviewed By: dschuff

Differential Revision: https://reviews.llvm.org/D120678

Added: 
    

Modified: 
    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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
index c165542019532..f09758a0d1033 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
@@ -1314,9 +1314,14 @@ bool WebAssemblyLowerEmscriptenEHSjLj::runSjLjOnFunction(Function &F) {
     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 @@ void WebAssemblyLowerEmscriptenEHSjLj::handleLongjmpableCallsForEmscriptenSjLj(
   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;

diff  --git a/llvm/test/CodeGen/WebAssembly/wasm-eh-em-sjlj-error.ll b/llvm/test/CodeGen/WebAssembly/wasm-eh-em-sjlj-error.ll
index 165f9e52e4d38..21959af25ca52 100644
--- a/llvm/test/CodeGen/WebAssembly/wasm-eh-em-sjlj-error.ll
+++ b/llvm/test/CodeGen/WebAssembly/wasm-eh-em-sjlj-error.ll
@@ -50,4 +50,6 @@ attributes #0 = { returns_twice }
 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

diff  --git a/llvm/test/CodeGen/WebAssembly/wasm-eh-sjlj-setjmp-within-catch.ll b/llvm/test/CodeGen/WebAssembly/wasm-eh-sjlj-setjmp-within-catch.ll
index d08644f8529e0..cc6ab50c986b1 100644
--- a/llvm/test/CodeGen/WebAssembly/wasm-eh-sjlj-setjmp-within-catch.ll
+++ b/llvm/test/CodeGen/WebAssembly/wasm-eh-sjlj-setjmp-within-catch.ll
@@ -28,7 +28,8 @@ catch:                                            ; preds = %catch.start
   %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 @@ ehcleanup:                                        ; preds = %catch
   cleanupret from %8 unwind to caller
 }
 
-
 declare void @foo()
 declare i32 @__gxx_wasm_personality_v0(...)
 ; Function Attrs: nounwind


        


More information about the llvm-commits mailing list