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 | 5ef4d5f | 2018-05-31 22:25:54 +0000 | [diff] [blame] | 22 | ; 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 Ahn | 4934f76 | 2018-06-25 01:07:11 +0000 | [diff] [blame] | 30 | ; CHECK-NEXT: rethrow |
| 31 | 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] | 32 | entry: |
| 33 | invoke void @foo() |
| 34 | to label %try.cont unwind label %catch.dispatch |
| 35 | |
| 36 | catch.dispatch: ; preds = %entry |
| 37 | %0 = catchswitch within none [label %catch.start] unwind to caller |
| 38 | |
| 39 | catch.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 | |
| 47 | catch: ; 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 | |
| 52 | rethrow: ; preds = %catch.start |
| 53 | call void @__cxa_rethrow() [ "funclet"(token %1) ] |
| 54 | unreachable |
| 55 | |
| 56 | try.cont: ; preds = %entry, %catch |
Heejin Ahn | ac62b05 | 2017-06-30 00:43:15 +0000 | [diff] [blame] | 57 | ret void |
| 58 | } |
Heejin Ahn | 5ef4d5f | 2018-05-31 22:25:54 +0000 | [diff] [blame] | 59 | |
| 60 | ; CHECK-LABEL: test_cleanup: |
| 61 | ; CHECK: call foo@FUNCTION |
Heejin Ahn | 4934f76 | 2018-06-25 01:07:11 +0000 | [diff] [blame] | 62 | ; CHECK: catch_all |
Heejin Ahn | 283e1c1 | 2018-08-14 22:14:51 +0000 | [diff] [blame] | 63 | ; CHECK: i32.call $push{{.+}}=, _ZN7CleanupD1Ev@FUNCTION |
Heejin Ahn | 4934f76 | 2018-06-25 01:07:11 +0000 | [diff] [blame] | 64 | ; CHECK: rethrow |
Heejin Ahn | 5ef4d5f | 2018-05-31 22:25:54 +0000 | [diff] [blame] | 65 | define void @test_cleanup() personality i8* bitcast (i32 (...)* @__gxx_wasm_personality_v0 to i8*) { |
| 66 | entry: |
| 67 | %c = alloca %struct.Cleanup, align 1 |
| 68 | invoke void @foo() |
| 69 | to label %invoke.cont unwind label %ehcleanup |
| 70 | |
| 71 | invoke.cont: ; preds = %entry |
| 72 | %call = call %struct.Cleanup* @_ZN7CleanupD1Ev(%struct.Cleanup* %c) |
| 73 | ret void |
| 74 | |
| 75 | ehcleanup: ; 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 Ahn | 4934f76 | 2018-06-25 01:07:11 +0000 | [diff] [blame] | 81 | ; - 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 |
| 91 | define hidden i32 @test_terminatepad() personality i8* bitcast (i32 (...)* @__gxx_wasm_personality_v0 to i8*) { |
| 92 | entry: |
| 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 | |
| 98 | invoke.cont: ; preds = %entry |
| 99 | %call = invoke %struct.Cleanup* @_ZN7CleanupD1Ev(%struct.Cleanup* %c1) |
| 100 | to label %try.cont unwind label %catch.dispatch |
| 101 | |
| 102 | ehcleanup: ; 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 | |
| 107 | invoke.cont3: ; preds = %ehcleanup |
| 108 | cleanupret from %0 unwind label %catch.dispatch |
| 109 | |
| 110 | catch.dispatch: ; preds = %invoke.cont3, %invoke.cont |
| 111 | %1 = catchswitch within none [label %catch.start] unwind label %ehcleanup7 |
| 112 | |
| 113 | catch.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 | |
| 121 | invoke.cont5: ; preds = %catch.start |
| 122 | catchret from %2 to label %try.cont |
| 123 | |
| 124 | try.cont: ; preds = %invoke.cont5, %invoke.cont |
| 125 | %call6 = call %struct.Cleanup* @_ZN7CleanupD1Ev(%struct.Cleanup* %c) |
| 126 | ret i32 0 |
| 127 | |
| 128 | ehcleanup7: ; 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 | |
| 133 | invoke.cont8: ; preds = %ehcleanup7 |
| 134 | cleanupret from %6 unwind to caller |
| 135 | |
| 136 | terminate: ; 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 | |
| 142 | terminate10: ; 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 Ahn | 5ef4d5f | 2018-05-31 22:25:54 +0000 | [diff] [blame] | 149 | declare void @foo() |
Heejin Ahn | 5ef4d5f | 2018-05-31 22:25:54 +0000 | [diff] [blame] | 150 | declare i32 @__gxx_wasm_personality_v0(...) |
| 151 | declare i8* @llvm.wasm.get.exception(token) |
| 152 | declare i32 @llvm.wasm.get.ehselector(token) |
| 153 | declare i32 @llvm.eh.typeid.for(i8*) |
| 154 | declare i8* @__cxa_begin_catch(i8*) |
| 155 | declare void @__cxa_end_catch() |
| 156 | declare void @__cxa_rethrow() |
| 157 | declare void @__clang_call_terminate(i8*) |
Heejin Ahn | 4934f76 | 2018-06-25 01:07:11 +0000 | [diff] [blame] | 158 | declare void @_ZSt9terminatev() |
Heejin Ahn | 5ef4d5f | 2018-05-31 22:25:54 +0000 | [diff] [blame] | 159 | declare %struct.Cleanup* @_ZN7CleanupD1Ev(%struct.Cleanup* returned) |