1 ; RUN: opt -mtriple=x86_64-pc-windows-msvc -winehprepare -S -o - < %s | FileCheck %s
4 ; This test is based on the following code:
26 ; ModuleID = 'cppeh-nested-3.cpp'
27 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
28 target triple = "x86_64-pc-windows-msvc"
30 %rtti.TypeDescriptor2 = type { i8**, i8*, [3 x i8] }
32 $"\01??_R0M@8" = comdat any
34 $"\01??_R0H@8" = comdat any
36 @"\01??_7type_info@@6B@" = external constant i8*
37 @"\01??_R0M@8" = linkonce_odr global %rtti.TypeDescriptor2 { i8** @"\01??_7type_info@@6B@", i8* null, [3 x i8] c".M\00" }, comdat
38 @"\01??_R0H@8" = linkonce_odr global %rtti.TypeDescriptor2 { i8** @"\01??_7type_info@@6B@", i8* null, [3 x i8] c".H\00" }, comdat
40 ; CHECK: define void @"\01?test@@YAXXZ"() #0 {
42 ; CHECK: %i = alloca i32, align 4
43 ; ------------================= FAIL here =================------------
44 ; CHECK: %j = alloca i32, align 4
45 ; CHECK: %f = alloca float, align 4
46 ; ------------================= FAIL here =================------------
47 ; CHECK: call void (...)* @llvm.frameescape(i32* %i, float* %f, int32* %j)
48 ; CHECK: invoke void @"\01?may_throw@@YAXXZ"()
49 ; CHECK: to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]*]]
51 ; Function Attrs: uwtable
52 define void @"\01?test@@YAXXZ"() #0 {
54 %exn.slot = alloca i8*
55 %ehselector.slot = alloca i32
56 %i = alloca i32, align 4
57 %j = alloca i32, align 4
58 %f = alloca float, align 4
59 invoke void @"\01?may_throw@@YAXXZ"()
60 to label %invoke.cont unwind label %lpad
62 invoke.cont: ; preds = %entry
65 ; CHECK: [[LPAD_LABEL]]:
66 ; CHECK: [[LPAD_VAL:\%.+]] = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
67 ; CHECK: catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)
68 ; CHECK: catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0M@8" to i8*)
69 ; CHECK: [[RECOVER:\%.+]] = call i8* (...)* @llvm.eh.actions({ i8*, i32 } [[LPAD_VAL]], i32 0, i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*), i32* %i, i8* bitcast (i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch" to i8*), i32 0, i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0M@8" to i8*), float* %f, i8* bitcast (i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch1" to i8*))
70 ; CHECK: indirectbr i8* [[RECOVER]], [label %try.cont10, label %try.cont19]
72 lpad: ; preds = %entry
73 %0 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
74 catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)
75 catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0M@8" to i8*)
76 %1 = extractvalue { i8*, i32 } %0, 0
77 store i8* %1, i8** %exn.slot
78 %2 = extractvalue { i8*, i32 } %0, 1
79 store i32 %2, i32* %ehselector.slot
80 br label %catch.dispatch
82 ; CHECK-NOT: catch.dispatch:
83 catch.dispatch: ; preds = %lpad
84 %sel = load i32, i32* %ehselector.slot
85 %3 = call i32 @llvm.eh.typeid.for(i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)) #3
86 %matches = icmp eq i32 %sel, %3
87 br i1 %matches, label %catch, label %catch.dispatch11
90 catch: ; preds = %catch.dispatch
91 %exn = load i8*, i8** %exn.slot
92 %4 = bitcast i32* %i to i8*
93 call void @llvm.eh.begincatch(i8* %exn, i8* %4) #3
94 invoke void @"\01?may_throw@@YAXXZ"()
95 to label %invoke.cont2 unwind label %lpad1
97 ; CHECK-NOT: invoke.cont2:
98 invoke.cont2: ; preds = %catch
102 lpad1: ; preds = %catch
103 %5 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
104 catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)
105 catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0M@8" to i8*)
106 %6 = extractvalue { i8*, i32 } %5, 0
107 store i8* %6, i8** %exn.slot
108 %7 = extractvalue { i8*, i32 } %5, 1
109 store i32 %7, i32* %ehselector.slot
110 br label %catch.dispatch3
112 ; CHECK-NOT: catch.dispatch3:
113 catch.dispatch3: ; preds = %lpad1
114 %sel4 = load i32, i32* %ehselector.slot
115 %8 = call i32 @llvm.eh.typeid.for(i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)) #3
116 %matches5 = icmp eq i32 %sel4, %8
117 br i1 %matches5, label %catch6, label %catch.dispatch11
120 catch6: ; preds = %catch.dispatch3
121 %exn7 = load i8*, i8** %exn.slot
122 %9 = bitcast i32* %j to i8*
123 call void @llvm.eh.begincatch(i8* %exn7, i8* %9) #3
124 %10 = load i32, i32* %j, align 4
125 store i32 %10, i32* %i, align 4
126 call void @llvm.eh.endcatch() #3
129 ; CHECK-NOT: try.cont:
130 try.cont: ; preds = %catch6, %invoke.cont2
131 %11 = load i32, i32* %i, align 4
132 invoke void @"\01?handle_int@@YAXH@Z"(i32 %11)
133 to label %invoke.cont9 unwind label %lpad8
135 ; CHECK-NOT: invoke.cont9:
136 invoke.cont9: ; preds = %try.cont
137 call void @llvm.eh.endcatch() #3
140 try.cont10: ; preds = %invoke.cont9, %invoke.cont
144 lpad8: ; preds = %try.cont
145 %12 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
146 catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0M@8" to i8*)
147 %13 = extractvalue { i8*, i32 } %12, 0
148 store i8* %13, i8** %exn.slot
149 %14 = extractvalue { i8*, i32 } %12, 1
150 store i32 %14, i32* %ehselector.slot
151 call void @llvm.eh.endcatch() #3
152 br label %catch.dispatch11
154 ; CHECK-NOT: catch.dispatch11:
155 catch.dispatch11: ; preds = %lpad8, %catch.dispatch3, %catch.dispatch
156 %sel12 = load i32, i32* %ehselector.slot
157 %15 = call i32 @llvm.eh.typeid.for(i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0M@8" to i8*)) #3
158 %matches13 = icmp eq i32 %sel12, %15
159 br i1 %matches13, label %catch14, label %eh.resume
161 ; CHECK-NOT: catch14:
162 catch14: ; preds = %catch.dispatch11
163 %exn15 = load i8*, i8** %exn.slot
164 %16 = bitcast float* %f to i8*
165 call void @llvm.eh.begincatch(i8* %exn15, i8* %16) #3
166 %17 = load float, float* %f, align 4
167 call void @"\01?handle_float@@YAXM@Z"(float %17)
168 call void @llvm.eh.endcatch() #3
171 try.cont19: ; preds = %catch14, %try.cont10
172 call void @"\01?done@@YAXXZ"()
175 ; CHECK-NOT: eh.resume:
176 eh.resume: ; preds = %lpad16, %catch.dispatch11
177 %exn20 = load i8*, i8** %exn.slot
178 %sel21 = load i32, i32* %ehselector.slot
179 %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn20, 0
180 %lpad.val22 = insertvalue { i8*, i32 } %lpad.val, i32 %sel21, 1
181 resume { i8*, i32 } %lpad.val22
185 ; CHECK: define internal i8* @"\01?test@@YAXXZ.catch"(i8*, i8*) {
187 ; CHECK: [[RECOVER_I:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 0)
188 ; CHECK: [[I_PTR:\%.+]] = bitcast i8* [[RECOVER_I]] to i32*
189 ; ------------================= FAIL here =================------------
190 ; CHECK: [[RECOVER_F:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 1)
191 ; CHECK: [[F_PTR:\%.+]] = bitcast i8* [[RECOVER_F]] to float*
192 ; ------------================= FAIL here =================------------
193 ; CHECK: [[RECOVER_J:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 2)
194 ; CHECK: [[J_PTR:\%.+]] = bitcast i8* [[RECOVER_I]] to i32*
195 ; CHECK: invoke void @"\01?may_throw@@YAXXZ"()
196 ; CHECK: to label %invoke.cont2 unwind label %[[LPAD1_LABEL:lpad[0-9]*]]
198 ; CHECK: invoke.cont2: ; preds = %entry
199 ; CHECK: [[TMP1:\%.+]] = load i32, i32* [[I_PTR]], align 4
200 ; CHECK: invoke void @"\01?handle_int@@YAXH@Z"(i32 [[TMP1]])
201 ; CHECK: to label %invoke.cont9 unwind label %[[LPAD8_LABEL:lpad[0-9]*]]
203 ; CHECK: [[LPAD1_LABEL]]:{{[ ]+}}; preds = %entry
204 ; CHECK: [[LPAD1_VAL:\%.+]] = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
205 ; CHECK: catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)
206 ; CHECK: catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0M@8" to i8*)
207 ; ------------================= FAIL here =================------------
208 ; CHECK: [[RECOVER1:\%.+]] = call i8* (...)* @llvm.eh.actions({ i8*, i32 } [[LPAD1_VAL]], i32 0, i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*), i32* [[J_PTR]], i8* bitcast (i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch2" to i8*), i32 0, i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0M@8" to i8*), float* [[F_PTR1]], i8* bitcast (i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch1" to i8*))
209 ; CHECK: indirectbr i8* [[RECOVER1]], []
211 ; CHECK: invoke.cont9:
212 ; CHECK: ret i8* blockaddress(@"\01?test@@YAXXZ", %try.cont10)
214 ; CHECK: [[LPAD8_LABEL]]:{{[ ]+}}; preds = %invoke.cont2
215 ; CHECK: [[LPAD8_VAL:\%.+]] = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
216 ; CHECK: catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0M@8" to i8*)
217 ; ------------================= FAIL here =================------------
218 ; CHECK: [[RECOVER2:\%.+]] = call i8* (...)* @llvm.eh.actions({ i8*, i32 } [[LPAD8_VAL]], i32 0, i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0M@8" to i8*), float* [[F_PTR1]], i8* bitcast (i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch1" to i8*))
219 ; CHECK: indirectbr i8* [[RECOVER2]], []
223 ; CHECK: define internal i8* @"\01?test@@YAXXZ.catch1"(i8*, i8*) {
225 ; CHECK: [[RECOVER_F1:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 1)
226 ; CHECK: [[F_PTR1:\%.+]] = bitcast i8* [[RECOVER_F1]] to float*
227 ; CHECK: [[TMP2:\%.+]] = load float, float* [[F_PTR1]], align 4
228 ; CHECK: call void @"\01?handle_float@@YAXM@Z"(float [[TMP2]])
229 ; CHECK: ret i8* blockaddress(@"\01?test@@YAXXZ", %try.cont19)
232 ; CHECK: define internal i8* @"\01?test@@YAXXZ.catch2"(i8*, i8*) {
234 ; ------------================= FAIL here =================------------
235 ; SHOULD-CHECK: [[J_PTR1:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 2)
236 ; CHECK: [[RECOVER_I1:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 0)
237 ; CHECK: [[I_PTR1:\%.+]] = bitcast i8* [[RECOVER_I1]] to i32*
238 ; CHECK: [[TMP3:\%.+]] = load i32, i32* [[J_PTR1]], align 4
239 ; CHECK: store i32 [[TMP3]], i32* [[I_PTR1]]
240 ; ------------================= FAIL here =================------------
241 ; CHECK: ret i8* blockaddress(@"\01?test@@YAXXZ.catch", %invoke.cont2)
245 declare void @"\01?may_throw@@YAXXZ"() #1
247 declare i32 @__CxxFrameHandler3(...)
249 ; Function Attrs: nounwind readnone
250 declare i32 @llvm.eh.typeid.for(i8*) #2
252 ; Function Attrs: nounwind
253 declare void @llvm.eh.begincatch(i8* nocapture, i8* nocapture) #3
255 ; Function Attrs: nounwind
256 declare void @llvm.eh.endcatch() #3
258 declare void @"\01?handle_int@@YAXH@Z"(i32) #1
260 declare void @"\01?handle_float@@YAXM@Z"(float) #1
262 declare void @"\01?done@@YAXXZ"() #1
264 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" }
265 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" }
266 attributes #2 = { nounwind readnone }
267 attributes #3 = { nounwind }
269 !llvm.module.flags = !{!0}
272 !0 = !{i32 1, !"PIC Level", i32 2}
273 !1 = !{!"clang version 3.7.0 (trunk 232069) (llvm/trunk 232070)"}