Centralize the handling of unique ids for temporary labels.
[oota-llvm.git] / test / CodeGen / WinEH / cppeh-nested-3.ll
1 ; RUN: opt -mtriple=x86_64-pc-windows-msvc -winehprepare -S -o - < %s | FileCheck %s
2 ; XFAIL: *
3
4 ; This test is based on the following code:
5 ;
6 ;void test()
7 ;{
8 ;  try {
9 ;    try {
10 ;       may_throw();
11 ;    } catch (int i) {
12 ;      try {
13 ;        may_throw();
14 ;      }
15 ;      catch (int j) {
16 ;        i = j;
17 ;      }
18 ;      handle_int(i);
19 ;    }
20 ;  } catch (float f) {
21 ;    handle_float(f);
22 ;  }
23 ;  done();
24 ;}
25
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"
29
30 %rtti.TypeDescriptor2 = type { i8**, i8*, [3 x i8] }
31
32 $"\01??_R0M@8" = comdat any
33
34 $"\01??_R0H@8" = comdat any
35
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
39
40 ; CHECK: define void @"\01?test@@YAXXZ"() #0 {
41 ; CHECK: entry:
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]*]]
50
51 ; Function Attrs: uwtable
52 define void @"\01?test@@YAXXZ"() #0 {
53 entry:
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
61
62 invoke.cont:                                      ; preds = %entry
63   br label %try.cont10
64
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]
71
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
81
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
88
89 ; CHECK-NOT: catch:
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
96
97 ; CHECK-NOT: invoke.cont2:
98 invoke.cont2:                                     ; preds = %catch
99   br label %try.cont
100
101 ; CHECK-NOT: lpad1:
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
111
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
118
119 ; CHECK-NOT: catch6:
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
127   br label %try.cont
128
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
134
135 ; CHECK-NOT: invoke.cont9:
136 invoke.cont9:                                     ; preds = %try.cont
137   call void @llvm.eh.endcatch() #3
138   br label %try.cont10
139
140 try.cont10:                                       ; preds = %invoke.cont9, %invoke.cont
141   br label %try.cont19
142
143 ; CHECK-NOT: lpad8:
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
153
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
160
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
169   br label %try.cont19
170
171 try.cont19:                                       ; preds = %catch14, %try.cont10
172   call void @"\01?done@@YAXXZ"()
173   ret void
174
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
182 ; CHECK: }
183 }
184
185 ; CHECK: define internal i8* @"\01?test@@YAXXZ.catch"(i8*, i8*) {
186 ; CHECK: entry:
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]*]]
197 ;
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]*]]
202 ;
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]], []
210 ;
211 ; CHECK: invoke.cont9:
212 ; CHECK:   ret i8* blockaddress(@"\01?test@@YAXXZ", %try.cont10)
213 ;
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]], []
220 ;
221 ; CHECK: }
222
223 ; CHECK: define internal i8* @"\01?test@@YAXXZ.catch1"(i8*, i8*) {
224 ; CHECK: entry:
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)
230 ; CHECK: }
231
232 ; CHECK: define internal i8* @"\01?test@@YAXXZ.catch2"(i8*, i8*) {
233 ; CHECK: entry:
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)
242 ; CHECK: }
243
244
245 declare void @"\01?may_throw@@YAXXZ"() #1
246
247 declare i32 @__CxxFrameHandler3(...)
248
249 ; Function Attrs: nounwind readnone
250 declare i32 @llvm.eh.typeid.for(i8*) #2
251
252 ; Function Attrs: nounwind
253 declare void @llvm.eh.begincatch(i8* nocapture, i8* nocapture) #3
254
255 ; Function Attrs: nounwind
256 declare void @llvm.eh.endcatch() #3
257
258 declare void @"\01?handle_int@@YAXH@Z"(i32) #1
259
260 declare void @"\01?handle_float@@YAXM@Z"(float) #1
261
262 declare void @"\01?done@@YAXXZ"() #1
263
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 }
268
269 !llvm.module.flags = !{!0}
270 !llvm.ident = !{!1}
271
272 !0 = !{i32 1, !"PIC Level", i32 2}
273 !1 = !{!"clang version 3.7.0 (trunk 232069) (llvm/trunk 232070)"}