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