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 {
36 ; CHECK: [[UNWIND_HELP:\%.+]] = alloca i64
37 ; CHECK: [[OBJ_PTR:\%.+]] = alloca %class.SomeClass
38 ; CHECK: [[TMP0:\%.+]] = alloca i32, align 4
39 ; CHECK: [[TMP1:\%.+]] = alloca i32, align 4
40 ; CHECK: call void (...)* @llvm.frameescape(i32* [[TMP1]], %class.SomeClass* [[OBJ_PTR]], i32* [[TMP0]])
41 ; CHECK: [[UNWIND_HELP_i8:\%.+]] = bitcast i64* [[UNWIND_HELP]] to i8*
42 ; CHECK: call void @llvm.eh.unwindhelp(i8* [[UNWIND_HELP_i8]])
43 ; CHECK: %call = invoke %class.SomeClass* @"\01??0SomeClass@@QEAA@XZ"(%class.SomeClass* %obj)
44 ; CHECK: to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]+]]
46 ; Function Attrs: uwtable
47 define void @"\01?test@@YAXXZ"() #0 {
49 %obj = alloca %class.SomeClass, align 1
50 %0 = alloca i32, align 4
51 %1 = alloca i32, align 4
52 %call = invoke %class.SomeClass* @"\01??0SomeClass@@QEAA@XZ"(%class.SomeClass* %obj)
53 to label %invoke.cont unwind label %lpad
56 ; CHECK: invoke void @"\01?may_throw@@YAXXZ"()
57 ; CHECK: to label %invoke.cont2 unwind label %[[LPAD1_LABEL:lpad[0-9]+]]
59 invoke.cont: ; preds = %entry
60 invoke void @"\01?may_throw@@YAXXZ"()
61 to label %invoke.cont2 unwind label %lpad1
63 ; CHECK: invoke.cont2:
64 ; CHECK: invoke void @"\01?may_throw@@YAXXZ"()
65 ; CHECK: to label %try.cont unwind label %[[LPAD3_LABEL:lpad[0-9]+]]
67 invoke.cont2: ; preds = %invoke.cont
68 invoke void @"\01?may_throw@@YAXXZ"()
69 to label %try.cont unwind label %lpad3
71 ; CHECK: [[LPAD_LABEL]]:{{[ ]+}}; preds = %entry
72 ; CHECK: [[LPAD_VAL:\%.+]] = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
73 ; CHECK-NEXT: catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)
74 ; CHECK-NEXT: [[RECOVER:\%.+]] = call i8* (...)* @llvm.eh.actions(i32 1, i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*), i32* [[TMP1]], i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch")
75 ; CHECK-NEXT: indirectbr i8* [[RECOVER]], [label %try.cont15]
77 lpad: ; preds = %entry
78 %2 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
79 catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)
80 %3 = extractvalue { i8*, i32 } %2, 0
81 %4 = extractvalue { i8*, i32 } %2, 1
82 br label %catch.dispatch7
84 ; CHECK: [[LPAD1_LABEL]]:{{[ ]+}}; preds = %invoke.cont
85 ; CHECK: [[LPAD1_VAL:\%.+]] = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
87 ; CHECK-NEXT: catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)
88 ; 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* [[TMP1]], i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch")
89 ; CHECK-NEXT: indirectbr i8* [[RECOVER1]], [label %try.cont15]
91 lpad1: ; preds = %invoke.cont
92 %5 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
94 catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)
95 %6 = extractvalue { i8*, i32 } %5, 0
96 %7 = extractvalue { i8*, i32 } %5, 1
99 ; CHECK: [[LPAD3_LABEL]]:{{[ ]+}}; preds = %invoke.cont2
100 ; CHECK: [[LPAD3_VAL:\%.+]] = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
101 ; CHECK-NEXT: cleanup
102 ; CHECK-NEXT: catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)
103 ; CHECK-NEXT: [[RECOVER3:\%.+]] = call i8* (...)* @llvm.eh.actions(i32 1, i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*), i32* [[TMP0]], i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch1", i32 0, void (i8*, i8*)* @"\01?test@@YAXXZ.cleanup")
104 ; CHECK-NEXT: indirectbr i8* [[RECOVER3]], [label %try.cont]
106 lpad3: ; preds = %invoke.cont2
107 %8 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
109 catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)
110 %9 = extractvalue { i8*, i32 } %8, 0
111 %10 = extractvalue { i8*, i32 } %8, 1
112 %11 = call i32 @llvm.eh.typeid.for(i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)) #3
113 %matches = icmp eq i32 %10, %11
114 br i1 %matches, label %catch, label %ehcleanup
117 catch: ; preds = %lpad3
118 %12 = bitcast i32* %0 to i8*
119 call void @llvm.eh.begincatch(i8* %9, i8* %12) #3
120 invoke void @"\01?handle_exception@@YAXXZ"()
121 to label %invoke.cont6 unwind label %lpad5
123 ; CHECK-NOT: invoke.cont6:
124 invoke.cont6: ; preds = %catch
125 call void @llvm.eh.endcatch() #3
128 try.cont: ; preds = %invoke.cont2, %invoke.cont6
129 call void @"\01??1SomeClass@@QEAA@XZ"(%class.SomeClass* %obj) #3
133 lpad5: ; preds = %catch
134 %13 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
136 catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)
137 %14 = extractvalue { i8*, i32 } %13, 0
138 %15 = extractvalue { i8*, i32 } %13, 1
139 call void @llvm.eh.endcatch() #3
142 ; CHECK-NOT: ehcleanup
143 ehcleanup: ; preds = %lpad5, %lpad3, %lpad1
144 %exn.slot.0 = phi i8* [ %14, %lpad5 ], [ %9, %lpad3 ], [ %6, %lpad1 ]
145 %ehselector.slot.0 = phi i32 [ %15, %lpad5 ], [ %10, %lpad3 ], [ %7, %lpad1 ]
146 call void @"\01??1SomeClass@@QEAA@XZ"(%class.SomeClass* %obj) #3
147 br label %catch.dispatch7
149 ; CHECK-NOT: catch.dispatch7:
150 catch.dispatch7: ; preds = %ehcleanup, %lpad
151 %exn.slot.1 = phi i8* [ %exn.slot.0, %ehcleanup ], [ %3, %lpad ]
152 %ehselector.slot.1 = phi i32 [ %ehselector.slot.0, %ehcleanup ], [ %4, %lpad ]
153 %16 = call i32 @llvm.eh.typeid.for(i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)) #3
154 %matches9 = icmp eq i32 %ehselector.slot.1, %16
155 br i1 %matches9, label %catch10, label %eh.resume
157 ; CHECK-NOT: catch10:
158 catch10: ; preds = %catch.dispatch7
159 %17 = bitcast i32* %1 to i8*
160 call void @llvm.eh.begincatch(i8* %exn.slot.1, i8* %17) #3
161 call void @"\01?handle_exception@@YAXXZ"()
162 br label %invoke.cont13
164 ; CHECK-NOT: invoke.cont13:
165 invoke.cont13: ; preds = %catch10
166 call void @llvm.eh.endcatch() #3
169 try.cont15: ; preds = %invoke.cont13, %try.cont
172 ; CHECK-NOT: eh.resume
173 eh.resume: ; preds = %catch.dispatch7
174 %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn.slot.1, 0
175 %lpad.val18 = insertvalue { i8*, i32 } %lpad.val, i32 %ehselector.slot.1, 1
176 resume { i8*, i32 } %lpad.val18
181 ; CHECK-LABEL: define internal i8* @"\01?test@@YAXXZ.catch"(i8*, i8*)
183 ; CHECK: [[RECOVER_TMP1:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 0)
184 ; CHECK: [[TMP1_PTR:\%.+]] = bitcast i8* [[RECOVER_TMP1]] to i32*
185 ; CHECK: call void @"\01?handle_exception@@YAXXZ"()
186 ; CHECK: ret i8* blockaddress(@"\01?test@@YAXXZ", %try.cont15)
189 ; CHECK-LABEL: define internal void @"\01?test@@YAXXZ.cleanup"(i8*, i8*)
191 ; CHECK: [[RECOVER_OBJ:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 1)
192 ; CHECK: [[OBJ_PTR:\%.+]] = bitcast i8* %obj.i8 to %class.SomeClass*
193 ; CHECK: call void @"\01??1SomeClass@@QEAA@XZ"(%class.SomeClass* [[OBJ_PTR]])
197 ; CHECK-LABEL: define internal i8* @"\01?test@@YAXXZ.catch1"(i8*, i8*)
199 ; CHECK: [[RECOVER_TMP0:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 2)
200 ; CHECK: [[TMP0_PTR:\%.+]] = bitcast i8* [[RECOVER_TMP0]] to i32*
201 ; CHECK: invoke void @"\01?handle_exception@@YAXXZ"()
202 ; CHECK: to label %invoke.cont6 unwind label %[[LPAD5_LABEL:lpad[0-9]+]]
204 ; CHECK: invoke.cont6: ; preds = %entry
205 ; CHECK: ret i8* blockaddress(@"\01?test@@YAXXZ", %try.cont)
207 ; CHECK: [[LPAD5_LABEL]]:{{[ ]+}}; preds = %entry
208 ; CHECK: [[LPAD5_VAL:\%.+]] = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
210 ; CHECK: catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)
214 declare %class.SomeClass* @"\01??0SomeClass@@QEAA@XZ"(%class.SomeClass* returned) #1
216 declare i32 @__CxxFrameHandler3(...)
218 declare void @"\01?may_throw@@YAXXZ"() #1
220 ; Function Attrs: nounwind readnone
221 declare i32 @llvm.eh.typeid.for(i8*) #2
223 ; Function Attrs: nounwind
224 declare void @llvm.eh.begincatch(i8* nocapture, i8* nocapture) #3
226 declare void @"\01?handle_exception@@YAXXZ"() #1
228 ; Function Attrs: nounwind
229 declare void @llvm.eh.endcatch() #3
231 ; Function Attrs: nounwind
232 declare void @"\01??1SomeClass@@QEAA@XZ"(%class.SomeClass*) #4
234 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" }
235 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" }
236 attributes #2 = { nounwind readnone }
237 attributes #3 = { nounwind }
238 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" }
240 !llvm.module.flags = !{!0}
243 !0 = !{i32 1, !"PIC Level", i32 2}
244 !1 = !{!"clang version 3.7.0 (trunk 232069) (llvm/trunk 232070)"}