Wouter van Oortmerssen | a7be375 | 2018-08-13 23:12:49 +0000 | [diff] [blame] | 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 |
Heejin Ahn | ac62b05 | 2017-06-30 00:43:15 +0000 | [diff] [blame] | 3 | |
| 4 | 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] | 5 | target triple = "wasm32-unknown-unknown" |
Heejin Ahn | ac62b05 | 2017-06-30 00:43:15 +0000 | [diff] [blame] | 6 | |
Heejin Ahn | 5ef4d5f | 2018-05-31 22:25:54 +0000 | [diff] [blame] | 7 | %struct.Cleanup = type { i8 } |
Heejin Ahn | ac62b05 | 2017-06-30 00:43:15 +0000 | [diff] [blame] | 8 | |
Heejin Ahn | 5ef4d5f | 2018-05-31 22:25:54 +0000 | [diff] [blame] | 9 | @_ZTIi = external constant i8* |
| 10 | |
| 11 | declare void @llvm.wasm.throw(i32, i8*) |
| 12 | |
| 13 | ; CHECK-LABEL: test_throw: |
Heejin Ahn | ac62b05 | 2017-06-30 00:43:15 +0000 | [diff] [blame] | 14 | ; CHECK-NEXT: i32.const $push0=, 0 |
| 15 | ; CHECK-NEXT: throw 0, $pop0 |
Heejin Ahn | 5ef4d5f | 2018-05-31 22:25:54 +0000 | [diff] [blame] | 16 | define void @test_throw() { |
Heejin Ahn | ac62b05 | 2017-06-30 00:43:15 +0000 | [diff] [blame] | 17 | call void @llvm.wasm.throw(i32 0, i8* null) |
| 18 | ret void |
| 19 | } |
| 20 | |
Heejin Ahn | 4934f76 | 2018-06-25 01:07:11 +0000 | [diff] [blame] | 21 | ; CHECK-LABEL: test_catch_rethrow: |
Heejin Ahn | e76fa9e | 2018-08-16 23:50:59 +0000 | [diff] [blame] | 22 | ; CHECK: try |
Heejin Ahn | 5ef4d5f | 2018-05-31 22:25:54 +0000 | [diff] [blame] | 23 | ; 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 Ahn | 4934f76 | 2018-06-25 01:07:11 +0000 | [diff] [blame] | 31 | ; CHECK-NEXT: rethrow |
Heejin Ahn | e76fa9e | 2018-08-16 23:50:59 +0000 | [diff] [blame] | 32 | ; CHECK: end_try |
Heejin Ahn | 4934f76 | 2018-06-25 01:07:11 +0000 | [diff] [blame] | 33 | 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] | 34 | entry: |
| 35 | invoke void @foo() |
| 36 | to label %try.cont unwind label %catch.dispatch |
| 37 | |
| 38 | catch.dispatch: ; preds = %entry |
| 39 | %0 = catchswitch within none [label %catch.start] unwind to caller |
| 40 | |
| 41 | catch.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 | |
| 49 | catch: ; 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 | |
| 54 | rethrow: ; preds = %catch.start |
| 55 | call void @__cxa_rethrow() [ "funclet"(token %1) ] |
| 56 | unreachable |
| 57 | |
| 58 | try.cont: ; preds = %entry, %catch |
Heejin Ahn | ac62b05 | 2017-06-30 00:43:15 +0000 | [diff] [blame] | 59 | ret void |
| 60 | } |
Heejin Ahn | 5ef4d5f | 2018-05-31 22:25:54 +0000 | [diff] [blame] | 61 | |
| 62 | ; CHECK-LABEL: test_cleanup: |
Heejin Ahn | e76fa9e | 2018-08-16 23:50:59 +0000 | [diff] [blame] | 63 | ; CHECK: try |
Heejin Ahn | 5ef4d5f | 2018-05-31 22:25:54 +0000 | [diff] [blame] | 64 | ; CHECK: call foo@FUNCTION |
Heejin Ahn | 4934f76 | 2018-06-25 01:07:11 +0000 | [diff] [blame] | 65 | ; CHECK: catch_all |
Heejin Ahn | 283e1c1 | 2018-08-14 22:14:51 +0000 | [diff] [blame] | 66 | ; CHECK: i32.call $push{{.+}}=, _ZN7CleanupD1Ev@FUNCTION |
Heejin Ahn | 4934f76 | 2018-06-25 01:07:11 +0000 | [diff] [blame] | 67 | ; CHECK: rethrow |
Heejin Ahn | e76fa9e | 2018-08-16 23:50:59 +0000 | [diff] [blame] | 68 | ; CHECK: end_try |
Heejin Ahn | 5ef4d5f | 2018-05-31 22:25:54 +0000 | [diff] [blame] | 69 | define void @test_cleanup() personality i8* bitcast (i32 (...)* @__gxx_wasm_personality_v0 to i8*) { |
| 70 | entry: |
| 71 | %c = alloca %struct.Cleanup, align 1 |
| 72 | invoke void @foo() |
| 73 | to label %invoke.cont unwind label %ehcleanup |
| 74 | |
| 75 | invoke.cont: ; preds = %entry |
| 76 | %call = call %struct.Cleanup* @_ZN7CleanupD1Ev(%struct.Cleanup* %c) |
| 77 | ret void |
| 78 | |
| 79 | ehcleanup: ; 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 Ahn | 4934f76 | 2018-06-25 01:07:11 +0000 | [diff] [blame] | 85 | ; - 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 |
| 95 | define hidden i32 @test_terminatepad() personality i8* bitcast (i32 (...)* @__gxx_wasm_personality_v0 to i8*) { |
| 96 | entry: |
| 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 | |
| 102 | invoke.cont: ; preds = %entry |
| 103 | %call = invoke %struct.Cleanup* @_ZN7CleanupD1Ev(%struct.Cleanup* %c1) |
| 104 | to label %try.cont unwind label %catch.dispatch |
| 105 | |
| 106 | ehcleanup: ; 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 | |
| 111 | invoke.cont3: ; preds = %ehcleanup |
| 112 | cleanupret from %0 unwind label %catch.dispatch |
| 113 | |
| 114 | catch.dispatch: ; preds = %invoke.cont3, %invoke.cont |
| 115 | %1 = catchswitch within none [label %catch.start] unwind label %ehcleanup7 |
| 116 | |
| 117 | catch.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 | |
| 125 | invoke.cont5: ; preds = %catch.start |
| 126 | catchret from %2 to label %try.cont |
| 127 | |
| 128 | try.cont: ; preds = %invoke.cont5, %invoke.cont |
| 129 | %call6 = call %struct.Cleanup* @_ZN7CleanupD1Ev(%struct.Cleanup* %c) |
| 130 | ret i32 0 |
| 131 | |
| 132 | ehcleanup7: ; 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 | |
| 137 | invoke.cont8: ; preds = %ehcleanup7 |
| 138 | cleanupret from %6 unwind to caller |
| 139 | |
| 140 | terminate: ; 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 | |
| 146 | terminate10: ; 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 Ahn | ed5e06b | 2018-08-21 19:44:11 +0000 | [diff] [blame] | 153 | ; 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 Ahn | 9cd7f88 | 2018-08-21 20:04:42 +0000 | [diff] [blame^] | 167 | ; CHECK-NOT: get_global $push{{.+}}=, __stack_pointer@GLOBAL |
Heejin Ahn | ed5e06b | 2018-08-21 19:44:11 +0000 | [diff] [blame] | 168 | ; 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 |
| 173 | define void @test_no_prolog_epilog_in_ehpad() personality i8* bitcast (i32 (...)* @__gxx_wasm_personality_v0 to i8*) { |
| 174 | entry: |
| 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 | |
| 180 | catch.dispatch: ; preds = %entry |
| 181 | %0 = catchswitch within none [label %catch.start] unwind to caller |
| 182 | |
| 183 | catch.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 | |
| 191 | catch: ; 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 | |
| 198 | invoke.cont1: ; preds = %catch |
| 199 | call void @__cxa_end_catch() [ "funclet"(token %1) ] |
| 200 | catchret from %1 to label %try.cont |
| 201 | |
| 202 | rethrow: ; preds = %catch.start |
| 203 | call void @__cxa_rethrow() [ "funclet"(token %1) ] |
| 204 | unreachable |
| 205 | |
| 206 | try.cont: ; preds = %entry, %invoke.cont1 |
| 207 | ret void |
| 208 | |
| 209 | ehcleanup: ; 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 Ahn | 5ef4d5f | 2018-05-31 22:25:54 +0000 | [diff] [blame] | 215 | declare void @foo() |
Heejin Ahn | ed5e06b | 2018-08-21 19:44:11 +0000 | [diff] [blame] | 216 | declare void @bar(i32*) |
Heejin Ahn | 5ef4d5f | 2018-05-31 22:25:54 +0000 | [diff] [blame] | 217 | declare i32 @__gxx_wasm_personality_v0(...) |
| 218 | declare i8* @llvm.wasm.get.exception(token) |
| 219 | declare i32 @llvm.wasm.get.ehselector(token) |
| 220 | declare i32 @llvm.eh.typeid.for(i8*) |
| 221 | declare i8* @__cxa_begin_catch(i8*) |
| 222 | declare void @__cxa_end_catch() |
| 223 | declare void @__cxa_rethrow() |
| 224 | declare void @__clang_call_terminate(i8*) |
Heejin Ahn | 4934f76 | 2018-06-25 01:07:11 +0000 | [diff] [blame] | 225 | declare void @_ZSt9terminatev() |
Heejin Ahn | 5ef4d5f | 2018-05-31 22:25:54 +0000 | [diff] [blame] | 226 | declare %struct.Cleanup* @_ZN7CleanupD1Ev(%struct.Cleanup* returned) |