876cb53baba123d0058722886285d576e1310ef3
[oota-llvm.git] / test / CodeGen / WinEH / cppeh-prepared-cleanups.ll
1 ; RUN: llc < %s | FileCheck %s
2
3 target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
4 target triple = "x86_64-pc-windows-msvc"
5
6 %rtti.TypeDescriptor2 = type { i8**, i8*, [3 x i8] }
7 %eh.CatchableType = type { i32, i32, i32, i32, i32, i32, i32 }
8 %eh.CatchableTypeArray.1 = type { i32, [1 x i32] }
9 %eh.ThrowInfo = type { i32, i32, i32, i32 }
10 %struct.S = type { i8 }
11
12 $"\01??_DS@@QEAA@XZ" = comdat any
13
14 $"\01??_R0H@8" = comdat any
15
16 $"_CT??_R0H@84" = comdat any
17
18 $_CTA1H = comdat any
19
20 $_TI1H = comdat any
21
22 @"\01??_7type_info@@6B@" = external constant i8*
23 @"\01??_R0H@8" = linkonce_odr global %rtti.TypeDescriptor2 { i8** @"\01??_7type_info@@6B@", i8* null, [3 x i8] c".H\00" }, comdat
24 @__ImageBase = external constant i8
25 @"_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
26 @_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
27 @_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
28
29
30 ; CHECK-LABEL: "?test1@@YAXXZ":
31 ; CHECK:             .seh_handlerdata
32 ; CHECK-NEXT:        .long   ("$cppxdata$?test1@@YAXXZ")@IMGREL
33 ; CHECK-NEXT:"$cppxdata$?test1@@YAXXZ":
34 ; CHECK-NEXT:        .long   429065506
35 ; CHECK-NEXT:        .long   1
36 ; CHECK-NEXT:        .long   ("$stateUnwindMap$?test1@@YAXXZ")@IMGREL
37 ; CHECK-NEXT:        .long   0
38 ; CHECK-NEXT:        .long   0
39 ; CHECK-NEXT:        .long   2
40 ; CHECK-NEXT:        .long   ("$ip2state$?test1@@YAXXZ")@IMGREL
41 ; CHECK-NEXT:        .long   32
42 ; CHECK-NEXT:        .long   0
43 ; CHECK-NEXT:        .long   1
44 ; CHECK-NEXT:"$stateUnwindMap$?test1@@YAXXZ":
45 ; CHECK-NEXT:        .long   -1
46 ; CHECK-NEXT:        .long   "?test1@@YAXXZ.cleanup"@IMGREL
47 ; CHECK-NEXT:"$ip2state$?test1@@YAXXZ":
48 ; CHECK-NEXT:        .long   .Lfunc_begin0@IMGREL
49 ; CHECK-NEXT:        .long   -1
50 ; CHECK-NEXT:        .long   .Ltmp0@IMGREL
51 ; CHECK-NEXT:        .long   0
52
53 define void @"\01?test1@@YAXXZ"() #0 {
54 entry:
55   %unwindhelp = alloca i64
56   %tmp = alloca i32, align 4
57   %exn.slot = alloca i8*
58   %ehselector.slot = alloca i32
59   store i32 0, i32* %tmp
60   %0 = bitcast i32* %tmp to i8*
61   call void (...) @llvm.frameescape()
62   store volatile i64 -2, i64* %unwindhelp
63   %1 = bitcast i64* %unwindhelp to i8*
64   call void @llvm.eh.unwindhelp(i8* %1)
65   invoke void @_CxxThrowException(i8* %0, %eh.ThrowInfo* @_TI1H) #8
66           to label %unreachable unwind label %lpad1
67
68 lpad1:                                            ; preds = %entry
69   %2 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
70           cleanup
71   %recover = call i8* (...) @llvm.eh.actions(i32 0, void (i8*, i8*)* @"\01?test1@@YAXXZ.cleanup")
72   indirectbr i8* %recover, []
73
74 unreachable:                                      ; preds = %entry
75   unreachable
76 }
77
78 declare void @_CxxThrowException(i8*, %eh.ThrowInfo*)
79
80 declare i32 @__CxxFrameHandler3(...)
81
82 ; Function Attrs: nounwind
83 define linkonce_odr void @"\01??_DS@@QEAA@XZ"(%struct.S* %this) unnamed_addr #1 comdat align 2 {
84 entry:
85   %this.addr = alloca %struct.S*, align 8
86   store %struct.S* %this, %struct.S** %this.addr, align 8
87   %this1 = load %struct.S*, %struct.S** %this.addr
88   call void @"\01??1S@@QEAA@XZ"(%struct.S* %this1) #4
89   ret void
90 }
91
92 ; CHECK-LABEL: "?test2@@YAX_N@Z":
93 ; CHECK:             .seh_handlerdata
94 ; CHECK-NEXT:        .long   ("$cppxdata$?test2@@YAX_N@Z")@IMGREL
95 ; CHECK-NEXT:"$cppxdata$?test2@@YAX_N@Z":
96 ; CHECK-NEXT:        .long   429065506
97 ; CHECK-NEXT:        .long   2
98 ; CHECK-NEXT:        .long   ("$stateUnwindMap$?test2@@YAX_N@Z")@IMGREL
99 ; CHECK-NEXT:        .long   0
100 ; CHECK-NEXT:        .long   0
101 ; CHECK-NEXT:        .long   4
102 ; CHECK-NEXT:        .long   ("$ip2state$?test2@@YAX_N@Z")@IMGREL
103 ; CHECK-NEXT:        .long   40
104 ; CHECK-NEXT:        .long   0
105 ; CHECK-NEXT:        .long   1
106 ; CHECK-NEXT:"$stateUnwindMap$?test2@@YAX_N@Z":
107 ; CHECK-NEXT:        .long   -1
108 ; CHECK-NEXT:        .long   "?test2@@YAX_N@Z.cleanup"@IMGREL
109 ; CHECK-NEXT:        .long   0
110 ; CHECK-NEXT:        .long   "?test2@@YAX_N@Z.cleanup1"@IMGREL
111 ; CHECK-NEXT:"$ip2state$?test2@@YAX_N@Z":
112 ; CHECK-NEXT:        .long   .Lfunc_begin1@IMGREL
113 ; CHECK-NEXT:        .long   -1
114 ; CHECK-NEXT:        .long   .Ltmp7@IMGREL
115 ; CHECK-NEXT:        .long   0
116 ; CHECK-NEXT:        .long   .Ltmp9@IMGREL
117 ; CHECK-NEXT:        .long   1
118 ; CHECK-NEXT:        .long   .Ltmp12@IMGREL
119 ; CHECK-NEXT:        .long   0
120
121 define void @"\01?test2@@YAX_N@Z"(i1 zeroext %b) #2 {
122   %b.addr = alloca i8, align 1
123   %s = alloca %struct.S, align 1
124   %exn.slot = alloca i8*
125   %ehselector.slot = alloca i32
126   %s1 = alloca %struct.S, align 1
127   %frombool = zext i1 %b to i8
128   store i8 %frombool, i8* %b.addr, align 1
129   call void (...) @llvm.frameescape(%struct.S* %s, %struct.S* %s1)
130   call void @"\01?may_throw@@YAXXZ"()
131   invoke void @"\01?may_throw@@YAXXZ"()
132           to label %invoke.cont unwind label %lpad1
133
134 invoke.cont:                                      ; preds = %entry
135   %1 = load i8, i8* %b.addr, align 1
136   %tobool = trunc i8 %1 to i1
137   br i1 %tobool, label %if.then, label %if.else
138
139 if.then:                                          ; preds = %invoke.cont
140   invoke void @"\01?may_throw@@YAXXZ"()
141           to label %invoke.cont3 unwind label %lpad3
142
143 invoke.cont3:                                     ; preds = %if.then
144   call void @"\01??_DS@@QEAA@XZ"(%struct.S* %s1) #4
145   br label %if.end
146
147 lpad1:                                            ; preds = %entry, %if.end
148   %2 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
149           cleanup
150   %recover = call i8* (...) @llvm.eh.actions(i32 0, void (i8*, i8*)* @"\01?test2@@YAX_N@Z.cleanup")
151   indirectbr i8* %recover, []
152
153 lpad3:                                            ; preds = %if.then
154   %3 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
155           cleanup
156   %recover4 = call i8* (...) @llvm.eh.actions(i32 0, void (i8*, i8*)* @"\01?test2@@YAX_N@Z.cleanup1", i32 0, void (i8*, i8*)* @"\01?test2@@YAX_N@Z.cleanup")
157   indirectbr i8* %recover4, []
158
159 if.else:                                          ; preds = %invoke.cont
160   call void @"\01?dont_throw@@YAXXZ"() #4
161   br label %if.end
162
163 if.end:                                           ; preds = %if.else, %invoke.cont3
164   invoke void @"\01?may_throw@@YAXXZ"()
165           to label %invoke.cont4 unwind label %lpad1
166
167 invoke.cont4:                                     ; preds = %if.end
168   call void @"\01??_DS@@QEAA@XZ"(%struct.S* %s) #4
169   ret void
170 }
171
172 declare void @"\01?may_throw@@YAXXZ"() #3
173
174 ; Function Attrs: nounwind
175 declare void @"\01?dont_throw@@YAXXZ"() #1
176
177 ; Function Attrs: nounwind
178 declare void @"\01??1S@@QEAA@XZ"(%struct.S*) #1
179
180 ; Function Attrs: nounwind
181 declare i8* @llvm.eh.actions(...) #4
182
183 define internal void @"\01?test1@@YAXXZ.cleanup"(i8*, i8*) #5 {
184 entry:
185   %s = alloca %struct.S, align 1
186   call void @"\01??_DS@@QEAA@XZ"(%struct.S* %s) #4
187   ret void
188 }
189
190 ; Function Attrs: nounwind
191 declare void @llvm.frameescape(...) #4
192
193 ; Function Attrs: nounwind readnone
194 declare i8* @llvm.framerecover(i8*, i8*, i32) #6
195
196 ; Function Attrs: nounwind
197 declare void @llvm.eh.unwindhelp(i8*) #4
198
199 define internal void @"\01?test2@@YAX_N@Z.cleanup"(i8*, i8*) #7 {
200 entry:
201   %s.i8 = call i8* @llvm.framerecover(i8* bitcast (void (i1)* @"\01?test2@@YAX_N@Z" to i8*), i8* %1, i32 0)
202   %s = bitcast i8* %s.i8 to %struct.S*
203   call void @"\01??_DS@@QEAA@XZ"(%struct.S* %s) #4
204   invoke void @llvm.donothing()
205           to label %entry.split unwind label %stub
206
207 entry.split:                                      ; preds = %entry
208   ret void
209
210 stub:                                             ; preds = %entry
211   %2 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
212           cleanup
213   unreachable
214 }
215
216 define internal void @"\01?test2@@YAX_N@Z.cleanup1"(i8*, i8*) #7 {
217 entry:
218   %s1.i8 = call i8* @llvm.framerecover(i8* bitcast (void (i1)* @"\01?test2@@YAX_N@Z" to i8*), i8* %1, i32 1)
219   %s1 = bitcast i8* %s1.i8 to %struct.S*
220   call void @"\01??_DS@@QEAA@XZ"(%struct.S* %s1) #4
221   invoke void @llvm.donothing()
222           to label %entry.split unwind label %stub
223
224 entry.split:                                      ; preds = %entry
225   ret void
226
227 stub:                                             ; preds = %entry
228   %2 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
229           cleanup
230   unreachable
231 }
232
233 declare void @llvm.donothing()
234
235 attributes #0 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" "wineh-parent"="\ 1?test1@@YAXXZ" }
236 attributes #1 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
237 attributes #2 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" "wineh-parent"="\ 1?test2@@YAX_N@Z" }
238 attributes #3 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
239 attributes #4 = { nounwind }
240 attributes #5 = { "wineh-parent"="\ 1?test1@@YAXXZ" }
241 attributes #6 = { nounwind readnone }
242 attributes #7 = { "wineh-parent"="\ 1?test2@@YAX_N@Z" }
243 attributes #8 = { noreturn }