diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp index c165542019532c..f09758a0d10334 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(&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(&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(&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 165f9e52e4d389..21959af25ca521 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 d08644f8529e09..cc6ab50c986b1a 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