3549b1d51dee3c721d2080acb601642db5a9bbe7
[oota-llvm.git] / test / CodeGen / WinEH / cppeh-state-calc-1.ll
1 ; RUN: llc < %s | FileCheck %s
2
3 ; This test was generated from the following code.
4 ;
5 ; void test() {
6 ;   try {
7 ;     try {
8 ;       try {
9 ;         two();
10 ;         throw 2;
11 ;       } catch (int x) {
12 ;         catch_two();
13 ;       }
14 ;       a();
15 ;       throw 'a';
16 ;     } catch (char c) {
17 ;       catch_a();
18 ;     }
19 ;     one();
20 ;     throw 1;
21 ;   } catch(int x) { 
22 ;     catch_one();
23 ;   } catch(...) {
24 ;     catch_all();
25 ;   }
26 ; }
27 ;
28 ; The function calls before the throws were declared as 'noexcept' and are
29 ; just here to make blocks easier to identify in the IR.
30
31 ; ModuleID = '<stdin>'
32 target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
33 target triple = "x86_64-pc-windows-msvc"
34
35 %rtti.TypeDescriptor2 = type { i8**, i8*, [3 x i8] }
36 %eh.CatchHandlerType = type { i32, i8* }
37 %eh.CatchableType = type { i32, i32, i32, i32, i32, i32, i32 }
38 %eh.CatchableTypeArray.1 = type { i32, [1 x i32] }
39 %eh.ThrowInfo = type { i32, i32, i32, i32 }
40
41 $"\01??_R0H@8" = comdat any
42
43 $"\01??_R0D@8" = comdat any
44
45 $"_CT??_R0H@84" = comdat any
46
47 $_CTA1H = comdat any
48
49 $_TI1H = comdat any
50
51 $"_CT??_R0D@81" = comdat any
52
53 $_CTA1D = comdat any
54
55 $_TI1D = comdat any
56
57 @"\01??_7type_info@@6B@" = external constant i8*
58 @"\01??_R0H@8" = linkonce_odr global %rtti.TypeDescriptor2 { i8** @"\01??_7type_info@@6B@", i8* null, [3 x i8] c".H\00" }, comdat
59 @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"
60 @"\01??_R0D@8" = linkonce_odr global %rtti.TypeDescriptor2 { i8** @"\01??_7type_info@@6B@", i8* null, [3 x i8] c".D\00" }, comdat
61 @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"
62 @__ImageBase = external constant i8
63 @"_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
64 @_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
65 @_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
66 @"_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
67 @_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
68 @_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
69
70 ; Function Attrs: nounwind uwtable
71 define void @"\01?test@@YAXXZ"() #0 {
72 entry:
73   %tmp = alloca i32, align 4
74   %x = alloca i32, align 4
75   %tmp2 = alloca i8, align 1
76   %c = alloca i8, align 1
77   %tmp11 = alloca i32, align 4
78   %x21 = alloca i32, align 4
79   call void @"\01?two@@YAXXZ"() #3
80   store i32 2, i32* %tmp
81   %0 = bitcast i32* %tmp to i8*
82   call void (...) @llvm.frameescape(i32* %x, i8* %c, i32* %x21)
83   invoke void @_CxxThrowException(i8* %0, %eh.ThrowInfo* @_TI1H) #5
84           to label %unreachable unwind label %lpad
85
86 lpad:                                             ; preds = %entry
87   %1 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
88           catch i8* bitcast (%eh.CatchHandlerType* @llvm.eh.handlertype.H.0 to i8*)
89           catch %eh.CatchHandlerType* @llvm.eh.handlertype.D.0
90           catch %eh.CatchHandlerType* @llvm.eh.handlertype.H.0
91           catch i8* null
92   %recover = call i8* (...) @llvm.eh.actions(i32 1, i8* bitcast (%eh.CatchHandlerType* @llvm.eh.handlertype.H.0 to i8*), i32 0, i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch", i32 1, i8* bitcast (%eh.CatchHandlerType* @llvm.eh.handlertype.D.0 to i8*), i32 1, i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch1", i32 1, i8* bitcast (%eh.CatchHandlerType* @llvm.eh.handlertype.H.0 to i8*), i32 2, i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch2", i32 1, i8* null, i32 -1, i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch3")
93   indirectbr i8* %recover, [label %try.cont, label %try.cont10, label %try.cont22]
94
95 try.cont:                                         ; preds = %lpad
96   call void @"\01?a@@YAXXZ"() #3
97   store i8 97, i8* %tmp2
98   invoke void @_CxxThrowException(i8* %tmp2, %eh.ThrowInfo* @_TI1D) #5
99           to label %unreachable unwind label %lpad3
100
101 lpad3:                                            ; preds = %try.cont
102   %2 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
103           catch %eh.CatchHandlerType* @llvm.eh.handlertype.D.0
104           catch %eh.CatchHandlerType* @llvm.eh.handlertype.H.0
105           catch i8* null
106   %recover1 = call i8* (...) @llvm.eh.actions(i32 1, i8* bitcast (%eh.CatchHandlerType* @llvm.eh.handlertype.D.0 to i8*), i32 1, i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch1", i32 1, i8* bitcast (%eh.CatchHandlerType* @llvm.eh.handlertype.H.0 to i8*), i32 2, i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch2", i32 1, i8* null, i32 -1, i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch3")
107   indirectbr i8* %recover1, [label %try.cont10, label %try.cont22]
108
109 try.cont10:                                       ; preds = %lpad3, %lpad
110   call void @"\01?one@@YAXXZ"() #3
111   store i32 1, i32* %tmp11
112   %3 = bitcast i32* %tmp11 to i8*
113   invoke void @_CxxThrowException(i8* %3, %eh.ThrowInfo* @_TI1H) #5
114           to label %unreachable unwind label %lpad12
115
116 lpad12:                                           ; preds = %try.cont10
117   %4 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
118           catch %eh.CatchHandlerType* @llvm.eh.handlertype.H.0
119           catch i8* null
120   %recover2 = call i8* (...) @llvm.eh.actions(i32 1, i8* bitcast (%eh.CatchHandlerType* @llvm.eh.handlertype.H.0 to i8*), i32 2, i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch2", i32 1, i8* null, i32 -1, i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch3")
121   indirectbr i8* %recover2, [label %try.cont22]
122
123 try.cont22:                                       ; preds = %lpad12, %lpad3, %lpad
124   ret void
125
126 unreachable:                                      ; preds = %try.cont10, %try.cont, %entry
127   unreachable
128 }
129
130 ; Function Attrs: nounwind
131 declare void @"\01?two@@YAXXZ"() #1
132
133 declare void @_CxxThrowException(i8*, %eh.ThrowInfo*)
134
135 declare i32 @__CxxFrameHandler3(...)
136
137 ; Function Attrs: nounwind readnone
138 declare i32 @llvm.eh.typeid.for(i8*) #2
139
140 ; Function Attrs: nounwind
141 declare void @llvm.eh.begincatch(i8* nocapture, i8* nocapture) #3
142
143 ; Function Attrs: nounwind
144 declare void @"\01?catch_two@@YAXXZ"() #1
145
146 ; Function Attrs: nounwind
147 declare void @llvm.eh.endcatch() #3
148
149 ; Function Attrs: nounwind
150 declare void @"\01?a@@YAXXZ"() #1
151
152 ; Function Attrs: nounwind
153 declare void @"\01?catch_a@@YAXXZ"() #1
154
155 ; Function Attrs: nounwind
156 declare void @"\01?one@@YAXXZ"() #1
157
158 ; Function Attrs: nounwind
159 declare void @"\01?catch_all@@YAXXZ"() #1
160
161 ; Function Attrs: nounwind
162 declare void @"\01?catch_one@@YAXXZ"() #1
163
164 ; Function Attrs: nounwind
165 declare i8* @llvm.eh.actions(...) #3
166
167 define internal i8* @"\01?test@@YAXXZ.catch"(i8*, i8*) #4 {
168 entry:
169   %x.i8 = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 0)
170   %x = bitcast i8* %x.i8 to i32*
171   %2 = bitcast i32* %x to i8*
172   call void @"\01?catch_two@@YAXXZ"() #3
173   invoke void @llvm.donothing()
174           to label %entry.split unwind label %stub
175
176 entry.split:                                      ; preds = %entry
177   ret i8* blockaddress(@"\01?test@@YAXXZ", %try.cont)
178
179 stub:                                             ; preds = %entry
180   %3 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
181           cleanup
182   %recover = call i8* (...) @llvm.eh.actions()
183   unreachable
184 }
185
186 ; Function Attrs: nounwind readnone
187 declare void @llvm.donothing() #2
188
189 define internal i8* @"\01?test@@YAXXZ.catch1"(i8*, i8*) #4 {
190 entry:
191   call void @"\01?catch_a@@YAXXZ"() #3
192   invoke void @llvm.donothing()
193           to label %entry.split unwind label %stub
194
195 entry.split:                                      ; preds = %entry
196   ret i8* blockaddress(@"\01?test@@YAXXZ", %try.cont10)
197
198 stub:                                             ; preds = %entry
199   %2 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
200           cleanup
201   %recover = call i8* (...) @llvm.eh.actions()
202   unreachable
203 }
204
205 define internal i8* @"\01?test@@YAXXZ.catch2"(i8*, i8*) #4 {
206 entry:
207   %x21.i8 = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 2)
208   %x21 = bitcast i8* %x21.i8 to i32*
209   %2 = bitcast i32* %x21 to i8*
210   call void @"\01?catch_one@@YAXXZ"() #3
211   invoke void @llvm.donothing()
212           to label %entry.split unwind label %stub
213
214 entry.split:                                      ; preds = %entry
215   ret i8* blockaddress(@"\01?test@@YAXXZ", %try.cont22)
216
217 stub:                                             ; preds = %entry
218   %3 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
219           cleanup
220   %recover = call i8* (...) @llvm.eh.actions()
221   unreachable
222 }
223
224 define internal i8* @"\01?test@@YAXXZ.catch3"(i8*, i8*) #4 {
225 entry:
226   call void @"\01?catch_all@@YAXXZ"() #3
227   invoke void @llvm.donothing()
228           to label %entry.split unwind label %stub
229
230 entry.split:                                      ; preds = %entry
231   ret i8* blockaddress(@"\01?test@@YAXXZ", %try.cont22)
232
233 stub:                                             ; preds = %entry
234   %2 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
235           cleanup
236   %recover = call i8* (...) @llvm.eh.actions()
237   unreachable
238 }
239
240 ; Function Attrs: nounwind
241 declare void @llvm.frameescape(...) #3
242
243 ; Function Attrs: nounwind readnone
244 declare i8* @llvm.framerecover(i8*, i8*, i32) #2
245
246 attributes #0 = { nounwind 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" "target-features"="+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" "wineh-parent"="\ 1?test@@YAXXZ" }
247 attributes #1 = { 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" "target-cpu"="x86-64" "target-features"="+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" }
248 attributes #2 = { nounwind readnone }
249 attributes #3 = { nounwind }
250 attributes #4 = { "wineh-parent"="\ 1?test@@YAXXZ" }
251 attributes #5 = { noreturn }
252
253 !llvm.module.flags = !{!0}
254 !llvm.ident = !{!1}
255
256 !0 = !{i32 1, !"PIC Level", i32 2}
257 !1 = !{!"clang version 3.7.0 (trunk 236059)"}
258
259 ; CHECK-LABEL: "$cppxdata$?test@@YAXXZ":
260 ; CHECK-NEXT:   .long   429065506
261 ; CHECK-NEXT:   .long
262 ; CHECK-NEXT:   .long   ("$stateUnwindMap$?test@@YAXXZ")@IMGREL
263 ; CHECK-NEXT:   .long
264 ; CHECK-NEXT:   .long   ("$tryMap$?test@@YAXXZ")@IMGREL
265 ; CHECK-NEXT:   .long
266 ; CHECK-NEXT:   .long   ("$ip2state$?test@@YAXXZ")@IMGREL
267 ; CHECK-NEXT:   .long   40
268 ; CHECK-NEXT:   .long   0
269 ; CHECK-NEXT:   .long   1
270 ; CHECK: "$stateUnwindMap$?test@@YAXXZ":
271 ; CHECK: "$tryMap$?test@@YAXXZ":
272 ; CHECK: "$handlerMap$0$?test@@YAXXZ":
273 ; CHECK: "$ip2state$?test@@YAXXZ":
274 ; CHECK-NEXT:   .long   .Lfunc_begin0@IMGREL
275 ; CHECK-NEXT:   .long   -1
276 ; CHECK-NEXT:   .long   .Ltmp0@IMGREL
277 ; CHECK-NEXT:   .long   2
278 ; CHECK-NEXT:   .long   .Ltmp3@IMGREL
279 ; CHECK-NEXT:   .long   1
280 ; CHECK-NEXT:   .long   .Ltmp6@IMGREL
281 ; CHECK-NEXT:   .long   0
282 ; CHECK-NEXT:   .long   .Lfunc_begin1@IMGREL
283 ; CHECK-NEXT:   .long   3
284 ; CHECK-NEXT:   .long   .Lfunc_begin2@IMGREL
285 ; CHECK-NEXT:   .long   4
286 ; CHECK-NEXT:   .long   .Lfunc_begin3@IMGREL
287 ; CHECK-NEXT:   .long   5
288 ; CHECK-NEXT:   .long   .Lfunc_begin4@IMGREL
289 ; CHECK-NEXT:   .long   6