mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-04-01 12:43:47 +00:00
[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
This commit is contained in:
parent
57f72ad91d
commit
0ca2132067
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user