Wouter van Oortmerssen | 8a9cb24 | 2018-08-27 15:45:51 +0000 | [diff] [blame] | 1 | ; RUN: not llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-keep-registers -exception-model=wasm |
Heejin Ahn | 095796a | 2018-11-16 00:47:18 +0000 | [diff] [blame^] | 2 | ; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-keep-registers -exception-model=wasm -mattr=+exception-handling -verify-machineinstrs | FileCheck -allow-deprecated-dag-overlap %s |
Heejin Ahn | 5b023e0 | 2018-11-02 18:38:52 +0000 | [diff] [blame] | 3 | ; RUN: llc < %s -disable-wasm-fallthrough-return-opt -wasm-keep-registers -exception-model=wasm -mattr=+exception-handling |
Heejin Ahn | ac62b05 | 2017-06-30 00:43:15 +0000 | [diff] [blame] | 4 | |
| 5 | target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" |
Sam Clegg | a590800 | 2018-05-10 17:49:11 +0000 | [diff] [blame] | 6 | target triple = "wasm32-unknown-unknown" |
Heejin Ahn | ac62b05 | 2017-06-30 00:43:15 +0000 | [diff] [blame] | 7 | |
Heejin Ahn | 5ef4d5f | 2018-05-31 22:25:54 +0000 | [diff] [blame] | 8 | %struct.Cleanup = type { i8 } |
Heejin Ahn | ac62b05 | 2017-06-30 00:43:15 +0000 | [diff] [blame] | 9 | |
Heejin Ahn | 5ef4d5f | 2018-05-31 22:25:54 +0000 | [diff] [blame] | 10 | @_ZTIi = external constant i8* |
| 11 | |
| 12 | declare void @llvm.wasm.throw(i32, i8*) |
| 13 | |
| 14 | ; CHECK-LABEL: test_throw: |
Heejin Ahn | 095796a | 2018-11-16 00:47:18 +0000 | [diff] [blame^] | 15 | ; CHECK: get_local $push0=, 0 |
Heejin Ahn | da419bd | 2018-11-14 02:46:21 +0000 | [diff] [blame] | 16 | ; CHECK-NEXT: throw __cpp_exception@EVENT, $pop0 |
Heejin Ahn | 095796a | 2018-11-16 00:47:18 +0000 | [diff] [blame^] | 17 | ; CHECK-NOT: unreachable |
| 18 | define void @test_throw(i8* %p) { |
| 19 | call void @llvm.wasm.throw(i32 0, i8* %p) |
Heejin Ahn | ac62b05 | 2017-06-30 00:43:15 +0000 | [diff] [blame] | 20 | ret void |
| 21 | } |
| 22 | |
Heejin Ahn | 4934f76 | 2018-06-25 01:07:11 +0000 | [diff] [blame] | 23 | ; CHECK-LABEL: test_catch_rethrow: |
Heejin Ahn | 78d1910 | 2018-08-21 21:23:07 +0000 | [diff] [blame] | 24 | ; CHECK: get_global $push{{.+}}=, __stack_pointer@GLOBAL |
Heejin Ahn | e76fa9e | 2018-08-16 23:50:59 +0000 | [diff] [blame] | 25 | ; CHECK: try |
Heejin Ahn | 5ef4d5f | 2018-05-31 22:25:54 +0000 | [diff] [blame] | 26 | ; CHECK: call foo@FUNCTION |
| 27 | ; CHECK: i32.catch $push{{.+}}=, 0 |
Heejin Ahn | 78d1910 | 2018-08-21 21:23:07 +0000 | [diff] [blame] | 28 | ; CHECK: set_global __stack_pointer@GLOBAL |
Heejin Ahn | 5ef4d5f | 2018-05-31 22:25:54 +0000 | [diff] [blame] | 29 | ; CHECK-DAG: i32.store __wasm_lpad_context |
| 30 | ; CHECK-DAG: i32.store __wasm_lpad_context+4 |
| 31 | ; CHECK: i32.call $push{{.+}}=, _Unwind_CallPersonality@FUNCTION |
| 32 | ; CHECK: i32.call $push{{.+}}=, __cxa_begin_catch@FUNCTION |
| 33 | ; CHECK: call __cxa_end_catch@FUNCTION |
| 34 | ; CHECK: call __cxa_rethrow@FUNCTION |
Heejin Ahn | 4934f76 | 2018-06-25 01:07:11 +0000 | [diff] [blame] | 35 | ; CHECK-NEXT: rethrow |
Heejin Ahn | e76fa9e | 2018-08-16 23:50:59 +0000 | [diff] [blame] | 36 | ; CHECK: end_try |
Heejin Ahn | 4934f76 | 2018-06-25 01:07:11 +0000 | [diff] [blame] | 37 | define void @test_catch_rethrow() personality i8* bitcast (i32 (...)* @__gxx_wasm_personality_v0 to i8*) { |
Heejin Ahn | 5ef4d5f | 2018-05-31 22:25:54 +0000 | [diff] [blame] | 38 | entry: |
| 39 | invoke void @foo() |
| 40 | to label %try.cont unwind label %catch.dispatch |
| 41 | |
| 42 | catch.dispatch: ; preds = %entry |
| 43 | %0 = catchswitch within none [label %catch.start] unwind to caller |
| 44 | |
| 45 | catch.start: ; preds = %catch.dispatch |
| 46 | %1 = catchpad within %0 [i8* bitcast (i8** @_ZTIi to i8*)] |
| 47 | %2 = call i8* @llvm.wasm.get.exception(token %1) |
| 48 | %3 = call i32 @llvm.wasm.get.ehselector(token %1) |
| 49 | %4 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) |
| 50 | %matches = icmp eq i32 %3, %4 |
| 51 | br i1 %matches, label %catch, label %rethrow |
| 52 | |
| 53 | catch: ; preds = %catch.start |
| 54 | %5 = call i8* @__cxa_begin_catch(i8* %2) [ "funclet"(token %1) ] |
| 55 | call void @__cxa_end_catch() [ "funclet"(token %1) ] |
| 56 | catchret from %1 to label %try.cont |
| 57 | |
| 58 | rethrow: ; preds = %catch.start |
| 59 | call void @__cxa_rethrow() [ "funclet"(token %1) ] |
| 60 | unreachable |
| 61 | |
| 62 | try.cont: ; preds = %entry, %catch |
Heejin Ahn | ac62b05 | 2017-06-30 00:43:15 +0000 | [diff] [blame] | 63 | ret void |
| 64 | } |
Heejin Ahn | 5ef4d5f | 2018-05-31 22:25:54 +0000 | [diff] [blame] | 65 | |
| 66 | ; CHECK-LABEL: test_cleanup: |
Heejin Ahn | e76fa9e | 2018-08-16 23:50:59 +0000 | [diff] [blame] | 67 | ; CHECK: try |
Heejin Ahn | 5ef4d5f | 2018-05-31 22:25:54 +0000 | [diff] [blame] | 68 | ; CHECK: call foo@FUNCTION |
Heejin Ahn | 4934f76 | 2018-06-25 01:07:11 +0000 | [diff] [blame] | 69 | ; CHECK: catch_all |
Heejin Ahn | 78d1910 | 2018-08-21 21:23:07 +0000 | [diff] [blame] | 70 | ; CHECK: set_global __stack_pointer@GLOBAL |
Heejin Ahn | 283e1c1 | 2018-08-14 22:14:51 +0000 | [diff] [blame] | 71 | ; CHECK: i32.call $push{{.+}}=, _ZN7CleanupD1Ev@FUNCTION |
Heejin Ahn | 4934f76 | 2018-06-25 01:07:11 +0000 | [diff] [blame] | 72 | ; CHECK: rethrow |
Heejin Ahn | e76fa9e | 2018-08-16 23:50:59 +0000 | [diff] [blame] | 73 | ; CHECK: end_try |
Heejin Ahn | 5ef4d5f | 2018-05-31 22:25:54 +0000 | [diff] [blame] | 74 | define void @test_cleanup() personality i8* bitcast (i32 (...)* @__gxx_wasm_personality_v0 to i8*) { |
| 75 | entry: |
| 76 | %c = alloca %struct.Cleanup, align 1 |
| 77 | invoke void @foo() |
| 78 | to label %invoke.cont unwind label %ehcleanup |
| 79 | |
| 80 | invoke.cont: ; preds = %entry |
| 81 | %call = call %struct.Cleanup* @_ZN7CleanupD1Ev(%struct.Cleanup* %c) |
| 82 | ret void |
| 83 | |
| 84 | ehcleanup: ; preds = %entry |
| 85 | %0 = cleanuppad within none [] |
| 86 | %call1 = call %struct.Cleanup* @_ZN7CleanupD1Ev(%struct.Cleanup* %c) [ "funclet"(token %0) ] |
| 87 | cleanupret from %0 unwind to caller |
| 88 | } |
| 89 | |
Heejin Ahn | 4934f76 | 2018-06-25 01:07:11 +0000 | [diff] [blame] | 90 | ; - Tests multple terminate pads are merged into one |
| 91 | ; - Tests a catch_all terminate pad is created after a catch terminate pad |
| 92 | |
| 93 | ; CHECK-LABEL: test_terminatepad |
| 94 | ; CHECK: i32.catch |
| 95 | ; CHECK: call __clang_call_terminate@FUNCTION |
| 96 | ; CHECK: unreachable |
| 97 | ; CHECK: catch_all |
| 98 | ; CHECK: call _ZSt9terminatev@FUNCTION |
| 99 | ; CHECK-NOT: call __clang_call_terminate@FUNCTION |
| 100 | define hidden i32 @test_terminatepad() personality i8* bitcast (i32 (...)* @__gxx_wasm_personality_v0 to i8*) { |
| 101 | entry: |
| 102 | %c = alloca %struct.Cleanup, align 1 |
| 103 | %c1 = alloca %struct.Cleanup, align 1 |
| 104 | invoke void @foo() |
| 105 | to label %invoke.cont unwind label %ehcleanup |
| 106 | |
| 107 | invoke.cont: ; preds = %entry |
| 108 | %call = invoke %struct.Cleanup* @_ZN7CleanupD1Ev(%struct.Cleanup* %c1) |
| 109 | to label %try.cont unwind label %catch.dispatch |
| 110 | |
| 111 | ehcleanup: ; preds = %entry |
| 112 | %0 = cleanuppad within none [] |
| 113 | %call4 = invoke %struct.Cleanup* @_ZN7CleanupD1Ev(%struct.Cleanup* %c1) [ "funclet"(token %0) ] |
| 114 | to label %invoke.cont3 unwind label %terminate |
| 115 | |
| 116 | invoke.cont3: ; preds = %ehcleanup |
| 117 | cleanupret from %0 unwind label %catch.dispatch |
| 118 | |
| 119 | catch.dispatch: ; preds = %invoke.cont3, %invoke.cont |
| 120 | %1 = catchswitch within none [label %catch.start] unwind label %ehcleanup7 |
| 121 | |
| 122 | catch.start: ; preds = %catch.dispatch |
| 123 | %2 = catchpad within %1 [i8* null] |
| 124 | %3 = call i8* @llvm.wasm.get.exception(token %2) |
| 125 | %4 = call i32 @llvm.wasm.get.ehselector(token %2) |
| 126 | %5 = call i8* @__cxa_begin_catch(i8* %3) [ "funclet"(token %2) ] |
| 127 | invoke void @__cxa_end_catch() [ "funclet"(token %2) ] |
| 128 | to label %invoke.cont5 unwind label %ehcleanup7 |
| 129 | |
| 130 | invoke.cont5: ; preds = %catch.start |
| 131 | catchret from %2 to label %try.cont |
| 132 | |
| 133 | try.cont: ; preds = %invoke.cont5, %invoke.cont |
| 134 | %call6 = call %struct.Cleanup* @_ZN7CleanupD1Ev(%struct.Cleanup* %c) |
| 135 | ret i32 0 |
| 136 | |
| 137 | ehcleanup7: ; preds = %catch.start, %catch.dispatch |
| 138 | %6 = cleanuppad within none [] |
| 139 | %call9 = invoke %struct.Cleanup* @_ZN7CleanupD1Ev(%struct.Cleanup* %c) [ "funclet"(token %6) ] |
| 140 | to label %invoke.cont8 unwind label %terminate10 |
| 141 | |
| 142 | invoke.cont8: ; preds = %ehcleanup7 |
| 143 | cleanupret from %6 unwind to caller |
| 144 | |
| 145 | terminate: ; preds = %ehcleanup |
| 146 | %7 = cleanuppad within %0 [] |
| 147 | %8 = call i8* @llvm.wasm.get.exception(token %7) |
| 148 | call void @__clang_call_terminate(i8* %8) [ "funclet"(token %7) ] |
| 149 | unreachable |
| 150 | |
| 151 | terminate10: ; preds = %ehcleanup7 |
| 152 | %9 = cleanuppad within %6 [] |
| 153 | %10 = call i8* @llvm.wasm.get.exception(token %9) |
| 154 | call void @__clang_call_terminate(i8* %10) [ "funclet"(token %9) ] |
| 155 | unreachable |
| 156 | } |
| 157 | |
Heejin Ahn | ed5e06b | 2018-08-21 19:44:11 +0000 | [diff] [blame] | 158 | ; Tests prologues and epilogues are not generated within EH scopes. |
| 159 | ; They should not be treated as funclets; BBs starting with a catch instruction |
| 160 | ; should not have a prologue, and BBs ending with a catchret/cleanupret should |
| 161 | ; not have an epilogue. This is separate from __stack_pointer restoring |
| 162 | ; instructions after a catch instruction. |
| 163 | |
| 164 | ; CHECK-LABEL: test_no_prolog_epilog_in_ehpad |
| 165 | ; CHECK: try |
| 166 | ; CHECK: call foo@FUNCTION |
| 167 | ; CHECK: i32.catch |
| 168 | ; CHECK-NOT: get_global $push{{.+}}=, __stack_pointer@GLOBAL |
Heejin Ahn | 78d1910 | 2018-08-21 21:23:07 +0000 | [diff] [blame] | 169 | ; CHECK: set_global __stack_pointer@GLOBAL |
Heejin Ahn | ed5e06b | 2018-08-21 19:44:11 +0000 | [diff] [blame] | 170 | ; CHECK: try |
| 171 | ; CHECK: call foo@FUNCTION |
| 172 | ; CHECK: catch_all |
Heejin Ahn | 9cd7f88 | 2018-08-21 20:04:42 +0000 | [diff] [blame] | 173 | ; CHECK-NOT: get_global $push{{.+}}=, __stack_pointer@GLOBAL |
Heejin Ahn | 78d1910 | 2018-08-21 21:23:07 +0000 | [diff] [blame] | 174 | ; CHECK: set_global __stack_pointer@GLOBAL |
Heejin Ahn | ed5e06b | 2018-08-21 19:44:11 +0000 | [diff] [blame] | 175 | ; CHECK: call __cxa_end_catch@FUNCTION |
| 176 | ; CHECK-NOT: set_global __stack_pointer@GLOBAL, $pop{{.+}} |
| 177 | ; CHECK: end_try |
| 178 | ; CHECK-NOT: set_global __stack_pointer@GLOBAL, $pop{{.+}} |
| 179 | ; CHECK: end_try |
| 180 | define void @test_no_prolog_epilog_in_ehpad() personality i8* bitcast (i32 (...)* @__gxx_wasm_personality_v0 to i8*) { |
| 181 | entry: |
| 182 | %stack_var = alloca i32, align 4 |
| 183 | call void @bar(i32* %stack_var) |
| 184 | invoke void @foo() |
| 185 | to label %try.cont unwind label %catch.dispatch |
| 186 | |
| 187 | catch.dispatch: ; preds = %entry |
| 188 | %0 = catchswitch within none [label %catch.start] unwind to caller |
| 189 | |
| 190 | catch.start: ; preds = %catch.dispatch |
| 191 | %1 = catchpad within %0 [i8* bitcast (i8** @_ZTIi to i8*)] |
| 192 | %2 = call i8* @llvm.wasm.get.exception(token %1) |
| 193 | %3 = call i32 @llvm.wasm.get.ehselector(token %1) |
| 194 | %4 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) |
| 195 | %matches = icmp eq i32 %3, %4 |
| 196 | br i1 %matches, label %catch, label %rethrow |
| 197 | |
| 198 | catch: ; preds = %catch.start |
| 199 | %5 = call i8* @__cxa_begin_catch(i8* %2) [ "funclet"(token %1) ] |
| 200 | %6 = bitcast i8* %5 to float* |
| 201 | %7 = load float, float* %6, align 4 |
| 202 | invoke void @foo() [ "funclet"(token %1) ] |
| 203 | to label %invoke.cont1 unwind label %ehcleanup |
| 204 | |
| 205 | invoke.cont1: ; preds = %catch |
| 206 | call void @__cxa_end_catch() [ "funclet"(token %1) ] |
| 207 | catchret from %1 to label %try.cont |
| 208 | |
| 209 | rethrow: ; preds = %catch.start |
| 210 | call void @__cxa_rethrow() [ "funclet"(token %1) ] |
| 211 | unreachable |
| 212 | |
| 213 | try.cont: ; preds = %entry, %invoke.cont1 |
| 214 | ret void |
| 215 | |
| 216 | ehcleanup: ; preds = %catch |
| 217 | %8 = cleanuppad within %1 [] |
| 218 | call void @__cxa_end_catch() [ "funclet"(token %8) ] |
| 219 | cleanupret from %8 unwind to caller |
| 220 | } |
| 221 | |
Heejin Ahn | 972fc35 | 2018-08-22 21:13:49 +0000 | [diff] [blame] | 222 | ; When a function does not have stack-allocated objects, it does not need to |
| 223 | ; store SP back to __stack_pointer global at the epilog. |
| 224 | |
| 225 | ; CHECK-LABEL: no_sp_writeback |
| 226 | ; CHECK: try |
| 227 | ; CHECK: call foo@FUNCTION |
| 228 | ; CHECK: end_try |
| 229 | ; CHECK-NOT: set_global __stack_pointer@GLOBAL |
| 230 | ; CHECK: return |
| 231 | define void @no_sp_writeback() personality i8* bitcast (i32 (...)* @__gxx_wasm_personality_v0 to i8*) { |
| 232 | entry: |
| 233 | invoke void @foo() |
| 234 | to label %try.cont unwind label %catch.dispatch |
| 235 | |
| 236 | catch.dispatch: ; preds = %entry |
| 237 | %0 = catchswitch within none [label %catch.start] unwind to caller |
| 238 | |
| 239 | catch.start: ; preds = %catch.dispatch |
| 240 | %1 = catchpad within %0 [i8* null] |
| 241 | %2 = call i8* @llvm.wasm.get.exception(token %1) |
| 242 | %3 = call i32 @llvm.wasm.get.ehselector(token %1) |
| 243 | %4 = call i8* @__cxa_begin_catch(i8* %2) #2 [ "funclet"(token %1) ] |
| 244 | call void @__cxa_end_catch() [ "funclet"(token %1) ] |
| 245 | catchret from %1 to label %try.cont |
| 246 | |
| 247 | try.cont: ; preds = %entry, %catch.start |
| 248 | ret void |
| 249 | } |
| 250 | |
Heejin Ahn | 5ef4d5f | 2018-05-31 22:25:54 +0000 | [diff] [blame] | 251 | declare void @foo() |
Heejin Ahn | ed5e06b | 2018-08-21 19:44:11 +0000 | [diff] [blame] | 252 | declare void @bar(i32*) |
Heejin Ahn | 5ef4d5f | 2018-05-31 22:25:54 +0000 | [diff] [blame] | 253 | declare i32 @__gxx_wasm_personality_v0(...) |
| 254 | declare i8* @llvm.wasm.get.exception(token) |
| 255 | declare i32 @llvm.wasm.get.ehselector(token) |
| 256 | declare i32 @llvm.eh.typeid.for(i8*) |
| 257 | declare i8* @__cxa_begin_catch(i8*) |
| 258 | declare void @__cxa_end_catch() |
| 259 | declare void @__cxa_rethrow() |
| 260 | declare void @__clang_call_terminate(i8*) |
Heejin Ahn | 4934f76 | 2018-06-25 01:07:11 +0000 | [diff] [blame] | 261 | declare void @_ZSt9terminatev() |
Heejin Ahn | 5ef4d5f | 2018-05-31 22:25:54 +0000 | [diff] [blame] | 262 | declare %struct.Cleanup* @_ZN7CleanupD1Ev(%struct.Cleanup* returned) |
Heejin Ahn | da419bd | 2018-11-14 02:46:21 +0000 | [diff] [blame] | 263 | |
| 264 | ; CHECK: __cpp_exception: |
| 265 | ; CHECK: .eventtype __cpp_exception, void, i32 |