1 ; RUN: opt -mtriple=x86_64-pc-windows-msvc -winehprepare -S -o - < %s | FileCheck %s
3 ; This test is based on the following code:
11 ; void does_not_throw(int i);
12 ; void dump(int *, int, SomeData&);
15 ; int NumExceptions = 0;
16 ; int ExceptionVal[10];
17 ; SomeData Data = { 0, 0 };
19 ; for (int i = 0; i < 10; ++i) {
25 ; ExceptionVal[NumExceptions] = e;
32 ; does_not_throw(NumExceptions);
34 ; dump(ExceptionVal, NumExceptions, Data);
37 ; Unlike the cppeh-frame-vars.ll test, this test was generated using -O2
38 ; optimization, which results in non-alloca values being used in the
41 ; ModuleID = 'cppeh-frame-vars.cpp'
42 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
43 target triple = "x86_64-pc-windows-msvc"
45 %rtti.TypeDescriptor2 = type { i8**, i8*, [3 x i8] }
46 %struct.SomeData = type { i32, i32 }
48 $"\01??_R0H@8" = comdat any
50 @"\01??_7type_info@@6B@" = external constant i8*
51 @"\01??_R0H@8" = linkonce_odr global %rtti.TypeDescriptor2 { i8** @"\01??_7type_info@@6B@", i8* null, [3 x i8] c".H\00" }, comdat
53 ; This structure should be declared for the frame allocation block.
54 ; CHECK: %"struct.\01?test@@YAXXZ.ehdata" = type { i32, i8*, i32, i32, [10 x i32], i32, i32*, i32* }
56 ; The function entry should be rewritten like this.
57 ; CHECK: define void @"\01?test@@YAXXZ"() #0 {
59 ; CHECK: %frame.alloc = call i8* @llvm.frameallocate(i32 88)
60 ; CHECK: %eh.data = bitcast i8* %frame.alloc to %"struct.\01?test@@YAXXZ.ehdata"*
61 ; CHECK-NOT: %ExceptionVal = alloca [10 x i32], align 16
62 ; CHECK: %NumExceptions.020.reg2mem = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 3
63 ; CHECK: %i.019.reg2mem = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 5
64 ; CHECK: %ExceptionVal = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 4
65 ; CHECK: %Data = alloca i64, align 8
66 ; CHECK: %tmpcast = bitcast i64* %Data to %struct.SomeData*
67 ; CHECK: %0 = bitcast [10 x i32]* %ExceptionVal to i8*
68 ; CHECK: call void @llvm.lifetime.start(i64 40, i8* %0) #1
69 ; CHECK: store i64 0, i64* %Data, align 8
70 ; CHECK: %a.reg2mem = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 6
71 ; CHECK: %a = bitcast i64* %Data to i32*
72 ; CHECK: store i32* %a, i32** %a.reg2mem
73 ; CHECK: %b.reg2mem = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 7
74 ; CHECK: %b = getelementptr inbounds %struct.SomeData, %struct.SomeData* %tmpcast, i64 0, i32 1
75 ; CHECK: store i32* %b, i32** %b.reg2mem
76 ; CHECK: store i32 0, i32* %NumExceptions.020.reg2mem
77 ; CHECK: store i32 0, i32* %i.019.reg2mem
78 ; CHECK: br label %for.body
80 ; Function Attrs: uwtable
81 define void @"\01?test@@YAXXZ"() #0 {
83 %e = alloca i32, align 4
84 %ExceptionVal = alloca [10 x i32], align 16
85 %Data = alloca i64, align 8
86 %tmpcast = bitcast i64* %Data to %struct.SomeData*
87 %0 = bitcast [10 x i32]* %ExceptionVal to i8*
88 call void @llvm.lifetime.start(i64 40, i8* %0) #1
89 store i64 0, i64* %Data, align 8
90 %a = bitcast i64* %Data to i32*
91 %b = getelementptr inbounds %struct.SomeData, %struct.SomeData* %tmpcast, i64 0, i32 1
95 ; CHECK-NOT: %NumExceptions.020 = phi i32 [ 0, %entry ], [ %NumExceptions.1, %try.cont ]
96 ; CHECK-NOT: %i.019 = phi i32 [ 0, %entry ], [ %inc5, %try.cont ]
97 ; CHECK: %i.019.reload = load i32, i32* %i.019.reg2mem
98 ; CHECK: %NumExceptions.020.reload = load i32, i32* %NumExceptions.020.reg2mem
99 for.body: ; preds = %entry, %try.cont
100 %NumExceptions.020 = phi i32 [ 0, %entry ], [ %NumExceptions.1, %try.cont ]
101 %i.019 = phi i32 [ 0, %entry ], [ %inc5, %try.cont ]
102 invoke void @"\01?may_throw@@YAXXZ"()
103 to label %invoke.cont unwind label %lpad
105 ; CHECK: invoke.cont: ; preds = %for.body
106 ; CHECK-NOT: %1 = load i32, i32* %a, align 8, !tbaa !2
107 ; CHECK-NOT: %add = add nsw i32 %1, %i.019
108 ; CHECK-NOT: store i32 %add, i32* %a, align 8, !tbaa !2
109 ; CHECK: %a.reload3 = load volatile i32*, i32** %a.reg2mem
110 ; CHECK: %1 = load i32, i32* %a.reload3, align 8, !tbaa !2
111 ; CHECK: %add = add nsw i32 %1, %i.019.reload
112 ; CHECK: %a.reload2 = load volatile i32*, i32** %a.reg2mem
113 ; CHECK: store i32 %add, i32* %a.reload2, align 8, !tbaa !2
114 ; CHECK: br label %try.cont
115 invoke.cont: ; preds = %for.body
116 %1 = load i32, i32* %a, align 8, !tbaa !2
117 %add = add nsw i32 %1, %i.019
118 store i32 %add, i32* %a, align 8, !tbaa !2
121 lpad: ; preds = %for.body
122 %2 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
123 catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)
124 %3 = extractvalue { i8*, i32 } %2, 1
125 %4 = tail call i32 @llvm.eh.typeid.for(i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)) #1
126 %matches = icmp eq i32 %3, %4
127 br i1 %matches, label %catch, label %eh.resume
129 catch: ; preds = %lpad
130 %5 = extractvalue { i8*, i32 } %2, 0
131 %e.i8 = bitcast i32* %e to i8*
132 call void @llvm.eh.begincatch(i8* %5, i8* %e.i8) #1
133 %tmp8 = load i32, i32* %e, align 4, !tbaa !7
134 %idxprom = sext i32 %NumExceptions.020 to i64
135 %arrayidx = getelementptr inbounds [10 x i32], [10 x i32]* %ExceptionVal, i64 0, i64 %idxprom
136 store i32 %tmp8, i32* %arrayidx, align 4, !tbaa !7
137 %inc = add nsw i32 %NumExceptions.020, 1
138 %cmp1 = icmp eq i32 %tmp8, %i.019
139 br i1 %cmp1, label %if.then, label %if.else
141 if.then: ; preds = %catch
142 %tmp9 = load i32, i32* %b, align 4, !tbaa !8
143 %add2 = add nsw i32 %tmp9, %i.019
144 store i32 %add2, i32* %b, align 4, !tbaa !8
147 if.else: ; preds = %catch
148 %tmp10 = load i32, i32* %a, align 8, !tbaa !2
149 %add4 = add nsw i32 %tmp10, %tmp8
150 store i32 %add4, i32* %a, align 8, !tbaa !2
153 if.end: ; preds = %if.else, %if.then
154 tail call void @llvm.eh.endcatch() #1
157 ; CHECK: try.cont: ; preds = %if.end, %invoke.cont
158 ; CHECK-NOT: %NumExceptions.1 = phi i32 [ %NumExceptions.020, %invoke.cont ], [ %inc, %if.end ]
159 ; CHECK: %NumExceptions.1 = phi i32 [ %NumExceptions.020.reload, %invoke.cont ], [ %inc, %if.end ]
160 ; CHECK: tail call void @"\01?does_not_throw@@YAXH@Z"(i32 %NumExceptions.1)
161 ; CHECK-NOT: %inc5 = add nuw nsw i32 %i.019, 1
162 ; CHECK: %inc5 = add nuw nsw i32 %i.019.reload, 1
163 ; CHECK: %cmp = icmp slt i32 %inc5, 10
164 ; CHECK: store i32 %NumExceptions.1, i32* %NumExceptions.020.reg2mem
165 ; CHECK: store i32 %inc5, i32* %i.019.reg2mem
166 ; CHECK: br i1 %cmp, label %for.body, label %for.end
168 try.cont: ; preds = %if.end, %invoke.cont
169 %NumExceptions.1 = phi i32 [ %NumExceptions.020, %invoke.cont ], [ %inc, %if.end ]
170 tail call void @"\01?does_not_throw@@YAXH@Z"(i32 %NumExceptions.1)
171 %inc5 = add nuw nsw i32 %i.019, 1
172 %cmp = icmp slt i32 %inc5, 10
173 br i1 %cmp, label %for.body, label %for.end
175 for.end: ; preds = %try.cont
176 %NumExceptions.1.lcssa = phi i32 [ %NumExceptions.1, %try.cont ]
177 %arraydecay = getelementptr inbounds [10 x i32], [10 x i32]* %ExceptionVal, i64 0, i64 0
178 call void @"\01?dump@@YAXPEAHHAEAUSomeData@@@Z"(i32* %arraydecay, i32 %NumExceptions.1.lcssa, %struct.SomeData* dereferenceable(8) %tmpcast)
179 call void @llvm.lifetime.end(i64 40, i8* %0) #1
182 eh.resume: ; preds = %lpad
183 %.lcssa = phi { i8*, i32 } [ %2, %lpad ]
184 resume { i8*, i32 } %.lcssa
187 ; The following catch handler should be outlined.
188 ; CHECK: define internal i8* @"\01?test@@YAXXZ.catch"(i8*, i8*) {
190 ; CHECK: %eh.alloc = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1)
191 ; CHECK: %eh.data = bitcast i8* %eh.alloc to %"struct.\01?test@@YAXXZ.ehdata"*
192 ; CHECK: %eh.obj.ptr = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 1
193 ; CHECK: %eh.obj = load i8*, i8** %eh.obj.ptr
194 ; CHECK: %e = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 2
195 ; CHECK: %eh.temp.alloca = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 3
196 ; CHECK: %NumExceptions.020.reload = load i32, i32* %eh.temp.alloca
197 ; CHECK: %ExceptionVal = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 4
198 ; CHECK: %eh.temp.alloca1 = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 5
199 ; CHECK: %i.019.reload = load i32, i32* %eh.temp.alloca1
200 ; CHECK: %eh.temp.alloca2 = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 6
201 ; CHECK: %a.reload = load i32*, i32** %eh.temp.alloca2
202 ; CHECK: %eh.temp.alloca3 = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 7
203 ; CHECK: %b.reload = load i32*, i32** %eh.temp.alloca3
204 ; CHECK: %e.i8 = bitcast i32* %e to i8*
205 ; CHECK: %tmp8 = load i32, i32* %e, align 4, !tbaa !7
206 ; CHECK: %idxprom = sext i32 %NumExceptions.020.reload to i64
207 ; CHECK: %arrayidx = getelementptr inbounds [10 x i32], [10 x i32]* %ExceptionVal, i64 0, i64 %idxprom
208 ; CHECK: store i32 %tmp8, i32* %arrayidx, align 4, !tbaa !7
209 ; CHECK: %inc = add nsw i32 %NumExceptions.020.reload, 1
210 ; CHECK: %cmp1 = icmp eq i32 %tmp8, %i.019.reload
211 ; CHECK: br i1 %cmp1, label %if.then, label %if.else
213 ; CHECK: if.then: ; preds = %entry
214 ; CHECK: %tmp9 = load i32, i32* %b.reload, align 4, !tbaa !8
215 ; CHECK: %add2 = add nsw i32 %tmp9, %i.019.reload
216 ; CHECK: store i32 %add2, i32* %b.reload, align 4, !tbaa !8
217 ; CHECK: br label %if.end
219 ; CHECK: if.else: ; preds = %entry
220 ; CHECK: %tmp10 = load i32, i32* %a.reload, align 8, !tbaa !2
221 ; CHECK: %add4 = add nsw i32 %tmp10, %tmp8
222 ; CHECK: store i32 %add4, i32* %a.reload, align 8, !tbaa !2
223 ; CHECK: br label %if.end
225 ; CHECK: if.end: ; preds = %if.else, %if.then
226 ; CHECK: ret i8* blockaddress(@"\01?test@@YAXXZ", %try.cont)
229 ; Function Attrs: nounwind
230 declare void @llvm.lifetime.start(i64, i8* nocapture) #1
232 declare void @"\01?may_throw@@YAXXZ"() #2
234 declare i32 @__CxxFrameHandler3(...)
236 ; Function Attrs: nounwind readnone
237 declare i32 @llvm.eh.typeid.for(i8*) #3
239 declare void @llvm.eh.begincatch(i8*, i8*)
241 declare void @llvm.eh.endcatch()
243 declare void @"\01?does_not_throw@@YAXH@Z"(i32) #2
245 declare void @"\01?dump@@YAXPEAHHAEAUSomeData@@@Z"(i32*, i32, %struct.SomeData* dereferenceable(8)) #2
247 ; Function Attrs: nounwind
248 declare void @llvm.lifetime.end(i64, i8* nocapture) #1
250 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" }
251 attributes #1 = { nounwind }
252 attributes #2 = { "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" }
253 attributes #3 = { nounwind readnone }
255 !llvm.module.flags = !{!0}
258 !0 = !{i32 1, !"PIC Level", i32 2}
259 !1 = !{!"clang version 3.7.0 (trunk 228868)"}
260 !2 = !{!3, !4, i64 0}
261 !3 = !{!"?AUSomeData@@", !4, i64 0, !4, i64 4}
262 !4 = !{!"int", !5, i64 0}
263 !5 = !{!"omnipotent char", !6, i64 0}
264 !6 = !{!"Simple C/C++ TBAA"}
265 !7 = !{!4, !4, i64 0}
266 !8 = !{!3, !4, i64 4}