Andrew Kaylor | 78b53db | 2015-02-10 19:52:43 +0000 | [diff] [blame] | 1 | ; RUN: opt -lint -disable-output < %s 2>&1 | FileCheck %s |
| 2 | |
| 3 | ; This test is meant to prove that the Verifier is able to identify a variety |
| 4 | ; of errors with the llvm.eh.begincatch and llvm.eh.endcatch intrinsics. |
| 5 | ; See cppeh-catch-intrinsics-clean for correct uses. |
| 6 | |
| 7 | target triple = "x86_64-pc-windows-msvc" |
| 8 | |
| 9 | declare i8* @llvm.eh.begincatch(i8*) |
| 10 | |
| 11 | declare void @llvm.eh.endcatch() |
| 12 | |
| 13 | @_ZTIi = external constant i8* |
| 14 | |
| 15 | ; Function Attrs: uwtable |
| 16 | define void @test_missing_endcatch() { |
| 17 | ; CHECK: Some paths from llvm.eh.begincatch may not reach llvm.eh.endcatch |
| 18 | ; CHECK-NEXT: %2 = call i8* @llvm.eh.begincatch(i8* %exn) |
| 19 | entry: |
| 20 | invoke void @_Z9may_throwv() |
| 21 | to label %try.cont unwind label %lpad |
| 22 | |
| 23 | lpad: ; preds = %entry |
| 24 | %0 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) |
| 25 | catch i8* bitcast (i8** @_ZTIi to i8*) |
| 26 | %exn = extractvalue { i8*, i32 } %0, 0 |
| 27 | %sel = extractvalue { i8*, i32 } %0, 1 |
| 28 | %1 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) |
| 29 | %matches = icmp eq i32 %sel, %1 |
| 30 | br i1 %matches, label %catch, label %eh.resume |
| 31 | |
| 32 | catch: ; preds = %lpad |
| 33 | %2 = call i8* @llvm.eh.begincatch(i8* %exn) |
| 34 | call void @_Z10handle_intv() |
| 35 | br label %invoke.cont2 |
| 36 | |
| 37 | invoke.cont2: ; preds = %catch |
| 38 | br label %try.cont |
| 39 | |
| 40 | try.cont: ; preds = %invoke.cont2, %entry |
| 41 | ret void |
| 42 | |
| 43 | eh.resume: ; preds = %catch.dispatch |
| 44 | resume { i8*, i32 } %0 |
| 45 | } |
| 46 | |
| 47 | ; Function Attrs: uwtable |
| 48 | define void @test_missing_begincatch() { |
| 49 | ; CHECK: llvm.eh.endcatch may be reachable without passing llvm.eh.begincatch |
| 50 | ; CHECK-NEXT: call void @llvm.eh.endcatch() |
| 51 | entry: |
| 52 | invoke void @_Z9may_throwv() |
| 53 | to label %try.cont unwind label %lpad |
| 54 | |
| 55 | lpad: ; preds = %entry |
| 56 | %0 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) |
| 57 | catch i8* bitcast (i8** @_ZTIi to i8*) |
| 58 | %exn = extractvalue { i8*, i32 } %0, 0 |
| 59 | %sel = extractvalue { i8*, i32 } %0, 1 |
| 60 | %1 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) |
| 61 | %matches = icmp eq i32 %sel, %1 |
| 62 | br i1 %matches, label %catch, label %eh.resume |
| 63 | |
| 64 | catch: ; preds = %lpad |
| 65 | call void @_Z10handle_intv() |
| 66 | br label %invoke.cont2 |
| 67 | |
| 68 | invoke.cont2: ; preds = %catch |
| 69 | call void @llvm.eh.endcatch() |
| 70 | br label %try.cont |
| 71 | |
| 72 | try.cont: ; preds = %invoke.cont2, %entry |
| 73 | ret void |
| 74 | |
| 75 | eh.resume: ; preds = %catch.dispatch |
| 76 | resume { i8*, i32 } %0 |
| 77 | } |
| 78 | |
| 79 | ; Function Attrs: uwtable |
| 80 | define void @test_multiple_begin() { |
| 81 | ; CHECK: llvm.eh.begincatch may be called a second time before llvm.eh.endcatch |
| 82 | ; CHECK-NEXT: %2 = call i8* @llvm.eh.begincatch(i8* %exn) |
| 83 | ; CHECK-NEXT: %3 = call i8* @llvm.eh.begincatch(i8* %exn) |
| 84 | entry: |
| 85 | invoke void @_Z9may_throwv() |
| 86 | to label %try.cont unwind label %lpad |
| 87 | |
| 88 | lpad: ; preds = %entry |
| 89 | %0 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) |
| 90 | catch i8* bitcast (i8** @_ZTIi to i8*) |
| 91 | %exn = extractvalue { i8*, i32 } %0, 0 |
| 92 | %sel = extractvalue { i8*, i32 } %0, 1 |
| 93 | %1 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) |
| 94 | %matches = icmp eq i32 %sel, %1 |
| 95 | br i1 %matches, label %catch, label %eh.resume |
| 96 | |
| 97 | catch: ; preds = %lpad |
| 98 | %2 = call i8* @llvm.eh.begincatch(i8* %exn) |
| 99 | call void @_Z10handle_intv() |
| 100 | br label %invoke.cont2 |
| 101 | |
| 102 | invoke.cont2: ; preds = %catch |
| 103 | %3 = call i8* @llvm.eh.begincatch(i8* %exn) |
| 104 | call void @llvm.eh.endcatch() |
| 105 | br label %try.cont |
| 106 | |
| 107 | try.cont: ; preds = %invoke.cont2, %entry |
| 108 | ret void |
| 109 | |
| 110 | eh.resume: ; preds = %catch.dispatch |
| 111 | resume { i8*, i32 } %0 |
| 112 | } |
| 113 | |
| 114 | ; Function Attrs: uwtable |
| 115 | define void @test_multiple_end() { |
| 116 | ; CHECK: llvm.eh.endcatch may be called a second time after llvm.eh.begincatch |
| 117 | ; CHECK-NEXT: call void @llvm.eh.endcatch() |
| 118 | ; CHECK-NEXT: call void @llvm.eh.endcatch() |
| 119 | entry: |
| 120 | invoke void @_Z9may_throwv() |
| 121 | to label %try.cont unwind label %lpad |
| 122 | |
| 123 | lpad: ; preds = %entry |
| 124 | %0 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) |
| 125 | catch i8* bitcast (i8** @_ZTIi to i8*) |
| 126 | %exn = extractvalue { i8*, i32 } %0, 0 |
| 127 | %sel = extractvalue { i8*, i32 } %0, 1 |
| 128 | %1 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) |
| 129 | %matches = icmp eq i32 %sel, %1 |
| 130 | br i1 %matches, label %catch, label %eh.resume |
| 131 | |
| 132 | catch: ; preds = %lpad |
| 133 | %2 = call i8* @llvm.eh.begincatch(i8* %exn) |
| 134 | call void @_Z10handle_intv() |
| 135 | call void @llvm.eh.endcatch() |
| 136 | br label %invoke.cont2 |
| 137 | |
| 138 | invoke.cont2: ; preds = %catch |
| 139 | call void @llvm.eh.endcatch() |
| 140 | br label %try.cont |
| 141 | |
| 142 | try.cont: ; preds = %invoke.cont2, %entry |
| 143 | ret void |
| 144 | |
| 145 | eh.resume: ; preds = %catch.dispatch |
| 146 | resume { i8*, i32 } %0 |
| 147 | } |
| 148 | |
| 149 | |
| 150 | ; Function Attrs: uwtable |
| 151 | define void @test_begincatch_without_lpad() { |
| 152 | ; CHECK: llvm.eh.begincatch may be reachable without passing a landingpad |
| 153 | ; CHECK-NEXT: %0 = call i8* @llvm.eh.begincatch(i8* %exn) |
| 154 | entry: |
| 155 | %exn = alloca i8 |
| 156 | %0 = call i8* @llvm.eh.begincatch(i8* %exn) |
| 157 | call void @_Z10handle_intv() |
| 158 | br label %invoke.cont2 |
| 159 | |
| 160 | invoke.cont2: ; preds = %catch |
| 161 | call void @llvm.eh.endcatch() |
| 162 | br label %try.cont |
| 163 | |
| 164 | try.cont: ; preds = %invoke.cont2, %entry |
| 165 | ret void |
| 166 | } |
| 167 | |
| 168 | ; Function Attrs: uwtable |
| 169 | define void @test_branch_to_begincatch_with_no_lpad(i32 %fake.sel) { |
| 170 | ; CHECK: llvm.eh.begincatch may be reachable without passing a landingpad |
| 171 | ; CHECK-NEXT: %3 = call i8* @llvm.eh.begincatch(i8* %exn2) |
| 172 | entry: |
| 173 | %fake.exn = alloca i8 |
| 174 | invoke void @_Z9may_throwv() |
| 175 | to label %catch unwind label %lpad |
| 176 | |
| 177 | lpad: ; preds = %entry |
| 178 | %0 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) |
| 179 | catch i8* bitcast (i8** @_ZTIi to i8*) |
| 180 | %exn = extractvalue { i8*, i32 } %0, 0 |
| 181 | %sel = extractvalue { i8*, i32 } %0, 1 |
| 182 | %1 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) |
| 183 | %matches = icmp eq i32 %sel, %1 |
| 184 | br i1 %matches, label %catch, label %eh.resume |
| 185 | |
| 186 | invoke void @_Z9may_throwv() |
| 187 | to label %try.cont unwind label %lpad |
| 188 | |
| 189 | catch: ; preds = %lpad, %entry |
| 190 | %exn2 = phi i8* [%exn, %lpad], [%fake.exn, %entry] |
| 191 | %sel2 = phi i32 [%sel, %lpad], [%fake.sel, %entry] |
| 192 | %3 = call i8* @llvm.eh.begincatch(i8* %exn2) |
| 193 | call void @_Z10handle_intv() |
| 194 | %matches1 = icmp eq i32 %sel2, 0 |
| 195 | br i1 %matches1, label %invoke.cont2, label %invoke.cont3 |
| 196 | |
| 197 | invoke.cont2: ; preds = %catch |
| 198 | call void @llvm.eh.endcatch() |
| 199 | br label %try.cont |
| 200 | |
| 201 | invoke.cont3: ; preds = %catch |
| 202 | call void @llvm.eh.endcatch() |
| 203 | br label %eh.resume |
| 204 | |
| 205 | try.cont: ; preds = %invoke.cont2 |
| 206 | ret void |
| 207 | |
| 208 | eh.resume: ; preds = %catch.dispatch |
| 209 | %lpad.val = insertvalue { i8*, i32 } undef, i32 0, 1 |
| 210 | resume { i8*, i32 } %lpad.val |
| 211 | } |
| 212 | |
| 213 | ; Function Attrs: uwtable |
| 214 | define void @test_branch_missing_endcatch() { |
| 215 | ; CHECK: Some paths from llvm.eh.begincatch may not reach llvm.eh.endcatch |
| 216 | ; CHECK-NEXT: %3 = call i8* @llvm.eh.begincatch(i8* %exn2) |
| 217 | entry: |
| 218 | invoke void @_Z9may_throwv() |
| 219 | to label %invoke.cont unwind label %lpad |
| 220 | |
| 221 | invoke.cont: |
| 222 | invoke void @_Z9may_throwv() |
| 223 | to label %invoke.cont unwind label %lpad1 |
| 224 | |
| 225 | lpad: ; preds = %entry |
| 226 | %0 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) |
| 227 | catch i8* bitcast (i8** @_ZTIi to i8*) |
| 228 | %exn = extractvalue { i8*, i32 } %0, 0 |
| 229 | %sel = extractvalue { i8*, i32 } %0, 1 |
| 230 | %1 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) |
| 231 | %matches = icmp eq i32 %sel, %1 |
| 232 | br i1 %matches, label %catch, label %eh.resume |
| 233 | |
| 234 | invoke void @_Z9may_throwv() |
| 235 | to label %try.cont unwind label %lpad |
| 236 | |
| 237 | lpad1: ; preds = %entry |
| 238 | %l1.0 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) |
| 239 | cleanup |
| 240 | catch i8* bitcast (i8** @_ZTIi to i8*) |
| 241 | %exn1 = extractvalue { i8*, i32 } %l1.0, 0 |
| 242 | %sel1 = extractvalue { i8*, i32 } %l1.0, 1 |
| 243 | %l1.1 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) |
| 244 | %matchesl1 = icmp eq i32 %sel1, %l1.1 |
| 245 | br i1 %matchesl1, label %catch, label %eh.resume |
| 246 | |
| 247 | catch: ; preds = %lpad, %lpad1 |
| 248 | %exn2 = phi i8* [%exn, %lpad], [%exn1, %lpad1] |
| 249 | %sel2 = phi i32 [%sel, %lpad], [%sel1, %lpad1] |
| 250 | %3 = call i8* @llvm.eh.begincatch(i8* %exn2) |
| 251 | call void @_Z10handle_intv() |
| 252 | %matches1 = icmp eq i32 %sel2, 0 |
| 253 | br i1 %matches1, label %invoke.cont2, label %invoke.cont3 |
| 254 | |
| 255 | invoke.cont2: ; preds = %catch |
| 256 | call void @llvm.eh.endcatch() |
| 257 | br label %try.cont |
| 258 | |
| 259 | invoke.cont3: ; preds = %catch |
| 260 | br label %eh.resume |
| 261 | |
| 262 | try.cont: ; preds = %invoke.cont2, %entry |
| 263 | ret void |
| 264 | |
| 265 | eh.resume: ; preds = %catch.dispatch |
| 266 | %lpad.val = insertvalue { i8*, i32 } undef, i32 0, 1 |
| 267 | resume { i8*, i32 } %lpad.val |
| 268 | } |
| 269 | |
| 270 | declare void @_Z9may_throwv() |
| 271 | |
| 272 | declare i32 @__CxxFrameHandler3(...) |
| 273 | |
| 274 | ; Function Attrs: nounwind readnone |
| 275 | declare i32 @llvm.eh.typeid.for(i8*) |
| 276 | |
| 277 | declare void @_Z10handle_intv() |
| 278 | |