• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: not llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -exception-model=wasm
2; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -exception-model=wasm -mattr=+exception-handling | FileCheck -allow-deprecated-dag-overlap %s
3
4target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
5target triple = "wasm32-unknown-unknown"
6
7%struct.Cleanup = type { i8 }
8
9@_ZTIi = external constant i8*
10
11declare void @llvm.wasm.throw(i32, i8*)
12
13; CHECK-LABEL: test_throw:
14; CHECK-NEXT: i32.const $push0=, 0
15; CHECK-NEXT: throw 0, $pop0
16define void @test_throw() {
17  call void @llvm.wasm.throw(i32 0, i8* null)
18  ret void
19}
20
21; CHECK-LABEL: test_catch_rethrow:
22; CHECK:   call      foo@FUNCTION
23; CHECK:   i32.catch     $push{{.+}}=, 0
24; CHECK-DAG:   i32.store  __wasm_lpad_context
25; CHECK-DAG:   i32.store  __wasm_lpad_context+4
26; CHECK:   i32.call  $push{{.+}}=, _Unwind_CallPersonality@FUNCTION
27; CHECK:   i32.call  $push{{.+}}=, __cxa_begin_catch@FUNCTION
28; CHECK:   call      __cxa_end_catch@FUNCTION
29; CHECK:   call      __cxa_rethrow@FUNCTION
30; CHECK-NEXT:   rethrow
31define void @test_catch_rethrow() personality i8* bitcast (i32 (...)* @__gxx_wasm_personality_v0 to i8*) {
32entry:
33  invoke void @foo()
34          to label %try.cont unwind label %catch.dispatch
35
36catch.dispatch:                                   ; preds = %entry
37  %0 = catchswitch within none [label %catch.start] unwind to caller
38
39catch.start:                                      ; preds = %catch.dispatch
40  %1 = catchpad within %0 [i8* bitcast (i8** @_ZTIi to i8*)]
41  %2 = call i8* @llvm.wasm.get.exception(token %1)
42  %3 = call i32 @llvm.wasm.get.ehselector(token %1)
43  %4 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*))
44  %matches = icmp eq i32 %3, %4
45  br i1 %matches, label %catch, label %rethrow
46
47catch:                                            ; preds = %catch.start
48  %5 = call i8* @__cxa_begin_catch(i8* %2) [ "funclet"(token %1) ]
49  call void @__cxa_end_catch() [ "funclet"(token %1) ]
50  catchret from %1 to label %try.cont
51
52rethrow:                                          ; preds = %catch.start
53  call void @__cxa_rethrow() [ "funclet"(token %1) ]
54  unreachable
55
56try.cont:                                         ; preds = %entry, %catch
57  ret void
58}
59
60; CHECK-LABEL: test_cleanup:
61; CHECK:   call      foo@FUNCTION
62; CHECK:   catch_all
63; CHECK:   i32.call  $push20=, _ZN7CleanupD1Ev@FUNCTION
64; CHECK:   rethrow
65define void @test_cleanup() personality i8* bitcast (i32 (...)* @__gxx_wasm_personality_v0 to i8*) {
66entry:
67  %c = alloca %struct.Cleanup, align 1
68  invoke void @foo()
69          to label %invoke.cont unwind label %ehcleanup
70
71invoke.cont:                                      ; preds = %entry
72  %call = call %struct.Cleanup* @_ZN7CleanupD1Ev(%struct.Cleanup* %c)
73  ret void
74
75ehcleanup:                                        ; preds = %entry
76  %0 = cleanuppad within none []
77  %call1 = call %struct.Cleanup* @_ZN7CleanupD1Ev(%struct.Cleanup* %c) [ "funclet"(token %0) ]
78  cleanupret from %0 unwind to caller
79}
80
81; - Tests multple terminate pads are merged into one
82; - Tests a catch_all terminate pad is created after a catch terminate pad
83
84; CHECK-LABEL: test_terminatepad
85; CHECK:  i32.catch
86; CHECK:  call      __clang_call_terminate@FUNCTION
87; CHECK:  unreachable
88; CHECK:  catch_all
89; CHECK:  call      _ZSt9terminatev@FUNCTION
90; CHECK-NOT:  call      __clang_call_terminate@FUNCTION
91define hidden i32 @test_terminatepad() personality i8* bitcast (i32 (...)* @__gxx_wasm_personality_v0 to i8*) {
92entry:
93  %c = alloca %struct.Cleanup, align 1
94  %c1 = alloca %struct.Cleanup, align 1
95  invoke void @foo()
96          to label %invoke.cont unwind label %ehcleanup
97
98invoke.cont:                                      ; preds = %entry
99  %call = invoke %struct.Cleanup* @_ZN7CleanupD1Ev(%struct.Cleanup* %c1)
100          to label %try.cont unwind label %catch.dispatch
101
102ehcleanup:                                        ; preds = %entry
103  %0 = cleanuppad within none []
104  %call4 = invoke %struct.Cleanup* @_ZN7CleanupD1Ev(%struct.Cleanup* %c1) [ "funclet"(token %0) ]
105          to label %invoke.cont3 unwind label %terminate
106
107invoke.cont3:                                     ; preds = %ehcleanup
108  cleanupret from %0 unwind label %catch.dispatch
109
110catch.dispatch:                                   ; preds = %invoke.cont3, %invoke.cont
111  %1 = catchswitch within none [label %catch.start] unwind label %ehcleanup7
112
113catch.start:                                      ; preds = %catch.dispatch
114  %2 = catchpad within %1 [i8* null]
115  %3 = call i8* @llvm.wasm.get.exception(token %2)
116  %4 = call i32 @llvm.wasm.get.ehselector(token %2)
117  %5 = call i8* @__cxa_begin_catch(i8* %3) [ "funclet"(token %2) ]
118  invoke void @__cxa_end_catch() [ "funclet"(token %2) ]
119          to label %invoke.cont5 unwind label %ehcleanup7
120
121invoke.cont5:                                     ; preds = %catch.start
122  catchret from %2 to label %try.cont
123
124try.cont:                                         ; preds = %invoke.cont5, %invoke.cont
125  %call6 = call %struct.Cleanup* @_ZN7CleanupD1Ev(%struct.Cleanup* %c)
126  ret i32 0
127
128ehcleanup7:                                       ; preds = %catch.start, %catch.dispatch
129  %6 = cleanuppad within none []
130  %call9 = invoke %struct.Cleanup* @_ZN7CleanupD1Ev(%struct.Cleanup* %c) [ "funclet"(token %6) ]
131          to label %invoke.cont8 unwind label %terminate10
132
133invoke.cont8:                                     ; preds = %ehcleanup7
134  cleanupret from %6 unwind to caller
135
136terminate:                                        ; preds = %ehcleanup
137  %7 = cleanuppad within %0 []
138  %8 = call i8* @llvm.wasm.get.exception(token %7)
139  call void @__clang_call_terminate(i8* %8) [ "funclet"(token %7) ]
140  unreachable
141
142terminate10:                                      ; preds = %ehcleanup7
143  %9 = cleanuppad within %6 []
144  %10 = call i8* @llvm.wasm.get.exception(token %9)
145  call void @__clang_call_terminate(i8* %10) [ "funclet"(token %9) ]
146  unreachable
147}
148
149declare void @foo()
150declare i32 @__gxx_wasm_personality_v0(...)
151declare i8* @llvm.wasm.get.exception(token)
152declare i32 @llvm.wasm.get.ehselector(token)
153declare i32 @llvm.eh.typeid.for(i8*)
154declare i8* @__cxa_begin_catch(i8*)
155declare void @__cxa_end_catch()
156declare void @__cxa_rethrow()
157declare void @__clang_call_terminate(i8*)
158declare void @_ZSt9terminatev()
159declare %struct.Cleanup* @_ZN7CleanupD1Ev(%struct.Cleanup* returned)
160