0a76a22208c2e9c8ac2a4daa62bc8d34b6f12c63
[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   1
40 ; CHECK-NEXT:        .long   ("$ip2state$?test1@@YAXXZ")@IMGREL
41 ; CHECK-NEXT:        .long   64
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   .Ltmp0@IMGREL
49 ; CHECK-NEXT:        .long   0
50
51 define void @"\01?test1@@YAXXZ"() #0 {
52 entry:
53   %unwindhelp = alloca i64
54   %tmp = alloca i32, align 4
55   %exn.slot = alloca i8*
56   %ehselector.slot = alloca i32
57   store i32 0, i32* %tmp
58   %0 = bitcast i32* %tmp to i8*
59   call void (...)* @llvm.frameescape()
60   store volatile i64 -2, i64* %unwindhelp
61   %1 = bitcast i64* %unwindhelp to i8*
62   call void @llvm.eh.unwindhelp(i8* %1)
63   invoke void @_CxxThrowException(i8* %0, %eh.ThrowInfo* @_TI1H) #8
64           to label %unreachable unwind label %lpad1
65
66 lpad1:                                            ; preds = %entry
67   %2 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
68           cleanup
69   %recover = call i8* (...)* @llvm.eh.actions(i32 0, void (i8*, i8*)* @"\01?test1@@YAXXZ.cleanup")
70   indirectbr i8* %recover, []
71
72 unreachable:                                      ; preds = %entry
73   unreachable
74 }
75
76 declare void @_CxxThrowException(i8*, %eh.ThrowInfo*)
77
78 declare i32 @__CxxFrameHandler3(...)
79
80 ; Function Attrs: nounwind
81 define linkonce_odr void @"\01??_DS@@QEAA@XZ"(%struct.S* %this) unnamed_addr #1 comdat align 2 {
82 entry:
83   %this.addr = alloca %struct.S*, align 8
84   store %struct.S* %this, %struct.S** %this.addr, align 8
85   %this1 = load %struct.S*, %struct.S** %this.addr
86   call void @"\01??1S@@QEAA@XZ"(%struct.S* %this1) #4
87   ret void
88 }
89
90 ; CHECK-LABEL: "?test2@@YAX_N@Z":
91 ; CHECK:             .seh_handlerdata
92 ; CHECK-NEXT:        .long   ("$cppxdata$?test2@@YAX_N@Z")@IMGREL
93 ; CHECK-NEXT:"$cppxdata$?test2@@YAX_N@Z":
94 ; CHECK-NEXT:        .long   429065506
95 ; CHECK-NEXT:        .long   2
96 ; CHECK-NEXT:        .long   ("$stateUnwindMap$?test2@@YAX_N@Z")@IMGREL
97 ; CHECK-NEXT:        .long   0
98 ; CHECK-NEXT:        .long   0
99 ; CHECK-NEXT:        .long   4
100 ; CHECK-NEXT:        .long   ("$ip2state$?test2@@YAX_N@Z")@IMGREL
101 ; CHECK-NEXT:        .long   64
102 ; CHECK-NEXT:        .long   0
103 ; CHECK-NEXT:        .long   1
104 ; CHECK-NEXT:"$stateUnwindMap$?test2@@YAX_N@Z":
105 ; CHECK-NEXT:        .long   -1
106 ; CHECK-NEXT:        .long   "?test2@@YAX_N@Z.cleanup"@IMGREL
107 ; CHECK-NEXT:        .long   0
108 ; CHECK-NEXT:        .long   "?test2@@YAX_N@Z.cleanup1"@IMGREL
109 ; CHECK-NEXT:"$ip2state$?test2@@YAX_N@Z":
110 ; CHECK-NEXT:        .long   .Lfunc_begin1@IMGREL
111 ; CHECK-NEXT:        .long   -1
112 ; CHECK-NEXT:        .long   .Ltmp7@IMGREL
113 ; CHECK-NEXT:        .long   0
114 ; CHECK-NEXT:        .long   .Ltmp9@IMGREL
115 ; CHECK-NEXT:        .long   1
116 ; CHECK-NEXT:        .long   .Ltmp12@IMGREL
117 ; CHECK-NEXT:        .long   0
118
119 define void @"\01?test2@@YAX_N@Z"(i1 zeroext %b) #2 {
120 entry:
121   %unwindhelp = alloca i64
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   %0 = bitcast i64* %unwindhelp to i8*
130   store volatile i64 -2, i64* %unwindhelp
131   call void (...)* @llvm.frameescape(%struct.S* %s, %struct.S* %s1)
132   call void @llvm.eh.unwindhelp(i8* %0)
133   call void @"\01?may_throw@@YAXXZ"()
134   invoke void @"\01?may_throw@@YAXXZ"()
135           to label %invoke.cont unwind label %lpad1
136
137 invoke.cont:                                      ; preds = %entry
138   %1 = load i8, i8* %b.addr, align 1
139   %tobool = trunc i8 %1 to i1
140   br i1 %tobool, label %if.then, label %if.else
141
142 if.then:                                          ; preds = %invoke.cont
143   invoke void @"\01?may_throw@@YAXXZ"()
144           to label %invoke.cont3 unwind label %lpad3
145
146 invoke.cont3:                                     ; preds = %if.then
147   call void @"\01??_DS@@QEAA@XZ"(%struct.S* %s1) #4
148   br label %if.end
149
150 lpad1:                                            ; preds = %entry, %if.end
151   %2 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
152           cleanup
153   %recover = call i8* (...)* @llvm.eh.actions(i32 0, void (i8*, i8*)* @"\01?test2@@YAX_N@Z.cleanup")
154   indirectbr i8* %recover, []
155
156 lpad3:                                            ; preds = %if.then
157   %3 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
158           cleanup
159   %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")
160   indirectbr i8* %recover4, []
161
162 if.else:                                          ; preds = %invoke.cont
163   call void @"\01?dont_throw@@YAXXZ"() #4
164   br label %if.end
165
166 if.end:                                           ; preds = %if.else, %invoke.cont3
167   invoke void @"\01?may_throw@@YAXXZ"()
168           to label %invoke.cont4 unwind label %lpad1
169
170 invoke.cont4:                                     ; preds = %if.end
171   call void @"\01??_DS@@QEAA@XZ"(%struct.S* %s) #4
172   ret void
173 }
174
175 declare void @"\01?may_throw@@YAXXZ"() #3
176
177 ; Function Attrs: nounwind
178 declare void @"\01?dont_throw@@YAXXZ"() #1
179
180 ; Function Attrs: nounwind
181 declare void @"\01??1S@@QEAA@XZ"(%struct.S*) #1
182
183 ; Function Attrs: nounwind
184 declare i8* @llvm.eh.actions(...) #4
185
186 define internal void @"\01?test1@@YAXXZ.cleanup"(i8*, i8*) #5 {
187 entry:
188   %s = alloca %struct.S, align 1
189   call void @"\01??_DS@@QEAA@XZ"(%struct.S* %s) #4
190   ret void
191 }
192
193 ; Function Attrs: nounwind
194 declare void @llvm.frameescape(...) #4
195
196 ; Function Attrs: nounwind readnone
197 declare i8* @llvm.framerecover(i8*, i8*, i32) #6
198
199 ; Function Attrs: nounwind
200 declare void @llvm.eh.unwindhelp(i8*) #4
201
202 define internal void @"\01?test2@@YAX_N@Z.cleanup"(i8*, i8*) #7 {
203 entry:
204   %s.i8 = call i8* @llvm.framerecover(i8* bitcast (void (i1)* @"\01?test2@@YAX_N@Z" to i8*), i8* %1, i32 0)
205   %s = bitcast i8* %s.i8 to %struct.S*
206   call void @"\01??_DS@@QEAA@XZ"(%struct.S* %s) #4
207   ret void
208 }
209
210 define internal void @"\01?test2@@YAX_N@Z.cleanup1"(i8*, i8*) #7 {
211 entry:
212   %s1.i8 = call i8* @llvm.framerecover(i8* bitcast (void (i1)* @"\01?test2@@YAX_N@Z" to i8*), i8* %1, i32 1)
213   %s1 = bitcast i8* %s1.i8 to %struct.S*
214   call void @"\01??_DS@@QEAA@XZ"(%struct.S* %s1) #4
215   ret void
216 }
217
218 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" }
219 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" }
220 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" }
221 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" }
222 attributes #4 = { nounwind }
223 attributes #5 = { "wineh-parent"="\ 1?test1@@YAXXZ" }
224 attributes #6 = { nounwind readnone }
225 attributes #7 = { "wineh-parent"="\ 1?test2@@YAX_N@Z" }
226 attributes #8 = { noreturn }