1 ; RUN: opt -mtriple=x86_64-pc-windows-msvc -winehprepare -S -o - < %s | FileCheck %s
3 ; This test was generated from the following source:
19 ; The code above was compiled with the -O2 option.
21 ; ModuleID = 'catch-unwind.cpp'
22 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
23 target triple = "x86_64-pc-windows-msvc"
25 %rtti.TypeDescriptor2 = type { i8**, i8*, [3 x i8] }
26 %class.SomeClass = type { i8 }
28 $"\01??_R0H@8" = comdat any
30 @"\01??_7type_info@@6B@" = external constant i8*
31 @"\01??_R0H@8" = linkonce_odr global %rtti.TypeDescriptor2 { i8** @"\01??_7type_info@@6B@", i8* null, [3 x i8] c".H\00" }, comdat
34 ; CHECK-LABEL: define void @"\01?test@@YAXXZ"() #0 personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
36 ; CHECK: [[OBJ_PTR:\%.+]] = alloca %class.SomeClass
37 ; CHECK: [[TMP0:\%.+]] = alloca i32, align 4
38 ; CHECK: [[TMP1:\%.+]] = alloca i32, align 4
39 ; CHECK: call void (...) @llvm.frameescape(i32* [[TMP1]], %class.SomeClass* [[OBJ_PTR]], i32* [[TMP0]])
40 ; CHECK: %call = invoke %class.SomeClass* @"\01??0SomeClass@@QEAA@XZ"(%class.SomeClass* %obj)
41 ; CHECK: to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]*]]
43 ; Function Attrs: uwtable
44 define void @"\01?test@@YAXXZ"() #0 personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
46 %obj = alloca %class.SomeClass, align 1
47 %0 = alloca i32, align 4
48 %1 = alloca i32, align 4
49 %call = invoke %class.SomeClass* @"\01??0SomeClass@@QEAA@XZ"(%class.SomeClass* %obj)
50 to label %invoke.cont unwind label %lpad
53 ; CHECK: invoke void @"\01?may_throw@@YAXXZ"()
54 ; CHECK: to label %invoke.cont2 unwind label %[[LPAD1_LABEL:lpad[0-9]*]]
56 invoke.cont: ; preds = %entry
57 invoke void @"\01?may_throw@@YAXXZ"()
58 to label %invoke.cont2 unwind label %lpad1
60 ; CHECK: invoke.cont2:
61 ; CHECK: invoke void @"\01?may_throw@@YAXXZ"()
62 ; CHECK: to label %try.cont unwind label %[[LPAD3_LABEL:lpad[0-9]*]]
64 invoke.cont2: ; preds = %invoke.cont
65 invoke void @"\01?may_throw@@YAXXZ"()
66 to label %try.cont unwind label %lpad3
68 ; CHECK: [[LPAD_LABEL]]:{{[ ]+}}; preds = %entry
69 ; CHECK: [[LPAD_VAL:\%.+]] = landingpad { i8*, i32 }
70 ; CHECK-NEXT: catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)
71 ; CHECK-NEXT: [[RECOVER:\%.+]] = call i8* (...) @llvm.eh.actions(i32 1, i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*), i32 0, i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch")
72 ; CHECK-NEXT: indirectbr i8* [[RECOVER]], [label %try.cont15]
74 lpad: ; preds = %entry
75 %2 = landingpad { i8*, i32 }
76 catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)
77 %3 = extractvalue { i8*, i32 } %2, 0
78 %4 = extractvalue { i8*, i32 } %2, 1
79 br label %catch.dispatch7
81 ; CHECK: [[LPAD1_LABEL]]:{{[ ]+}}; preds = %invoke.cont
82 ; CHECK: [[LPAD1_VAL:\%.+]] = landingpad { i8*, i32 }
84 ; CHECK-NEXT: catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)
85 ; CHECK-NEXT: [[RECOVER1:\%.+]] = call i8* (...) @llvm.eh.actions(i32 0, void (i8*, i8*)* @"\01?test@@YAXXZ.cleanup", i32 1, i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*), i32 0, i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch")
86 ; CHECK-NEXT: indirectbr i8* [[RECOVER1]], [label %try.cont15]
88 lpad1: ; preds = %invoke.cont
89 %5 = landingpad { i8*, i32 }
91 catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)
92 %6 = extractvalue { i8*, i32 } %5, 0
93 %7 = extractvalue { i8*, i32 } %5, 1
96 ; CHECK: [[LPAD3_LABEL]]:{{[ ]+}}; preds = %invoke.cont2
97 ; CHECK: [[LPAD3_VAL:\%.+]] = landingpad { i8*, i32 }
99 ; CHECK-NEXT: catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)
100 ; CHECK-NEXT: [[RECOVER3:\%.+]] = call i8* (...) @llvm.eh.actions(i32 1, i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*), i32 2, i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch.1", i32 0, void (i8*, i8*)* @"\01?test@@YAXXZ.cleanup")
101 ; CHECK-NEXT: indirectbr i8* [[RECOVER3]], [label %try.cont, label %try.cont15]
103 lpad3: ; preds = %invoke.cont2
104 %8 = landingpad { i8*, i32 }
106 catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)
107 %9 = extractvalue { i8*, i32 } %8, 0
108 %10 = extractvalue { i8*, i32 } %8, 1
109 %11 = call i32 @llvm.eh.typeid.for(i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)) #3
110 %matches = icmp eq i32 %10, %11
111 br i1 %matches, label %catch, label %ehcleanup
114 catch: ; preds = %lpad3
115 %12 = bitcast i32* %0 to i8*
116 call void @llvm.eh.begincatch(i8* %9, i8* %12) #3
117 invoke void @"\01?handle_exception@@YAXXZ"()
118 to label %invoke.cont6 unwind label %lpad5
120 ; CHECK-NOT: invoke.cont6:
121 invoke.cont6: ; preds = %catch
122 call void @llvm.eh.endcatch() #3
125 try.cont: ; preds = %invoke.cont2, %invoke.cont6
126 call void @"\01??1SomeClass@@QEAA@XZ"(%class.SomeClass* %obj) #3
130 lpad5: ; preds = %catch
131 %13 = landingpad { i8*, i32 }
133 catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)
134 %14 = extractvalue { i8*, i32 } %13, 0
135 %15 = extractvalue { i8*, i32 } %13, 1
136 call void @llvm.eh.endcatch() #3
139 ; CHECK-NOT: ehcleanup
140 ehcleanup: ; preds = %lpad5, %lpad3, %lpad1
141 %exn.slot.0 = phi i8* [ %14, %lpad5 ], [ %9, %lpad3 ], [ %6, %lpad1 ]
142 %ehselector.slot.0 = phi i32 [ %15, %lpad5 ], [ %10, %lpad3 ], [ %7, %lpad1 ]
143 call void @"\01??1SomeClass@@QEAA@XZ"(%class.SomeClass* %obj) #3
144 br label %catch.dispatch7
146 ; CHECK-NOT: catch.dispatch7:
147 catch.dispatch7: ; preds = %ehcleanup, %lpad
148 %exn.slot.1 = phi i8* [ %exn.slot.0, %ehcleanup ], [ %3, %lpad ]
149 %ehselector.slot.1 = phi i32 [ %ehselector.slot.0, %ehcleanup ], [ %4, %lpad ]
150 %16 = call i32 @llvm.eh.typeid.for(i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)) #3
151 %matches9 = icmp eq i32 %ehselector.slot.1, %16
152 br i1 %matches9, label %catch10, label %eh.resume
154 ; CHECK-NOT: catch10:
155 catch10: ; preds = %catch.dispatch7
156 %17 = bitcast i32* %1 to i8*
157 call void @llvm.eh.begincatch(i8* %exn.slot.1, i8* %17) #3
158 call void @"\01?handle_exception@@YAXXZ"()
159 br label %invoke.cont13
161 ; CHECK-NOT: invoke.cont13:
162 invoke.cont13: ; preds = %catch10
163 call void @llvm.eh.endcatch() #3
166 try.cont15: ; preds = %invoke.cont13, %try.cont
169 ; CHECK-NOT: eh.resume
170 eh.resume: ; preds = %catch.dispatch7
171 %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn.slot.1, 0
172 %lpad.val18 = insertvalue { i8*, i32 } %lpad.val, i32 %ehselector.slot.1, 1
173 resume { i8*, i32 } %lpad.val18
178 ; CHECK-LABEL: define internal i8* @"\01?test@@YAXXZ.catch"(i8*, i8*)
180 ; CHECK: [[RECOVER_TMP1:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 0)
181 ; CHECK: [[TMP1_PTR:\%.+]] = bitcast i8* [[RECOVER_TMP1]] to i32*
182 ; CHECK: call void @"\01?handle_exception@@YAXXZ"()
183 ; CHECK: ret i8* blockaddress(@"\01?test@@YAXXZ", %try.cont15)
186 ; CHECK-LABEL: define internal void @"\01?test@@YAXXZ.cleanup"(i8*, i8*)
188 ; CHECK: [[RECOVER_OBJ:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 1)
189 ; CHECK: [[OBJ_PTR:\%.+]] = bitcast i8* %obj.i8 to %class.SomeClass*
190 ; CHECK: call void @"\01??1SomeClass@@QEAA@XZ"(%class.SomeClass* [[OBJ_PTR]])
194 ; CHECK-LABEL: define internal i8* @"\01?test@@YAXXZ.catch.1"(i8*, i8*)
196 ; CHECK: [[RECOVER_TMP0:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 2)
197 ; CHECK: [[TMP0_PTR:\%.+]] = bitcast i8* [[RECOVER_TMP0]] to i32*
198 ; CHECK: invoke void @"\01?handle_exception@@YAXXZ"()
199 ; CHECK: to label %invoke.cont6 unwind label %[[LPAD5_LABEL:lpad[0-9]+]]
201 ; CHECK: invoke.cont6: ; preds = %entry
202 ; CHECK: ret i8* blockaddress(@"\01?test@@YAXXZ", %try.cont)
204 ; CHECK: [[LPAD5_LABEL]]:{{[ ]+}}; preds = %entry
205 ; CHECK: [[LPAD5_VAL:\%.+]] = landingpad { i8*, i32 }
207 ; CHECK: catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)
210 declare %class.SomeClass* @"\01??0SomeClass@@QEAA@XZ"(%class.SomeClass* returned) #1
212 declare i32 @__CxxFrameHandler3(...)
214 declare void @"\01?may_throw@@YAXXZ"() #1
216 ; Function Attrs: nounwind readnone
217 declare i32 @llvm.eh.typeid.for(i8*) #2
219 ; Function Attrs: nounwind
220 declare void @llvm.eh.begincatch(i8* nocapture, i8* nocapture) #3
222 declare void @"\01?handle_exception@@YAXXZ"() #1
224 ; Function Attrs: nounwind
225 declare void @llvm.eh.endcatch() #3
227 ; Function Attrs: nounwind
228 declare void @"\01??1SomeClass@@QEAA@XZ"(%class.SomeClass*) #4
230 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" "unsafe-fp-math"="false" "use-soft-float"="false" }
231 attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
232 attributes #2 = { nounwind readnone }
233 attributes #3 = { nounwind }
234 attributes #4 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
236 !llvm.module.flags = !{!0}
239 !0 = !{i32 1, !"PIC Level", i32 2}
240 !1 = !{!"clang version 3.7.0 (trunk 232069) (llvm/trunk 232070)"}