Heejin Ahn | 5ef4d5f | 2018-05-31 22:25:54 +0000 | [diff] [blame] | 1 | ; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -exception-model=wasm | FileCheck %s |
Heejin Ahn | ac62b05 | 2017-06-30 00:43:15 +0000 | [diff] [blame] | 2 | |
| 3 | 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] | 4 | target triple = "wasm32-unknown-unknown" |
Heejin Ahn | ac62b05 | 2017-06-30 00:43:15 +0000 | [diff] [blame] | 5 | |
Heejin Ahn | 5ef4d5f | 2018-05-31 22:25:54 +0000 | [diff] [blame] | 6 | %struct.Cleanup = type { i8 } |
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 | @_ZTIi = external constant i8* |
| 9 | |
| 10 | declare void @llvm.wasm.throw(i32, i8*) |
| 11 | |
| 12 | ; CHECK-LABEL: test_throw: |
Heejin Ahn | ac62b05 | 2017-06-30 00:43:15 +0000 | [diff] [blame] | 13 | ; CHECK-NEXT: i32.const $push0=, 0 |
| 14 | ; CHECK-NEXT: throw 0, $pop0 |
Heejin Ahn | 5ef4d5f | 2018-05-31 22:25:54 +0000 | [diff] [blame] | 15 | define void @test_throw() { |
Heejin Ahn | ac62b05 | 2017-06-30 00:43:15 +0000 | [diff] [blame] | 16 | call void @llvm.wasm.throw(i32 0, i8* null) |
| 17 | ret void |
| 18 | } |
| 19 | |
Heejin Ahn | 4934f76 | 2018-06-25 01:07:11 +0000 | [diff] [blame^] | 20 | ; CHECK-LABEL: test_catch_rethrow: |
Heejin Ahn | 5ef4d5f | 2018-05-31 22:25:54 +0000 | [diff] [blame] | 21 | ; CHECK: call foo@FUNCTION |
| 22 | ; CHECK: i32.catch $push{{.+}}=, 0 |
| 23 | ; CHECK-DAG: i32.store __wasm_lpad_context |
| 24 | ; CHECK-DAG: i32.store __wasm_lpad_context+4 |
| 25 | ; CHECK: i32.call $push{{.+}}=, _Unwind_CallPersonality@FUNCTION |
| 26 | ; CHECK: i32.call $push{{.+}}=, __cxa_begin_catch@FUNCTION |
| 27 | ; CHECK: call __cxa_end_catch@FUNCTION |
| 28 | ; CHECK: call __cxa_rethrow@FUNCTION |
Heejin Ahn | 4934f76 | 2018-06-25 01:07:11 +0000 | [diff] [blame^] | 29 | ; CHECK-NEXT: rethrow |
| 30 | 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] | 31 | entry: |
| 32 | invoke void @foo() |
| 33 | to label %try.cont unwind label %catch.dispatch |
| 34 | |
| 35 | catch.dispatch: ; preds = %entry |
| 36 | %0 = catchswitch within none [label %catch.start] unwind to caller |
| 37 | |
| 38 | catch.start: ; preds = %catch.dispatch |
| 39 | %1 = catchpad within %0 [i8* bitcast (i8** @_ZTIi to i8*)] |
| 40 | %2 = call i8* @llvm.wasm.get.exception(token %1) |
| 41 | %3 = call i32 @llvm.wasm.get.ehselector(token %1) |
| 42 | %4 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) |
| 43 | %matches = icmp eq i32 %3, %4 |
| 44 | br i1 %matches, label %catch, label %rethrow |
| 45 | |
| 46 | catch: ; preds = %catch.start |
| 47 | %5 = call i8* @__cxa_begin_catch(i8* %2) [ "funclet"(token %1) ] |
| 48 | call void @__cxa_end_catch() [ "funclet"(token %1) ] |
| 49 | catchret from %1 to label %try.cont |
| 50 | |
| 51 | rethrow: ; preds = %catch.start |
| 52 | call void @__cxa_rethrow() [ "funclet"(token %1) ] |
| 53 | unreachable |
| 54 | |
| 55 | try.cont: ; preds = %entry, %catch |
Heejin Ahn | ac62b05 | 2017-06-30 00:43:15 +0000 | [diff] [blame] | 56 | ret void |
| 57 | } |
Heejin Ahn | 5ef4d5f | 2018-05-31 22:25:54 +0000 | [diff] [blame] | 58 | |
| 59 | ; CHECK-LABEL: test_cleanup: |
| 60 | ; CHECK: call foo@FUNCTION |
Heejin Ahn | 4934f76 | 2018-06-25 01:07:11 +0000 | [diff] [blame^] | 61 | ; CHECK: catch_all |
Heejin Ahn | 5ef4d5f | 2018-05-31 22:25:54 +0000 | [diff] [blame] | 62 | ; CHECK: i32.call $push20=, _ZN7CleanupD1Ev@FUNCTION |
Heejin Ahn | 4934f76 | 2018-06-25 01:07:11 +0000 | [diff] [blame^] | 63 | ; CHECK: rethrow |
Heejin Ahn | 5ef4d5f | 2018-05-31 22:25:54 +0000 | [diff] [blame] | 64 | define void @test_cleanup() personality i8* bitcast (i32 (...)* @__gxx_wasm_personality_v0 to i8*) { |
| 65 | entry: |
| 66 | %c = alloca %struct.Cleanup, align 1 |
| 67 | invoke void @foo() |
| 68 | to label %invoke.cont unwind label %ehcleanup |
| 69 | |
| 70 | invoke.cont: ; preds = %entry |
| 71 | %call = call %struct.Cleanup* @_ZN7CleanupD1Ev(%struct.Cleanup* %c) |
| 72 | ret void |
| 73 | |
| 74 | ehcleanup: ; preds = %entry |
| 75 | %0 = cleanuppad within none [] |
| 76 | %call1 = call %struct.Cleanup* @_ZN7CleanupD1Ev(%struct.Cleanup* %c) [ "funclet"(token %0) ] |
| 77 | cleanupret from %0 unwind to caller |
| 78 | } |
| 79 | |
Heejin Ahn | 4934f76 | 2018-06-25 01:07:11 +0000 | [diff] [blame^] | 80 | ; - Tests multple terminate pads are merged into one |
| 81 | ; - Tests a catch_all terminate pad is created after a catch terminate pad |
| 82 | |
| 83 | ; CHECK-LABEL: test_terminatepad |
| 84 | ; CHECK: i32.catch |
| 85 | ; CHECK: call __clang_call_terminate@FUNCTION |
| 86 | ; CHECK: unreachable |
| 87 | ; CHECK: catch_all |
| 88 | ; CHECK: call _ZSt9terminatev@FUNCTION |
| 89 | ; CHECK-NOT: call __clang_call_terminate@FUNCTION |
| 90 | define hidden i32 @test_terminatepad() personality i8* bitcast (i32 (...)* @__gxx_wasm_personality_v0 to i8*) { |
| 91 | entry: |
| 92 | %c = alloca %struct.Cleanup, align 1 |
| 93 | %c1 = alloca %struct.Cleanup, align 1 |
| 94 | invoke void @foo() |
| 95 | to label %invoke.cont unwind label %ehcleanup |
| 96 | |
| 97 | invoke.cont: ; preds = %entry |
| 98 | %call = invoke %struct.Cleanup* @_ZN7CleanupD1Ev(%struct.Cleanup* %c1) |
| 99 | to label %try.cont unwind label %catch.dispatch |
| 100 | |
| 101 | ehcleanup: ; preds = %entry |
| 102 | %0 = cleanuppad within none [] |
| 103 | %call4 = invoke %struct.Cleanup* @_ZN7CleanupD1Ev(%struct.Cleanup* %c1) [ "funclet"(token %0) ] |
| 104 | to label %invoke.cont3 unwind label %terminate |
| 105 | |
| 106 | invoke.cont3: ; preds = %ehcleanup |
| 107 | cleanupret from %0 unwind label %catch.dispatch |
| 108 | |
| 109 | catch.dispatch: ; preds = %invoke.cont3, %invoke.cont |
| 110 | %1 = catchswitch within none [label %catch.start] unwind label %ehcleanup7 |
| 111 | |
| 112 | catch.start: ; preds = %catch.dispatch |
| 113 | %2 = catchpad within %1 [i8* null] |
| 114 | %3 = call i8* @llvm.wasm.get.exception(token %2) |
| 115 | %4 = call i32 @llvm.wasm.get.ehselector(token %2) |
| 116 | %5 = call i8* @__cxa_begin_catch(i8* %3) [ "funclet"(token %2) ] |
| 117 | invoke void @__cxa_end_catch() [ "funclet"(token %2) ] |
| 118 | to label %invoke.cont5 unwind label %ehcleanup7 |
| 119 | |
| 120 | invoke.cont5: ; preds = %catch.start |
| 121 | catchret from %2 to label %try.cont |
| 122 | |
| 123 | try.cont: ; preds = %invoke.cont5, %invoke.cont |
| 124 | %call6 = call %struct.Cleanup* @_ZN7CleanupD1Ev(%struct.Cleanup* %c) |
| 125 | ret i32 0 |
| 126 | |
| 127 | ehcleanup7: ; preds = %catch.start, %catch.dispatch |
| 128 | %6 = cleanuppad within none [] |
| 129 | %call9 = invoke %struct.Cleanup* @_ZN7CleanupD1Ev(%struct.Cleanup* %c) [ "funclet"(token %6) ] |
| 130 | to label %invoke.cont8 unwind label %terminate10 |
| 131 | |
| 132 | invoke.cont8: ; preds = %ehcleanup7 |
| 133 | cleanupret from %6 unwind to caller |
| 134 | |
| 135 | terminate: ; preds = %ehcleanup |
| 136 | %7 = cleanuppad within %0 [] |
| 137 | %8 = call i8* @llvm.wasm.get.exception(token %7) |
| 138 | call void @__clang_call_terminate(i8* %8) [ "funclet"(token %7) ] |
| 139 | unreachable |
| 140 | |
| 141 | terminate10: ; preds = %ehcleanup7 |
| 142 | %9 = cleanuppad within %6 [] |
| 143 | %10 = call i8* @llvm.wasm.get.exception(token %9) |
| 144 | call void @__clang_call_terminate(i8* %10) [ "funclet"(token %9) ] |
| 145 | unreachable |
| 146 | } |
| 147 | |
Heejin Ahn | 5ef4d5f | 2018-05-31 22:25:54 +0000 | [diff] [blame] | 148 | declare void @foo() |
Heejin Ahn | 5ef4d5f | 2018-05-31 22:25:54 +0000 | [diff] [blame] | 149 | declare i32 @__gxx_wasm_personality_v0(...) |
| 150 | declare i8* @llvm.wasm.get.exception(token) |
| 151 | declare i32 @llvm.wasm.get.ehselector(token) |
| 152 | declare i32 @llvm.eh.typeid.for(i8*) |
| 153 | declare i8* @__cxa_begin_catch(i8*) |
| 154 | declare void @__cxa_end_catch() |
| 155 | declare void @__cxa_rethrow() |
| 156 | declare void @__clang_call_terminate(i8*) |
Heejin Ahn | 4934f76 | 2018-06-25 01:07:11 +0000 | [diff] [blame^] | 157 | declare void @_ZSt9terminatev() |
Heejin Ahn | 5ef4d5f | 2018-05-31 22:25:54 +0000 | [diff] [blame] | 158 | declare %struct.Cleanup* @_ZN7CleanupD1Ev(%struct.Cleanup* returned) |