1 ; RUN: opt -mtriple=x86_64-pc-windows-msvc -winehprepare -S -o - < %s | FileCheck %s
3 ; This test is based on the following code:
35 ; This test is just checking for failures in processing the IR.
36 ; Extensive handler matching is not required.
38 ; ModuleID = 'cppeh-similar-catch-blocks.cpp'
39 target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
40 target triple = "x86_64-pc-windows-msvc"
42 %rtti.TypeDescriptor2 = type { i8**, i8*, [3 x i8] }
43 %eh.CatchHandlerType = type { i32, i8* }
44 %eh.CatchableType = type { i32, i32, i32, i32, i32, i32, i32 }
45 %eh.CatchableTypeArray.1 = type { i32, [1 x i32] }
46 %eh.ThrowInfo = type { i32, i32, i32, i32 }
48 $"\01??_R0H@8" = comdat any
50 $"\01??_R0D@8" = comdat any
52 $"_CT??_R0D@81" = comdat any
58 $"\01??_C@_03PJCJOCBM@?$CFc?6?$AA@" = comdat any
60 $"_CT??_R0H@84" = comdat any
66 $"\01??_C@_04MPPNMCOK@?4?4?4?6?$AA@" = comdat any
68 $"\01??_C@_03PMGGPEJJ@?$CFd?6?$AA@" = comdat any
70 @"\01??_7type_info@@6B@" = external constant i8*
71 @"\01??_R0H@8" = linkonce_odr global %rtti.TypeDescriptor2 { i8** @"\01??_7type_info@@6B@", i8* null, [3 x i8] c".H\00" }, comdat
72 @llvm.eh.handlertype.H.0 = private unnamed_addr constant %eh.CatchHandlerType { i32 0, i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*) }, section "llvm.metadata"
73 @"\01??_R0D@8" = linkonce_odr global %rtti.TypeDescriptor2 { i8** @"\01??_7type_info@@6B@", i8* null, [3 x i8] c".D\00" }, comdat
74 @llvm.eh.handlertype.D.0 = private unnamed_addr constant %eh.CatchHandlerType { i32 0, i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0D@8" to i8*) }, section "llvm.metadata"
75 @__ImageBase = external constant i8
76 @"_CT??_R0D@81" = linkonce_odr unnamed_addr constant %eh.CatchableType { i32 1, i32 trunc (i64 sub nuw nsw (i64 ptrtoint (%rtti.TypeDescriptor2* @"\01??_R0D@8" to i64), i64 ptrtoint (i8* @__ImageBase to i64)) to i32), i32 0, i32 -1, i32 0, i32 1, i32 0 }, section ".xdata", comdat
77 @_CTA1D = linkonce_odr unnamed_addr constant %eh.CatchableTypeArray.1 { i32 1, [1 x i32] [i32 trunc (i64 sub nuw nsw (i64 ptrtoint (%eh.CatchableType* @"_CT??_R0D@81" to i64), i64 ptrtoint (i8* @__ImageBase to i64)) to i32)] }, section ".xdata", comdat
78 @_TI1D = linkonce_odr unnamed_addr constant %eh.ThrowInfo { i32 0, i32 0, i32 0, i32 trunc (i64 sub nuw nsw (i64 ptrtoint (%eh.CatchableTypeArray.1* @_CTA1D to i64), i64 ptrtoint (i8* @__ImageBase to i64)) to i32) }, section ".xdata", comdat
79 @"\01??_C@_03PJCJOCBM@?$CFc?6?$AA@" = linkonce_odr unnamed_addr constant [4 x i8] c"%c\0A\00", comdat, align 1
80 @"_CT??_R0H@84" = linkonce_odr unnamed_addr constant %eh.CatchableType { i32 1, i32 trunc (i64 sub nuw nsw (i64 ptrtoint (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i64), i64 ptrtoint (i8* @__ImageBase to i64)) to i32), i32 0, i32 -1, i32 0, i32 4, i32 0 }, section ".xdata", comdat
81 @_CTA1H = linkonce_odr unnamed_addr constant %eh.CatchableTypeArray.1 { i32 1, [1 x i32] [i32 trunc (i64 sub nuw nsw (i64 ptrtoint (%eh.CatchableType* @"_CT??_R0H@84" to i64), i64 ptrtoint (i8* @__ImageBase to i64)) to i32)] }, section ".xdata", comdat
82 @_TI1H = linkonce_odr unnamed_addr constant %eh.ThrowInfo { i32 0, i32 0, i32 0, i32 trunc (i64 sub nuw nsw (i64 ptrtoint (%eh.CatchableTypeArray.1* @_CTA1H to i64), i64 ptrtoint (i8* @__ImageBase to i64)) to i32) }, section ".xdata", comdat
83 @"\01??_C@_04MPPNMCOK@?4?4?4?6?$AA@" = linkonce_odr unnamed_addr constant [5 x i8] c"...\0A\00", comdat, align 1
84 @"\01??_C@_03PMGGPEJJ@?$CFd?6?$AA@" = linkonce_odr unnamed_addr constant [4 x i8] c"%d\0A\00", comdat, align 1
86 ; This is just a minimal check to verify that main was handled by WinEHPrepare.
87 ; CHECK: define i32 @main()
89 ; CHECK: call void (...) @llvm.frameescape(i32* [[X_PTR:\%.+]], i32* [[X2_PTR:\%.+]], i8* [[C2_PTR:\%.+]], i8* [[C3_PTR:\%.+]], i8* [[C_PTR:\%.+]])
90 ; CHECK: invoke void @_CxxThrowException
93 ; Function Attrs: uwtable
94 define i32 @main() #0 personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
96 %retval = alloca i32, align 4
97 %tmp = alloca i8, align 1
98 %exn.slot = alloca i8*
99 %ehselector.slot = alloca i32
100 %c = alloca i8, align 1
101 %tmp3 = alloca i32, align 4
102 %x = alloca i32, align 4
103 %tmp20 = alloca i8, align 1
104 %c28 = alloca i8, align 1
105 %tmp34 = alloca i32, align 4
106 %c48 = alloca i8, align 1
107 %x56 = alloca i32, align 4
108 store i32 0, i32* %retval
109 store i8 97, i8* %tmp
110 invoke void @_CxxThrowException(i8* %tmp, %eh.ThrowInfo* @_TI1D) #4
111 to label %unreachable unwind label %lpad
113 lpad: ; preds = %entry
114 %0 = landingpad { i8*, i32 }
115 catch %eh.CatchHandlerType* @llvm.eh.handlertype.D.0
116 catch %eh.CatchHandlerType* @llvm.eh.handlertype.H.0
118 %1 = extractvalue { i8*, i32 } %0, 0
119 store i8* %1, i8** %exn.slot
120 %2 = extractvalue { i8*, i32 } %0, 1
121 store i32 %2, i32* %ehselector.slot
122 br label %catch.dispatch
124 catch.dispatch: ; preds = %lpad
125 %sel = load i32, i32* %ehselector.slot
126 %3 = call i32 @llvm.eh.typeid.for(i8* bitcast (%eh.CatchHandlerType* @llvm.eh.handlertype.D.0 to i8*)) #2
127 %matches = icmp eq i32 %sel, %3
128 br i1 %matches, label %catch, label %catch.dispatch5
130 catch: ; preds = %catch.dispatch
131 %exn = load i8*, i8** %exn.slot
132 call void @llvm.eh.begincatch(i8* %exn, i8* %c) #2
133 %4 = load i8, i8* %c, align 1
134 %conv = sext i8 %4 to i32
135 %call = invoke i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @"\01??_C@_03PJCJOCBM@?$CFc?6?$AA@", i32 0, i32 0), i32 %conv)
136 to label %invoke.cont unwind label %lpad2
138 invoke.cont: ; preds = %catch
139 call void @llvm.eh.endcatch() #2
142 try.cont: ; preds = %invoke.cont
143 store i32 1, i32* %tmp3
144 %5 = bitcast i32* %tmp3 to i8*
145 invoke void @_CxxThrowException(i8* %5, %eh.ThrowInfo* @_TI1H) #4
146 to label %unreachable unwind label %lpad4
148 lpad2: ; preds = %catch
149 %6 = landingpad { i8*, i32 }
150 catch %eh.CatchHandlerType* @llvm.eh.handlertype.H.0
152 %7 = extractvalue { i8*, i32 } %6, 0
153 store i8* %7, i8** %exn.slot
154 %8 = extractvalue { i8*, i32 } %6, 1
155 store i32 %8, i32* %ehselector.slot
156 call void @llvm.eh.endcatch() #2
157 br label %catch.dispatch5
159 lpad4: ; preds = %try.cont
160 %9 = landingpad { i8*, i32 }
161 catch %eh.CatchHandlerType* @llvm.eh.handlertype.H.0
163 %10 = extractvalue { i8*, i32 } %9, 0
164 store i8* %10, i8** %exn.slot
165 %11 = extractvalue { i8*, i32 } %9, 1
166 store i32 %11, i32* %ehselector.slot
167 br label %catch.dispatch5
169 catch.dispatch5: ; preds = %lpad4, %lpad2, %catch.dispatch
170 %sel6 = load i32, i32* %ehselector.slot
171 %12 = call i32 @llvm.eh.typeid.for(i8* bitcast (%eh.CatchHandlerType* @llvm.eh.handlertype.H.0 to i8*)) #2
172 %matches7 = icmp eq i32 %sel6, %12
173 br i1 %matches7, label %catch13, label %catch8
175 catch13: ; preds = %catch.dispatch5
176 %exn14 = load i8*, i8** %exn.slot
177 %13 = bitcast i32* %x to i8*
178 call void @llvm.eh.begincatch(i8* %exn14, i8* %13) #2
179 %14 = load i32, i32* %x, align 4
180 %call18 = invoke i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @"\01??_C@_03PMGGPEJJ@?$CFd?6?$AA@", i32 0, i32 0), i32 %14)
181 to label %invoke.cont17 unwind label %lpad16
183 invoke.cont17: ; preds = %catch13
184 call void @llvm.eh.endcatch() #2
187 try.cont19: ; preds = %invoke.cont17, %invoke.cont11
188 store i8 98, i8* %tmp20
189 invoke void @_CxxThrowException(i8* %tmp20, %eh.ThrowInfo* @_TI1D) #4
190 to label %unreachable unwind label %lpad21
192 catch8: ; preds = %catch.dispatch5
193 %exn9 = load i8*, i8** %exn.slot
194 call void @llvm.eh.begincatch(i8* %exn9, i8* null) #2
195 %call12 = invoke i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @"\01??_C@_04MPPNMCOK@?4?4?4?6?$AA@", i32 0, i32 0))
196 to label %invoke.cont11 unwind label %lpad10
198 invoke.cont11: ; preds = %catch8
199 call void @llvm.eh.endcatch() #2
202 lpad10: ; preds = %catch8
203 %15 = landingpad { i8*, i32 }
205 %16 = extractvalue { i8*, i32 } %15, 0
206 store i8* %16, i8** %exn.slot
207 %17 = extractvalue { i8*, i32 } %15, 1
208 store i32 %17, i32* %ehselector.slot
209 call void @llvm.eh.endcatch() #2
212 lpad16: ; preds = %catch13
213 %18 = landingpad { i8*, i32 }
215 %19 = extractvalue { i8*, i32 } %18, 0
216 store i8* %19, i8** %exn.slot
217 %20 = extractvalue { i8*, i32 } %18, 1
218 store i32 %20, i32* %ehselector.slot
219 call void @llvm.eh.endcatch() #2
222 lpad21: ; preds = %try.cont19
223 %21 = landingpad { i8*, i32 }
224 catch i8* bitcast (%eh.CatchHandlerType* @llvm.eh.handlertype.D.0 to i8*)
225 catch i8* bitcast (%eh.CatchHandlerType* @llvm.eh.handlertype.H.0 to i8*)
227 %22 = extractvalue { i8*, i32 } %21, 0
228 store i8* %22, i8** %exn.slot
229 %23 = extractvalue { i8*, i32 } %21, 1
230 store i32 %23, i32* %ehselector.slot
231 br label %catch.dispatch22
233 catch.dispatch22: ; preds = %lpad21
234 %sel23 = load i32, i32* %ehselector.slot
235 %24 = call i32 @llvm.eh.typeid.for(i8* bitcast (%eh.CatchHandlerType* @llvm.eh.handlertype.D.0 to i8*)) #2
236 %matches24 = icmp eq i32 %sel23, %24
237 br i1 %matches24, label %catch25, label %catch.dispatch36
239 catch25: ; preds = %catch.dispatch22
240 %exn26 = load i8*, i8** %exn.slot
241 call void @llvm.eh.begincatch(i8* %exn26, i8* %c28) #2
242 %25 = load i8, i8* %c28, align 1
243 %conv29 = sext i8 %25 to i32
244 %call32 = invoke i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @"\01??_C@_03PJCJOCBM@?$CFc?6?$AA@", i32 0, i32 0), i32 %conv29)
245 to label %invoke.cont31 unwind label %lpad30
247 invoke.cont31: ; preds = %catch25
248 call void @llvm.eh.endcatch() #2
251 try.cont33: ; preds = %invoke.cont31
252 store i32 2, i32* %tmp34
253 %26 = bitcast i32* %tmp34 to i8*
254 invoke void @_CxxThrowException(i8* %26, %eh.ThrowInfo* @_TI1H) #4
255 to label %unreachable unwind label %lpad35
257 lpad30: ; preds = %catch25
258 %27 = landingpad { i8*, i32 }
259 catch i8* bitcast (%eh.CatchHandlerType* @llvm.eh.handlertype.H.0 to i8*)
260 catch i8* bitcast (%eh.CatchHandlerType* @llvm.eh.handlertype.D.0 to i8*)
262 %28 = extractvalue { i8*, i32 } %27, 0
263 store i8* %28, i8** %exn.slot
264 %29 = extractvalue { i8*, i32 } %27, 1
265 store i32 %29, i32* %ehselector.slot
266 call void @llvm.eh.endcatch() #2
267 br label %catch.dispatch36
269 lpad35: ; preds = %try.cont33
270 %30 = landingpad { i8*, i32 }
271 catch i8* bitcast (%eh.CatchHandlerType* @llvm.eh.handlertype.H.0 to i8*)
272 catch i8* bitcast (%eh.CatchHandlerType* @llvm.eh.handlertype.D.0 to i8*)
274 %31 = extractvalue { i8*, i32 } %30, 0
275 store i8* %31, i8** %exn.slot
276 %32 = extractvalue { i8*, i32 } %30, 1
277 store i32 %32, i32* %ehselector.slot
278 br label %catch.dispatch36
280 catch.dispatch36: ; preds = %lpad35, %lpad30, %catch.dispatch22
281 %sel37 = load i32, i32* %ehselector.slot
282 %33 = call i32 @llvm.eh.typeid.for(i8* bitcast (%eh.CatchHandlerType* @llvm.eh.handlertype.H.0 to i8*)) #2
283 %matches38 = icmp eq i32 %sel37, %33
284 br i1 %matches38, label %catch53, label %catch.fallthrough
286 catch53: ; preds = %catch.dispatch36
287 %exn54 = load i8*, i8** %exn.slot
288 %34 = bitcast i32* %x56 to i8*
289 call void @llvm.eh.begincatch(i8* %exn54, i8* %34) #2
290 %35 = load i32, i32* %x56, align 4
291 %call59 = invoke i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @"\01??_C@_03PMGGPEJJ@?$CFd?6?$AA@", i32 0, i32 0), i32 %35)
292 to label %invoke.cont58 unwind label %lpad57
294 invoke.cont58: ; preds = %catch53
295 call void @llvm.eh.endcatch() #2
298 try.cont60: ; preds = %invoke.cont58, %invoke.cont51, %invoke.cont43
301 catch.fallthrough: ; preds = %catch.dispatch36
302 %36 = call i32 @llvm.eh.typeid.for(i8* bitcast (%eh.CatchHandlerType* @llvm.eh.handlertype.D.0 to i8*)) #2
303 %matches39 = icmp eq i32 %sel37, %36
304 br i1 %matches39, label %catch45, label %catch40
306 catch45: ; preds = %catch.fallthrough
307 %exn46 = load i8*, i8** %exn.slot
308 call void @llvm.eh.begincatch(i8* %exn46, i8* %c48) #2
309 %37 = load i8, i8* %c48, align 1
310 %conv49 = sext i8 %37 to i32
311 %call52 = invoke i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @"\01??_C@_03PJCJOCBM@?$CFc?6?$AA@", i32 0, i32 0), i32 %conv49)
312 to label %invoke.cont51 unwind label %lpad50
314 invoke.cont51: ; preds = %catch45
315 call void @llvm.eh.endcatch() #2
318 catch40: ; preds = %catch.fallthrough
319 %exn41 = load i8*, i8** %exn.slot
320 call void @llvm.eh.begincatch(i8* %exn41, i8* null) #2
321 %call44 = invoke i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @"\01??_C@_04MPPNMCOK@?4?4?4?6?$AA@", i32 0, i32 0))
322 to label %invoke.cont43 unwind label %lpad42
324 invoke.cont43: ; preds = %catch40
325 call void @llvm.eh.endcatch() #2
328 lpad42: ; preds = %catch40
329 %38 = landingpad { i8*, i32 }
331 %39 = extractvalue { i8*, i32 } %38, 0
332 store i8* %39, i8** %exn.slot
333 %40 = extractvalue { i8*, i32 } %38, 1
334 store i32 %40, i32* %ehselector.slot
335 call void @llvm.eh.endcatch() #2
338 lpad50: ; preds = %catch45
339 %41 = landingpad { i8*, i32 }
341 %42 = extractvalue { i8*, i32 } %41, 0
342 store i8* %42, i8** %exn.slot
343 %43 = extractvalue { i8*, i32 } %41, 1
344 store i32 %43, i32* %ehselector.slot
345 call void @llvm.eh.endcatch() #2
348 lpad57: ; preds = %catch53
349 %44 = landingpad { i8*, i32 }
351 %45 = extractvalue { i8*, i32 } %44, 0
352 store i8* %45, i8** %exn.slot
353 %46 = extractvalue { i8*, i32 } %44, 1
354 store i32 %46, i32* %ehselector.slot
355 call void @llvm.eh.endcatch() #2
358 eh.resume: ; preds = %lpad57, %lpad50, %lpad42, %lpad16, %lpad10
359 %exn61 = load i8*, i8** %exn.slot
360 %sel62 = load i32, i32* %ehselector.slot
361 %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn61, 0
362 %lpad.val63 = insertvalue { i8*, i32 } %lpad.val, i32 %sel62, 1
363 resume { i8*, i32 } %lpad.val63
365 unreachable: ; preds = %try.cont33, %try.cont19, %try.cont, %entry
369 declare void @_CxxThrowException(i8*, %eh.ThrowInfo*)
371 declare i32 @__CxxFrameHandler3(...)
373 ; Function Attrs: nounwind readnone
374 declare i32 @llvm.eh.typeid.for(i8*) #1
376 ; Function Attrs: nounwind
377 declare void @llvm.eh.begincatch(i8* nocapture, i8* nocapture) #2
379 declare i32 @printf(i8*, ...) #3
381 ; Function Attrs: nounwind
382 declare void @llvm.eh.endcatch() #2
384 attributes #0 = { uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "unsafe-fp-math"="false" "use-soft-float"="false" }
385 attributes #1 = { nounwind readnone }
386 attributes #2 = { nounwind }
387 attributes #3 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "unsafe-fp-math"="false" "use-soft-float"="false" }
388 attributes #4 = { noreturn }
390 !llvm.module.flags = !{!0}
393 !0 = !{i32 1, !"PIC Level", i32 2}
394 !1 = !{!"clang version 3.7.0 (trunk 235214) (llvm/trunk 235213)"}