blob: 2519ffcc78c0c0d8048658b64772a09bb8f00f45 [file] [log] [blame]
Wouter van Oortmerssena7be3752018-08-13 23:12:49 +00001; 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
Heejin Ahnac62b052017-06-30 00:43:15 +00003
4target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
Sam Clegga5908002018-05-10 17:49:11 +00005target triple = "wasm32-unknown-unknown"
Heejin Ahnac62b052017-06-30 00:43:15 +00006
Heejin Ahn5ef4d5f2018-05-31 22:25:54 +00007%struct.Cleanup = type { i8 }
Heejin Ahnac62b052017-06-30 00:43:15 +00008
Heejin Ahn5ef4d5f2018-05-31 22:25:54 +00009@_ZTIi = external constant i8*
10
11declare void @llvm.wasm.throw(i32, i8*)
12
13; CHECK-LABEL: test_throw:
Heejin Ahnac62b052017-06-30 00:43:15 +000014; CHECK-NEXT: i32.const $push0=, 0
15; CHECK-NEXT: throw 0, $pop0
Heejin Ahn5ef4d5f2018-05-31 22:25:54 +000016define void @test_throw() {
Heejin Ahnac62b052017-06-30 00:43:15 +000017 call void @llvm.wasm.throw(i32 0, i8* null)
18 ret void
19}
20
Heejin Ahn4934f762018-06-25 01:07:11 +000021; CHECK-LABEL: test_catch_rethrow:
Heejin Ahne76fa9e2018-08-16 23:50:59 +000022; CHECK: try
Heejin Ahn5ef4d5f2018-05-31 22:25:54 +000023; CHECK: call foo@FUNCTION
24; CHECK: i32.catch $push{{.+}}=, 0
25; CHECK-DAG: i32.store __wasm_lpad_context
26; CHECK-DAG: i32.store __wasm_lpad_context+4
27; CHECK: i32.call $push{{.+}}=, _Unwind_CallPersonality@FUNCTION
28; CHECK: i32.call $push{{.+}}=, __cxa_begin_catch@FUNCTION
29; CHECK: call __cxa_end_catch@FUNCTION
30; CHECK: call __cxa_rethrow@FUNCTION
Heejin Ahn4934f762018-06-25 01:07:11 +000031; CHECK-NEXT: rethrow
Heejin Ahne76fa9e2018-08-16 23:50:59 +000032; CHECK: end_try
Heejin Ahn4934f762018-06-25 01:07:11 +000033define void @test_catch_rethrow() personality i8* bitcast (i32 (...)* @__gxx_wasm_personality_v0 to i8*) {
Heejin Ahn5ef4d5f2018-05-31 22:25:54 +000034entry:
35 invoke void @foo()
36 to label %try.cont unwind label %catch.dispatch
37
38catch.dispatch: ; preds = %entry
39 %0 = catchswitch within none [label %catch.start] unwind to caller
40
41catch.start: ; preds = %catch.dispatch
42 %1 = catchpad within %0 [i8* bitcast (i8** @_ZTIi to i8*)]
43 %2 = call i8* @llvm.wasm.get.exception(token %1)
44 %3 = call i32 @llvm.wasm.get.ehselector(token %1)
45 %4 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*))
46 %matches = icmp eq i32 %3, %4
47 br i1 %matches, label %catch, label %rethrow
48
49catch: ; preds = %catch.start
50 %5 = call i8* @__cxa_begin_catch(i8* %2) [ "funclet"(token %1) ]
51 call void @__cxa_end_catch() [ "funclet"(token %1) ]
52 catchret from %1 to label %try.cont
53
54rethrow: ; preds = %catch.start
55 call void @__cxa_rethrow() [ "funclet"(token %1) ]
56 unreachable
57
58try.cont: ; preds = %entry, %catch
Heejin Ahnac62b052017-06-30 00:43:15 +000059 ret void
60}
Heejin Ahn5ef4d5f2018-05-31 22:25:54 +000061
62; CHECK-LABEL: test_cleanup:
Heejin Ahne76fa9e2018-08-16 23:50:59 +000063; CHECK: try
Heejin Ahn5ef4d5f2018-05-31 22:25:54 +000064; CHECK: call foo@FUNCTION
Heejin Ahn4934f762018-06-25 01:07:11 +000065; CHECK: catch_all
Heejin Ahn283e1c12018-08-14 22:14:51 +000066; CHECK: i32.call $push{{.+}}=, _ZN7CleanupD1Ev@FUNCTION
Heejin Ahn4934f762018-06-25 01:07:11 +000067; CHECK: rethrow
Heejin Ahne76fa9e2018-08-16 23:50:59 +000068; CHECK: end_try
Heejin Ahn5ef4d5f2018-05-31 22:25:54 +000069define void @test_cleanup() personality i8* bitcast (i32 (...)* @__gxx_wasm_personality_v0 to i8*) {
70entry:
71 %c = alloca %struct.Cleanup, align 1
72 invoke void @foo()
73 to label %invoke.cont unwind label %ehcleanup
74
75invoke.cont: ; preds = %entry
76 %call = call %struct.Cleanup* @_ZN7CleanupD1Ev(%struct.Cleanup* %c)
77 ret void
78
79ehcleanup: ; preds = %entry
80 %0 = cleanuppad within none []
81 %call1 = call %struct.Cleanup* @_ZN7CleanupD1Ev(%struct.Cleanup* %c) [ "funclet"(token %0) ]
82 cleanupret from %0 unwind to caller
83}
84
Heejin Ahn4934f762018-06-25 01:07:11 +000085; - Tests multple terminate pads are merged into one
86; - Tests a catch_all terminate pad is created after a catch terminate pad
87
88; CHECK-LABEL: test_terminatepad
89; CHECK: i32.catch
90; CHECK: call __clang_call_terminate@FUNCTION
91; CHECK: unreachable
92; CHECK: catch_all
93; CHECK: call _ZSt9terminatev@FUNCTION
94; CHECK-NOT: call __clang_call_terminate@FUNCTION
95define hidden i32 @test_terminatepad() personality i8* bitcast (i32 (...)* @__gxx_wasm_personality_v0 to i8*) {
96entry:
97 %c = alloca %struct.Cleanup, align 1
98 %c1 = alloca %struct.Cleanup, align 1
99 invoke void @foo()
100 to label %invoke.cont unwind label %ehcleanup
101
102invoke.cont: ; preds = %entry
103 %call = invoke %struct.Cleanup* @_ZN7CleanupD1Ev(%struct.Cleanup* %c1)
104 to label %try.cont unwind label %catch.dispatch
105
106ehcleanup: ; preds = %entry
107 %0 = cleanuppad within none []
108 %call4 = invoke %struct.Cleanup* @_ZN7CleanupD1Ev(%struct.Cleanup* %c1) [ "funclet"(token %0) ]
109 to label %invoke.cont3 unwind label %terminate
110
111invoke.cont3: ; preds = %ehcleanup
112 cleanupret from %0 unwind label %catch.dispatch
113
114catch.dispatch: ; preds = %invoke.cont3, %invoke.cont
115 %1 = catchswitch within none [label %catch.start] unwind label %ehcleanup7
116
117catch.start: ; preds = %catch.dispatch
118 %2 = catchpad within %1 [i8* null]
119 %3 = call i8* @llvm.wasm.get.exception(token %2)
120 %4 = call i32 @llvm.wasm.get.ehselector(token %2)
121 %5 = call i8* @__cxa_begin_catch(i8* %3) [ "funclet"(token %2) ]
122 invoke void @__cxa_end_catch() [ "funclet"(token %2) ]
123 to label %invoke.cont5 unwind label %ehcleanup7
124
125invoke.cont5: ; preds = %catch.start
126 catchret from %2 to label %try.cont
127
128try.cont: ; preds = %invoke.cont5, %invoke.cont
129 %call6 = call %struct.Cleanup* @_ZN7CleanupD1Ev(%struct.Cleanup* %c)
130 ret i32 0
131
132ehcleanup7: ; preds = %catch.start, %catch.dispatch
133 %6 = cleanuppad within none []
134 %call9 = invoke %struct.Cleanup* @_ZN7CleanupD1Ev(%struct.Cleanup* %c) [ "funclet"(token %6) ]
135 to label %invoke.cont8 unwind label %terminate10
136
137invoke.cont8: ; preds = %ehcleanup7
138 cleanupret from %6 unwind to caller
139
140terminate: ; preds = %ehcleanup
141 %7 = cleanuppad within %0 []
142 %8 = call i8* @llvm.wasm.get.exception(token %7)
143 call void @__clang_call_terminate(i8* %8) [ "funclet"(token %7) ]
144 unreachable
145
146terminate10: ; preds = %ehcleanup7
147 %9 = cleanuppad within %6 []
148 %10 = call i8* @llvm.wasm.get.exception(token %9)
149 call void @__clang_call_terminate(i8* %10) [ "funclet"(token %9) ]
150 unreachable
151}
152
Heejin Ahned5e06b2018-08-21 19:44:11 +0000153; Tests prologues and epilogues are not generated within EH scopes.
154; They should not be treated as funclets; BBs starting with a catch instruction
155; should not have a prologue, and BBs ending with a catchret/cleanupret should
156; not have an epilogue. This is separate from __stack_pointer restoring
157; instructions after a catch instruction.
158
159; CHECK-LABEL: test_no_prolog_epilog_in_ehpad
160; CHECK: try
161; CHECK: call foo@FUNCTION
162; CHECK: i32.catch
163; CHECK-NOT: get_global $push{{.+}}=, __stack_pointer@GLOBAL
164; CHECK: try
165; CHECK: call foo@FUNCTION
166; CHECK: catch_all
Heejin Ahn9cd7f882018-08-21 20:04:42 +0000167; CHECK-NOT: get_global $push{{.+}}=, __stack_pointer@GLOBAL
Heejin Ahned5e06b2018-08-21 19:44:11 +0000168; CHECK: call __cxa_end_catch@FUNCTION
169; CHECK-NOT: set_global __stack_pointer@GLOBAL, $pop{{.+}}
170; CHECK: end_try
171; CHECK-NOT: set_global __stack_pointer@GLOBAL, $pop{{.+}}
172; CHECK: end_try
173define void @test_no_prolog_epilog_in_ehpad() personality i8* bitcast (i32 (...)* @__gxx_wasm_personality_v0 to i8*) {
174entry:
175 %stack_var = alloca i32, align 4
176 call void @bar(i32* %stack_var)
177 invoke void @foo()
178 to label %try.cont unwind label %catch.dispatch
179
180catch.dispatch: ; preds = %entry
181 %0 = catchswitch within none [label %catch.start] unwind to caller
182
183catch.start: ; preds = %catch.dispatch
184 %1 = catchpad within %0 [i8* bitcast (i8** @_ZTIi to i8*)]
185 %2 = call i8* @llvm.wasm.get.exception(token %1)
186 %3 = call i32 @llvm.wasm.get.ehselector(token %1)
187 %4 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*))
188 %matches = icmp eq i32 %3, %4
189 br i1 %matches, label %catch, label %rethrow
190
191catch: ; preds = %catch.start
192 %5 = call i8* @__cxa_begin_catch(i8* %2) [ "funclet"(token %1) ]
193 %6 = bitcast i8* %5 to float*
194 %7 = load float, float* %6, align 4
195 invoke void @foo() [ "funclet"(token %1) ]
196 to label %invoke.cont1 unwind label %ehcleanup
197
198invoke.cont1: ; preds = %catch
199 call void @__cxa_end_catch() [ "funclet"(token %1) ]
200 catchret from %1 to label %try.cont
201
202rethrow: ; preds = %catch.start
203 call void @__cxa_rethrow() [ "funclet"(token %1) ]
204 unreachable
205
206try.cont: ; preds = %entry, %invoke.cont1
207 ret void
208
209ehcleanup: ; preds = %catch
210 %8 = cleanuppad within %1 []
211 call void @__cxa_end_catch() [ "funclet"(token %8) ]
212 cleanupret from %8 unwind to caller
213}
214
Heejin Ahn5ef4d5f2018-05-31 22:25:54 +0000215declare void @foo()
Heejin Ahned5e06b2018-08-21 19:44:11 +0000216declare void @bar(i32*)
Heejin Ahn5ef4d5f2018-05-31 22:25:54 +0000217declare i32 @__gxx_wasm_personality_v0(...)
218declare i8* @llvm.wasm.get.exception(token)
219declare i32 @llvm.wasm.get.ehselector(token)
220declare i32 @llvm.eh.typeid.for(i8*)
221declare i8* @__cxa_begin_catch(i8*)
222declare void @__cxa_end_catch()
223declare void @__cxa_rethrow()
224declare void @__clang_call_terminate(i8*)
Heejin Ahn4934f762018-06-25 01:07:11 +0000225declare void @_ZSt9terminatev()
Heejin Ahn5ef4d5f2018-05-31 22:25:54 +0000226declare %struct.Cleanup* @_ZN7CleanupD1Ev(%struct.Cleanup* returned)