1 ; RUN: not --crash opt < %s -wasm-lower-em-ehsjlj -wasm-enable-eh -wasm-enable-sjlj -S 2>&1 | FileCheck %s
3 target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
4 target triple = "wasm32-unknown-unknown"
6 %struct.__jmp_buf_tag = type { [6 x i32], i32, [32 x i32] }
7 @_ZTIi = external constant ptr
9 define void @setjmp_within_catch() personality ptr @__gxx_wasm_personality_v0 {
11 %buf = alloca [1 x %struct.__jmp_buf_tag], align 16
13 to label %try.cont unwind label %catch.dispatch
15 catch.dispatch: ; preds = %entry
16 %0 = catchswitch within none [label %catch.start] unwind to caller
18 catch.start: ; preds = %catch.dispatch
19 %1 = catchpad within %0 [ptr @_ZTIi]
20 %2 = call ptr @llvm.wasm.get.exception(token %1)
21 %3 = call i32 @llvm.wasm.get.ehselector(token %1)
22 %4 = call i32 @llvm.eh.typeid.for(ptr @_ZTIi) #0
23 %matches = icmp eq i32 %3, %4
24 br i1 %matches, label %catch, label %rethrow
26 catch: ; preds = %catch.start
27 %5 = call ptr @__cxa_begin_catch(ptr %2) #0 [ "funclet"(token %1) ]
28 %6 = load i32, ptr %5, align 4
29 ; CHECK: LLVM ERROR: In function setjmp_within_catch: setjmp within a catch clause is not supported in Wasm EH
30 ; CHECK-NEXT: %call = invoke i32 @setjmp
31 %call = invoke i32 @setjmp(ptr noundef %buf) #2 [ "funclet"(token %1) ]
32 to label %invoke.cont1 unwind label %ehcleanup
34 invoke.cont1: ; preds = %catch
35 call void @__cxa_end_catch() #0 [ "funclet"(token %1) ]
36 catchret from %1 to label %try.cont
38 rethrow: ; preds = %catch.start
39 call void @llvm.wasm.rethrow() #1 [ "funclet"(token %1) ]
42 try.cont: ; preds = %entry, %invoke.cont1
45 ehcleanup: ; preds = %catch
46 %7 = cleanuppad within %1 []
47 call void @__cxa_end_catch() #0 [ "funclet"(token %7) ]
48 cleanupret from %7 unwind to caller
52 declare i32 @__gxx_wasm_personality_v0(...)
53 ; Function Attrs: nounwind
54 declare ptr @llvm.wasm.get.exception(token) #0
55 ; Function Attrs: nounwind
56 declare i32 @llvm.wasm.get.ehselector(token) #0
57 ; Function Attrs: nounwind
58 declare i32 @llvm.eh.typeid.for(ptr) #0
59 ; Function Attrs: noreturn
60 declare void @llvm.wasm.rethrow() #1
61 declare ptr @__cxa_begin_catch(ptr)
62 ; Function Attrs: returns_twice
63 declare i32 @setjmp(ptr noundef) #2
64 declare void @__cxa_end_catch()
66 attributes #0 = { nounwind }
67 attributes #1 = { noreturn }
68 attributes #2 = { returns_twice }