1 ; RUN: opt -lint -disable-output < %s 2>&1 | FileCheck %s
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.
7 target triple = "x86_64-pc-windows-msvc"
9 declare void @llvm.eh.begincatch(i8*, i8*)
11 declare void @llvm.eh.endcatch()
13 @_ZTIi = external constant i8*
15 ; Function Attrs: uwtable
16 define void @test_missing_endcatch() personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
17 ; CHECK: Some paths from llvm.eh.begincatch may not reach llvm.eh.endcatch
18 ; CHECK-NEXT: call void @llvm.eh.begincatch(i8* %exn, i8* null)
20 invoke void @_Z9may_throwv()
21 to label %try.cont unwind label %lpad
23 lpad: ; preds = %entry
24 %0 = landingpad { i8*, i32 }
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
32 catch: ; preds = %lpad
33 call void @llvm.eh.begincatch(i8* %exn, i8* null)
34 call void @_Z10handle_intv()
35 br label %invoke.cont2
37 invoke.cont2: ; preds = %catch
40 try.cont: ; preds = %invoke.cont2, %entry
43 eh.resume: ; preds = %catch.dispatch
44 resume { i8*, i32 } %0
47 ; Function Attrs: uwtable
48 define void @test_missing_begincatch() personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
49 ; CHECK: llvm.eh.endcatch may be reachable without passing llvm.eh.begincatch
50 ; CHECK-NEXT: call void @llvm.eh.endcatch()
52 invoke void @_Z9may_throwv()
53 to label %try.cont unwind label %lpad
55 lpad: ; preds = %entry
56 %0 = landingpad { i8*, i32 }
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
64 catch: ; preds = %lpad
65 call void @_Z10handle_intv()
66 br label %invoke.cont2
68 invoke.cont2: ; preds = %catch
69 call void @llvm.eh.endcatch()
72 try.cont: ; preds = %invoke.cont2, %entry
75 eh.resume: ; preds = %catch.dispatch
76 resume { i8*, i32 } %0
79 ; Function Attrs: uwtable
80 define void @test_multiple_begin() personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
81 ; CHECK: llvm.eh.begincatch may be called a second time before llvm.eh.endcatch
82 ; CHECK-NEXT: call void @llvm.eh.begincatch(i8* %exn, i8* null)
83 ; CHECK-NEXT: call void @llvm.eh.begincatch(i8* %exn, i8* null)
85 invoke void @_Z9may_throwv()
86 to label %try.cont unwind label %lpad
88 lpad: ; preds = %entry
89 %0 = landingpad { i8*, i32 }
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
97 catch: ; preds = %lpad
98 call void @llvm.eh.begincatch(i8* %exn, i8* null)
99 call void @_Z10handle_intv()
100 br label %invoke.cont2
102 invoke.cont2: ; preds = %catch
103 call void @llvm.eh.begincatch(i8* %exn, i8* null)
104 call void @llvm.eh.endcatch()
107 try.cont: ; preds = %invoke.cont2, %entry
110 eh.resume: ; preds = %catch.dispatch
111 resume { i8*, i32 } %0
114 ; Function Attrs: uwtable
115 define void @test_multiple_end() personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
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()
120 invoke void @_Z9may_throwv()
121 to label %try.cont unwind label %lpad
123 lpad: ; preds = %entry
124 %0 = landingpad { i8*, i32 }
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
132 catch: ; preds = %lpad
133 call void @llvm.eh.begincatch(i8* %exn, i8* null)
134 call void @_Z10handle_intv()
135 call void @llvm.eh.endcatch()
136 br label %invoke.cont2
138 invoke.cont2: ; preds = %catch
139 call void @llvm.eh.endcatch()
142 try.cont: ; preds = %invoke.cont2, %entry
145 eh.resume: ; preds = %catch.dispatch
146 resume { i8*, i32 } %0
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: call void @llvm.eh.begincatch(i8* %exn, i8* null)
156 call void @llvm.eh.begincatch(i8* %exn, i8* null)
157 call void @_Z10handle_intv()
158 br label %invoke.cont2
160 invoke.cont2: ; preds = %catch
161 call void @llvm.eh.endcatch()
164 try.cont: ; preds = %invoke.cont2, %entry
168 ; Function Attrs: uwtable
169 define void @test_branch_to_begincatch_with_no_lpad(i32 %fake.sel) personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
170 ; CHECK: llvm.eh.begincatch may be reachable without passing a landingpad
171 ; CHECK-NEXT: call void @llvm.eh.begincatch(i8* %exn2, i8* null)
173 %fake.exn = alloca i8
174 invoke void @_Z9may_throwv()
175 to label %catch unwind label %lpad
177 lpad: ; preds = %entry
178 %0 = landingpad { i8*, i32 }
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
186 invoke void @_Z9may_throwv()
187 to label %try.cont unwind label %lpad
189 catch: ; preds = %lpad, %entry
190 %exn2 = phi i8* [%exn, %lpad], [%fake.exn, %entry]
191 %sel2 = phi i32 [%sel, %lpad], [%fake.sel, %entry]
192 call void @llvm.eh.begincatch(i8* %exn2, i8* null)
193 call void @_Z10handle_intv()
194 %matches1 = icmp eq i32 %sel2, 0
195 br i1 %matches1, label %invoke.cont2, label %invoke.cont3
197 invoke.cont2: ; preds = %catch
198 call void @llvm.eh.endcatch()
201 invoke.cont3: ; preds = %catch
202 call void @llvm.eh.endcatch()
205 try.cont: ; preds = %invoke.cont2
208 eh.resume: ; preds = %catch.dispatch
209 %lpad.val = insertvalue { i8*, i32 } undef, i32 0, 1
210 resume { i8*, i32 } %lpad.val
213 ; Function Attrs: uwtable
214 define void @test_branch_missing_endcatch() personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
215 ; CHECK: Some paths from llvm.eh.begincatch may not reach llvm.eh.endcatch
216 ; CHECK-NEXT: call void @llvm.eh.begincatch(i8* %exn2, i8* null)
218 invoke void @_Z9may_throwv()
219 to label %invoke.cont unwind label %lpad
222 invoke void @_Z9may_throwv()
223 to label %invoke.cont unwind label %lpad1
225 lpad: ; preds = %entry
226 %0 = landingpad { i8*, i32 }
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
234 invoke void @_Z9may_throwv()
235 to label %try.cont unwind label %lpad
237 lpad1: ; preds = %entry
238 %l1.0 = landingpad { i8*, i32 }
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
247 catch: ; preds = %lpad, %lpad1
248 %exn2 = phi i8* [%exn, %lpad], [%exn1, %lpad1]
249 %sel2 = phi i32 [%sel, %lpad], [%sel1, %lpad1]
250 call void @llvm.eh.begincatch(i8* %exn2, i8* null)
251 call void @_Z10handle_intv()
252 %matches1 = icmp eq i32 %sel2, 0
253 br i1 %matches1, label %invoke.cont2, label %invoke.cont3
255 invoke.cont2: ; preds = %catch
256 call void @llvm.eh.endcatch()
259 invoke.cont3: ; preds = %catch
262 try.cont: ; preds = %invoke.cont2, %entry
265 eh.resume: ; preds = %catch.dispatch
266 %lpad.val = insertvalue { i8*, i32 } undef, i32 0, 1
267 resume { i8*, i32 } %lpad.val
270 declare void @_Z9may_throwv()
272 declare i32 @__CxxFrameHandler3(...)
274 ; Function Attrs: nounwind readnone
275 declare i32 @llvm.eh.typeid.for(i8*)
277 declare void @_Z10handle_intv()