1 ; RUN: opt -S -simplifycfg < %s | FileCheck %s 2 3 declare void @Personality() 4 declare void @f() 5 6 ; CHECK-LABEL: define void @test1() 7 define void @test1() personality i8* bitcast (void ()* @Personality to i8*) { 8 entry: 9 ; CHECK: call void @f() 10 invoke void @f() 11 to label %exit unwind label %unreachable.unwind 12 exit: 13 ret void 14 unreachable.unwind: 15 cleanuppad within none [] 16 unreachable 17 } 18 19 ; CHECK-LABEL: define void @test2() 20 define void @test2() personality i8* bitcast (void ()* @Personality to i8*) { 21 entry: 22 invoke void @f() 23 to label %exit unwind label %catch.pad 24 catch.pad: 25 %cs1 = catchswitch within none [label %catch.body] unwind label %unreachable.unwind 26 ; CHECK: catch.pad: 27 ; CHECK-NEXT: catchswitch within none [label %catch.body] unwind to caller 28 catch.body: 29 ; CHECK: catch.body: 30 ; CHECK-NEXT: catchpad within %cs1 31 ; CHECK-NEXT: call void @f() 32 ; CHECK-NEXT: unreachable 33 %catch = catchpad within %cs1 [] 34 call void @f() 35 catchret from %catch to label %unreachable 36 exit: 37 ret void 38 unreachable.unwind: 39 cleanuppad within none [] 40 unreachable 41 unreachable: 42 unreachable 43 } 44 45 ; CHECK-LABEL: define void @test3() 46 define void @test3() personality i8* bitcast (void ()* @Personality to i8*) { 47 entry: 48 invoke void @f() 49 to label %exit unwind label %cleanup.pad 50 cleanup.pad: 51 ; CHECK: %cleanup = cleanuppad within none [] 52 ; CHECK-NEXT: call void @f() 53 ; CHECK-NEXT: unreachable 54 %cleanup = cleanuppad within none [] 55 invoke void @f() 56 to label %cleanup.ret unwind label %unreachable.unwind 57 cleanup.ret: 58 ; This cleanupret should be rewritten to unreachable, 59 ; and merged into the pred block. 60 cleanupret from %cleanup unwind label %unreachable.unwind 61 exit: 62 ret void 63 unreachable.unwind: 64 cleanuppad within none [] 65 unreachable 66 } 67 68 ; CHECK-LABEL: define void @test5() 69 define void @test5() personality i8* bitcast (void ()* @Personality to i8*) { 70 entry: 71 invoke void @f() 72 to label %exit unwind label %catch.pad 73 74 catch.pad: 75 %cs1 = catchswitch within none [label %catch.body] unwind to caller 76 77 catch.body: 78 %catch = catchpad within %cs1 [] 79 catchret from %catch to label %exit 80 81 exit: 82 unreachable 83 } 84 85 ; CHECK-LABEL: define void @test6() 86 define void @test6() personality i8* bitcast (void ()* @Personality to i8*) { 87 entry: 88 invoke void @f() 89 to label %exit unwind label %catch.pad 90 91 catch.pad: 92 %cs1 = catchswitch within none [label %catch.body, label %catch.body] unwind to caller 93 ; CHECK: catchswitch within none [label %catch.body] unwind to caller 94 95 catch.body: 96 %catch = catchpad within %cs1 [i8* null, i32 0, i8* null] 97 catchret from %catch to label %exit 98 99 exit: 100 ret void 101 } 102 103 ; CHECK-LABEL: define void @test7() 104 define void @test7() personality i8* bitcast (void ()* @Personality to i8*) { 105 entry: 106 invoke void @f() 107 to label %exit unwind label %catch.pad 108 109 catch.pad: 110 %cs1 = catchswitch within none [label %catch.body, label %catch.body2] unwind to caller 111 ; CHECK: catchswitch within none [label %catch.body] unwind to caller 112 113 catch.body: 114 %catch = catchpad within %cs1 [i8* null, i32 0, i8* null] 115 catchret from %catch to label %exit 116 117 catch.body2: 118 %catch2 = catchpad within %cs1 [i8* null, i32 0, i8* null] 119 catchret from %catch2 to label %exit 120 121 exit: 122 ret void 123 } 124 125 ; CHECK-LABEL: define void @test8() 126 define void @test8() personality i8* bitcast (void ()* @Personality to i8*) { 127 entry: 128 invoke void @f() 129 to label %exit unwind label %catch.pad 130 131 catch.pad: 132 %cs1 = catchswitch within none [label %catch.body, label %catch.body2] unwind to caller 133 ; CHECK: catchswitch within none [label %catch.body] unwind to caller 134 135 catch.body2: 136 %catch2 = catchpad within %cs1 [i8* null, i32 0, i8* null] 137 catchret from %catch2 to label %exit 138 139 catch.body: 140 %catch = catchpad within %cs1 [i8* null, i32 0, i8* null] 141 catchret from %catch to label %exit 142 143 exit: 144 ret void 145 } 146 147 ; CHECK-LABEL: define void @test9() 148 define void @test9() personality i8* bitcast (void ()* @Personality to i8*) { 149 entry: 150 invoke void @f() 151 to label %exit unwind label %catch.pad 152 153 catch.pad: 154 %cs1 = catchswitch within none [label %catch.body, label %catch.body2] unwind to caller 155 ; CHECK: catchswitch within none [label %catch.body, label %catch.body2] unwind to caller 156 157 catch.body: 158 %catch = catchpad within %cs1 [i8* null, i32 0, i8* null] 159 catchret from %catch to label %exit 160 161 catch.body2: 162 %catch2 = catchpad within %cs1 [i8* null, i32 64, i8* null] 163 catchret from %catch2 to label %exit 164 165 exit: 166 ret void 167 } 168