Heejin Ahn | 7829763 | 2019-02-26 03:29:59 +0000 | [diff] [blame] | 1 | ; RUN: llc < %s -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -disable-block-placement -verify-machineinstrs -fast-isel=false -machine-sink-split-probability-threshold=0 -cgp-freq-ratio-to-skip-merge=1000 -exception-model=wasm -mattr=+exception-handling | FileCheck %s |
Heejin Ahn | 7fb68d2 | 2018-08-07 20:19:23 +0000 | [diff] [blame] | 2 | |
| 3 | target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" |
| 4 | target triple = "wasm32-unknown-unknown" |
| 5 | |
| 6 | @_ZTIi = external constant i8* |
| 7 | @_ZTId = external constant i8* |
| 8 | |
| 9 | ; Simple test case with two catch clauses |
Heejin Ahn | 7829763 | 2019-02-26 03:29:59 +0000 | [diff] [blame] | 10 | ; |
| 11 | ; void foo(); |
Heejin Ahn | d6f4878 | 2019-01-30 03:21:57 +0000 | [diff] [blame] | 12 | ; void test0() { |
| 13 | ; try { |
| 14 | ; foo(); |
Heejin Ahn | 7829763 | 2019-02-26 03:29:59 +0000 | [diff] [blame] | 15 | ; } catch (int) { |
| 16 | ; } catch (double) { |
Heejin Ahn | d6f4878 | 2019-01-30 03:21:57 +0000 | [diff] [blame] | 17 | ; } |
| 18 | ; } |
Heejin Ahn | 7fb68d2 | 2018-08-07 20:19:23 +0000 | [diff] [blame] | 19 | |
| 20 | ; CHECK-LABEL: test0 |
Heejin Ahn | cf699b4 | 2019-02-27 00:50:53 +0000 | [diff] [blame] | 21 | ; CHECK: try |
| 22 | ; CHECK: call foo |
| 23 | ; CHECK: catch |
| 24 | ; CHECK: block |
| 25 | ; CHECK: br_if 0, {{.*}} # 0: down to label2 |
| 26 | ; CHECK: i32.call $drop=, __cxa_begin_catch |
| 27 | ; CHECK: call __cxa_end_catch |
| 28 | ; CHECK: br 1 # 1: down to label0 |
| 29 | ; CHECK: end_block # label2: |
| 30 | ; CHECK: block |
| 31 | ; CHECK: br_if 0, {{.*}} # 0: down to label3 |
| 32 | ; CHECK: i32.call $drop=, __cxa_begin_catch |
| 33 | ; CHECK: call __cxa_end_catch |
| 34 | ; CHECK: br 1 # 1: down to label0 |
| 35 | ; CHECK: end_block # label3: |
| 36 | ; CHECK: call __cxa_rethrow |
| 37 | ; CHECK: end_try # label0: |
Heejin Ahn | 7fb68d2 | 2018-08-07 20:19:23 +0000 | [diff] [blame] | 38 | define void @test0() personality i8* bitcast (i32 (...)* @__gxx_wasm_personality_v0 to i8*) { |
| 39 | entry: |
| 40 | invoke void @foo() |
| 41 | to label %try.cont unwind label %catch.dispatch |
| 42 | |
| 43 | catch.dispatch: ; preds = %entry |
| 44 | %0 = catchswitch within none [label %catch.start] unwind to caller |
| 45 | |
| 46 | catch.start: ; preds = %catch.dispatch |
| 47 | %1 = catchpad within %0 [i8* bitcast (i8** @_ZTIi to i8*), i8* bitcast (i8** @_ZTId to i8*)] |
| 48 | %2 = call i8* @llvm.wasm.get.exception(token %1) |
| 49 | %3 = call i32 @llvm.wasm.get.ehselector(token %1) |
| 50 | %4 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) |
| 51 | %matches = icmp eq i32 %3, %4 |
| 52 | br i1 %matches, label %catch2, label %catch.fallthrough |
| 53 | |
| 54 | catch2: ; preds = %catch.start |
| 55 | %5 = call i8* @__cxa_begin_catch(i8* %2) [ "funclet"(token %1) ] |
Heejin Ahn | 7fb68d2 | 2018-08-07 20:19:23 +0000 | [diff] [blame] | 56 | call void @__cxa_end_catch() [ "funclet"(token %1) ] |
| 57 | catchret from %1 to label %try.cont |
| 58 | |
| 59 | catch.fallthrough: ; preds = %catch.start |
Heejin Ahn | 7829763 | 2019-02-26 03:29:59 +0000 | [diff] [blame] | 60 | %6 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTId to i8*)) |
| 61 | %matches1 = icmp eq i32 %3, %6 |
Heejin Ahn | 7fb68d2 | 2018-08-07 20:19:23 +0000 | [diff] [blame] | 62 | br i1 %matches1, label %catch, label %rethrow |
| 63 | |
| 64 | catch: ; preds = %catch.fallthrough |
Heejin Ahn | 7829763 | 2019-02-26 03:29:59 +0000 | [diff] [blame] | 65 | %7 = call i8* @__cxa_begin_catch(i8* %2) [ "funclet"(token %1) ] |
Heejin Ahn | 7fb68d2 | 2018-08-07 20:19:23 +0000 | [diff] [blame] | 66 | call void @__cxa_end_catch() [ "funclet"(token %1) ] |
| 67 | catchret from %1 to label %try.cont |
| 68 | |
| 69 | rethrow: ; preds = %catch.fallthrough |
| 70 | call void @__cxa_rethrow() [ "funclet"(token %1) ] |
| 71 | unreachable |
| 72 | |
| 73 | try.cont: ; preds = %entry, %catch, %catch2 |
| 74 | ret void |
| 75 | } |
| 76 | |
| 77 | ; Nested try-catches within a catch |
Heejin Ahn | d6f4878 | 2019-01-30 03:21:57 +0000 | [diff] [blame] | 78 | ; void test1() { |
| 79 | ; try { |
| 80 | ; foo(); |
Heejin Ahn | 7829763 | 2019-02-26 03:29:59 +0000 | [diff] [blame] | 81 | ; } catch (int) { |
Heejin Ahn | d6f4878 | 2019-01-30 03:21:57 +0000 | [diff] [blame] | 82 | ; try { |
| 83 | ; foo(); |
Heejin Ahn | 7829763 | 2019-02-26 03:29:59 +0000 | [diff] [blame] | 84 | ; } catch (int) { |
Heejin Ahn | d6f4878 | 2019-01-30 03:21:57 +0000 | [diff] [blame] | 85 | ; foo(); |
| 86 | ; } |
| 87 | ; } |
| 88 | ; } |
Heejin Ahn | 7fb68d2 | 2018-08-07 20:19:23 +0000 | [diff] [blame] | 89 | |
| 90 | ; CHECK-LABEL: test1 |
Heejin Ahn | 82da1ff | 2019-02-27 01:35:14 +0000 | [diff] [blame] | 91 | ; CHECK: try |
| 92 | ; CHECK: call foo |
| 93 | ; CHECK: catch |
| 94 | ; CHECK: block |
| 95 | ; CHECK: block |
| 96 | ; CHECK: br_if 0, {{.*}} # 0: down to label7 |
| 97 | ; CHECK: i32.call $drop=, __cxa_begin_catch |
| 98 | ; CHECK: try |
| 99 | ; CHECK: call foo |
| 100 | ; CHECK: br 2 # 2: down to label6 |
| 101 | ; CHECK: catch |
| 102 | ; CHECK: try |
| 103 | ; CHECK: block |
| 104 | ; CHECK: br_if 0, {{.*}} # 0: down to label11 |
| 105 | ; CHECK: i32.call $drop=, __cxa_begin_catch |
| 106 | ; CHECK: try |
| 107 | ; CHECK: call foo |
| 108 | ; CHECK: br 2 # 2: down to label10 |
| 109 | ; CHECK: catch |
| 110 | ; CHECK: call __cxa_end_catch |
| 111 | ; CHECK: rethrow # down to catch3 |
| 112 | ; CHECK: end_try |
| 113 | ; CHECK: end_block # label11: |
| 114 | ; CHECK: call __cxa_rethrow |
| 115 | ; CHECK: unreachable |
| 116 | ; CHECK: catch {{.*}} # catch3: |
| 117 | ; CHECK: call __cxa_end_catch |
| 118 | ; CHECK: rethrow # to caller |
| 119 | ; CHECK: end_try # label10: |
| 120 | ; CHECK: call __cxa_end_catch |
| 121 | ; CHECK: br 2 # 2: down to label6 |
| 122 | ; CHECK: end_try |
| 123 | ; CHECK: end_block # label7: |
| 124 | ; CHECK: call __cxa_rethrow |
| 125 | ; CHECK: unreachable |
| 126 | ; CHECK: end_block # label6: |
| 127 | ; CHECK: call __cxa_end_catch |
| 128 | ; CHECK: end_try |
Heejin Ahn | d6f4878 | 2019-01-30 03:21:57 +0000 | [diff] [blame] | 129 | define void @test1() personality i8* bitcast (i32 (...)* @__gxx_wasm_personality_v0 to i8*) { |
Heejin Ahn | 7fb68d2 | 2018-08-07 20:19:23 +0000 | [diff] [blame] | 130 | entry: |
| 131 | invoke void @foo() |
| 132 | to label %try.cont11 unwind label %catch.dispatch |
| 133 | |
| 134 | catch.dispatch: ; preds = %entry |
| 135 | %0 = catchswitch within none [label %catch.start] unwind to caller |
| 136 | |
| 137 | catch.start: ; preds = %catch.dispatch |
| 138 | %1 = catchpad within %0 [i8* bitcast (i8** @_ZTIi to i8*)] |
| 139 | %2 = call i8* @llvm.wasm.get.exception(token %1) |
| 140 | %3 = call i32 @llvm.wasm.get.ehselector(token %1) |
| 141 | %4 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) |
| 142 | %matches = icmp eq i32 %3, %4 |
| 143 | br i1 %matches, label %catch, label %rethrow |
| 144 | |
| 145 | catch: ; preds = %catch.start |
| 146 | %5 = call i8* @__cxa_begin_catch(i8* %2) [ "funclet"(token %1) ] |
| 147 | %6 = bitcast i8* %5 to i32* |
| 148 | %7 = load i32, i32* %6, align 4 |
| 149 | invoke void @foo() [ "funclet"(token %1) ] |
| 150 | to label %try.cont unwind label %catch.dispatch2 |
| 151 | |
| 152 | catch.dispatch2: ; preds = %catch |
| 153 | %8 = catchswitch within %1 [label %catch.start3] unwind label %ehcleanup9 |
| 154 | |
| 155 | catch.start3: ; preds = %catch.dispatch2 |
| 156 | %9 = catchpad within %8 [i8* bitcast (i8** @_ZTIi to i8*)] |
| 157 | %10 = call i8* @llvm.wasm.get.exception(token %9) |
| 158 | %11 = call i32 @llvm.wasm.get.ehselector(token %9) |
| 159 | %12 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) |
| 160 | %matches4 = icmp eq i32 %11, %12 |
| 161 | br i1 %matches4, label %catch6, label %rethrow5 |
| 162 | |
| 163 | catch6: ; preds = %catch.start3 |
| 164 | %13 = call i8* @__cxa_begin_catch(i8* %10) [ "funclet"(token %9) ] |
| 165 | %14 = bitcast i8* %13 to i32* |
| 166 | %15 = load i32, i32* %14, align 4 |
| 167 | invoke void @foo() [ "funclet"(token %9) ] |
| 168 | to label %invoke.cont8 unwind label %ehcleanup |
| 169 | |
| 170 | invoke.cont8: ; preds = %catch6 |
| 171 | call void @__cxa_end_catch() [ "funclet"(token %9) ] |
| 172 | catchret from %9 to label %try.cont |
| 173 | |
| 174 | rethrow5: ; preds = %catch.start3 |
| 175 | invoke void @__cxa_rethrow() [ "funclet"(token %9) ] |
| 176 | to label %unreachable unwind label %ehcleanup9 |
| 177 | |
| 178 | try.cont: ; preds = %catch, %invoke.cont8 |
| 179 | call void @__cxa_end_catch() [ "funclet"(token %1) ] |
| 180 | catchret from %1 to label %try.cont11 |
| 181 | |
| 182 | rethrow: ; preds = %catch.start |
| 183 | call void @__cxa_rethrow() [ "funclet"(token %1) ] |
| 184 | unreachable |
| 185 | |
| 186 | try.cont11: ; preds = %entry, %try.cont |
| 187 | ret void |
| 188 | |
| 189 | ehcleanup: ; preds = %catch6 |
| 190 | %16 = cleanuppad within %9 [] |
| 191 | call void @__cxa_end_catch() [ "funclet"(token %16) ] |
| 192 | cleanupret from %16 unwind label %ehcleanup9 |
| 193 | |
| 194 | ehcleanup9: ; preds = %ehcleanup, %rethrow5, %catch.dispatch2 |
| 195 | %17 = cleanuppad within %1 [] |
| 196 | call void @__cxa_end_catch() [ "funclet"(token %17) ] |
| 197 | cleanupret from %17 unwind to caller |
| 198 | |
| 199 | unreachable: ; preds = %rethrow5 |
| 200 | unreachable |
| 201 | } |
| 202 | |
| 203 | ; Nested loop within a catch clause |
Heejin Ahn | d6f4878 | 2019-01-30 03:21:57 +0000 | [diff] [blame] | 204 | ; void test2() { |
| 205 | ; try { |
| 206 | ; foo(); |
| 207 | ; } catch (...) { |
| 208 | ; for (int i = 0; i < 50; i++) |
| 209 | ; foo(); |
| 210 | ; } |
| 211 | ; } |
Heejin Ahn | 7fb68d2 | 2018-08-07 20:19:23 +0000 | [diff] [blame] | 212 | |
| 213 | ; CHECK-LABEL: test2 |
Heejin Ahn | cf699b4 | 2019-02-27 00:50:53 +0000 | [diff] [blame] | 214 | ; CHECK: try |
| 215 | ; CHECK: call foo |
| 216 | ; CHECK: catch |
| 217 | ; CHECK: i32.call $drop=, __cxa_begin_catch |
| 218 | ; CHECK: loop # label15: |
| 219 | ; CHECK: block |
Heejin Ahn | 7829763 | 2019-02-26 03:29:59 +0000 | [diff] [blame] | 220 | ; CHECK: block |
Heejin Ahn | cf699b4 | 2019-02-27 00:50:53 +0000 | [diff] [blame] | 221 | ; CHECK: br_if 0, {{.*}} # 0: down to label17 |
| 222 | ; CHECK: try |
| 223 | ; CHECK: call foo |
| 224 | ; CHECK: br 2 # 2: down to label16 |
| 225 | ; CHECK: catch |
Heejin Ahn | 7829763 | 2019-02-26 03:29:59 +0000 | [diff] [blame] | 226 | ; CHECK: try |
Heejin Ahn | cf699b4 | 2019-02-27 00:50:53 +0000 | [diff] [blame] | 227 | ; CHECK: call __cxa_end_catch |
Heejin Ahn | 7829763 | 2019-02-26 03:29:59 +0000 | [diff] [blame] | 228 | ; CHECK: catch |
Heejin Ahn | cf699b4 | 2019-02-27 00:50:53 +0000 | [diff] [blame] | 229 | ; CHECK: call __clang_call_terminate |
| 230 | ; CHECK: unreachable |
Heejin Ahn | 7829763 | 2019-02-26 03:29:59 +0000 | [diff] [blame] | 231 | ; CHECK: end_try |
Heejin Ahn | cf699b4 | 2019-02-27 00:50:53 +0000 | [diff] [blame] | 232 | ; CHECK: rethrow # to caller |
| 233 | ; CHECK: end_try |
| 234 | ; CHECK: end_block # label17: |
| 235 | ; CHECK: call __cxa_end_catch |
| 236 | ; CHECK: br 2 # 2: down to label13 |
| 237 | ; CHECK: end_block # label16: |
| 238 | ; CHECK: br 0 # 0: up to label15 |
| 239 | ; CHECK: end_loop |
| 240 | ; CHECK: end_try # label13: |
Heejin Ahn | 7fb68d2 | 2018-08-07 20:19:23 +0000 | [diff] [blame] | 241 | define void @test2() personality i8* bitcast (i32 (...)* @__gxx_wasm_personality_v0 to i8*) { |
| 242 | entry: |
| 243 | invoke void @foo() |
| 244 | to label %try.cont unwind label %catch.dispatch |
| 245 | |
| 246 | catch.dispatch: ; preds = %entry |
| 247 | %0 = catchswitch within none [label %catch.start] unwind to caller |
| 248 | |
| 249 | catch.start: ; preds = %catch.dispatch |
| 250 | %1 = catchpad within %0 [i8* null] |
| 251 | %2 = call i8* @llvm.wasm.get.exception(token %1) |
| 252 | %3 = call i32 @llvm.wasm.get.ehselector(token %1) |
| 253 | %4 = call i8* @__cxa_begin_catch(i8* %2) [ "funclet"(token %1) ] |
| 254 | br label %for.cond |
| 255 | |
| 256 | for.cond: ; preds = %for.inc, %catch.start |
| 257 | %i.0 = phi i32 [ 0, %catch.start ], [ %inc, %for.inc ] |
| 258 | %cmp = icmp slt i32 %i.0, 50 |
| 259 | br i1 %cmp, label %for.body, label %for.end |
| 260 | |
| 261 | for.body: ; preds = %for.cond |
| 262 | invoke void @foo() [ "funclet"(token %1) ] |
| 263 | to label %for.inc unwind label %ehcleanup |
| 264 | |
| 265 | for.inc: ; preds = %for.body |
| 266 | %inc = add nsw i32 %i.0, 1 |
| 267 | br label %for.cond |
| 268 | |
| 269 | for.end: ; preds = %for.cond |
| 270 | call void @__cxa_end_catch() [ "funclet"(token %1) ] |
| 271 | catchret from %1 to label %try.cont |
| 272 | |
| 273 | try.cont: ; preds = %for.end, %entry |
| 274 | ret void |
| 275 | |
| 276 | ehcleanup: ; preds = %for.body |
| 277 | %5 = cleanuppad within %1 [] |
| 278 | invoke void @__cxa_end_catch() [ "funclet"(token %5) ] |
| 279 | to label %invoke.cont2 unwind label %terminate |
| 280 | |
| 281 | invoke.cont2: ; preds = %ehcleanup |
| 282 | cleanupret from %5 unwind to caller |
| 283 | |
| 284 | terminate: ; preds = %ehcleanup |
| 285 | %6 = cleanuppad within %5 [] |
| 286 | %7 = call i8* @llvm.wasm.get.exception(token %6) |
| 287 | call void @__clang_call_terminate(i8* %7) [ "funclet"(token %6) ] |
| 288 | unreachable |
| 289 | } |
| 290 | |
| 291 | declare void @foo() |
| 292 | declare void @bar() |
| 293 | declare i32 @__gxx_wasm_personality_v0(...) |
| 294 | declare i8* @llvm.wasm.get.exception(token) |
| 295 | declare i32 @llvm.wasm.get.ehselector(token) |
| 296 | declare i32 @llvm.eh.typeid.for(i8*) |
| 297 | declare i8* @__cxa_begin_catch(i8*) |
| 298 | declare void @__cxa_end_catch() |
| 299 | declare void @__cxa_rethrow() |
| 300 | declare void @__clang_call_terminate(i8*) |
| 301 | declare void @_ZSt9terminatev() |