blob: 1f002f9f2ae3a07e8aea66a356fd7057a89b940e [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 Ahn5ef4d5f2018-05-31 22:25:54 +000022; 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
Heejin Ahn4934f762018-06-25 01:07:11 +000030; CHECK-NEXT: rethrow
31define void @test_catch_rethrow() personality i8* bitcast (i32 (...)* @__gxx_wasm_personality_v0 to i8*) {
Heejin Ahn5ef4d5f2018-05-31 22:25:54 +000032entry:
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
Heejin Ahnac62b052017-06-30 00:43:15 +000057 ret void
58}
Heejin Ahn5ef4d5f2018-05-31 22:25:54 +000059
60; CHECK-LABEL: test_cleanup:
61; CHECK: call foo@FUNCTION
Heejin Ahn4934f762018-06-25 01:07:11 +000062; CHECK: catch_all
Heejin Ahn283e1c12018-08-14 22:14:51 +000063; CHECK: i32.call $push{{.+}}=, _ZN7CleanupD1Ev@FUNCTION
Heejin Ahn4934f762018-06-25 01:07:11 +000064; CHECK: rethrow
Heejin Ahn5ef4d5f2018-05-31 22:25:54 +000065define 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
Heejin Ahn4934f762018-06-25 01:07:11 +000081; - 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
Heejin Ahn5ef4d5f2018-05-31 22:25:54 +0000149declare void @foo()
Heejin Ahn5ef4d5f2018-05-31 22:25:54 +0000150declare 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*)
Heejin Ahn4934f762018-06-25 01:07:11 +0000158declare void @_ZSt9terminatev()
Heejin Ahn5ef4d5f2018-05-31 22:25:54 +0000159declare %struct.Cleanup* @_ZN7CleanupD1Ev(%struct.Cleanup* returned)