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 ; The function entry should be rewritten like this.
54 ; CHECK: define void @"\01?test@@YAXXZ"()
56 ; CHECK: [[NUMEXCEPTIONS_REGMEM:\%.+]] = alloca i32
57 ; CHECK: [[I_REGMEM:\%.+]] = alloca i32
58 ; CHECK: [[B_REGMEM:\%.+]] = alloca i32*
59 ; CHECK: [[A_REGMEM:\%.+]] = alloca i32*
60 ; CHECK: [[E_PTR:\%.+]] = alloca i32, align 4
61 ; CHECK: [[EXCEPTIONVAL:\%.+]] = alloca [10 x i32], align 16
62 ; CHECK: [[DATA_PTR:\%.+]] = alloca i64, align 8
63 ; CHECK: [[TMPCAST:\%.+]] = bitcast i64* [[DATA_PTR]] to %struct.SomeData*
64 ; CHECK: [[TMP:\%.+]] = bitcast [10 x i32]* [[EXCEPTIONVAL]] to i8*
65 ; CHECK: call void @llvm.lifetime.start(i64 40, i8* [[TMP]])
66 ; CHECK: store i64 0, i64* [[DATA_PTR]], align 8
67 ; CHECK: [[A_PTR:\%.+]] = bitcast i64* [[DATA_PTR]] to i32*
68 ; CHECK: store i32* [[A_PTR]], i32** [[A_REGMEM]]
69 ; CHECK: [[B_PTR:\%.+]] = getelementptr inbounds %struct.SomeData, %struct.SomeData* [[TMPCAST]], i64 0, i32 1
70 ; CHECK: store i32* [[B_PTR]], i32** [[B_REGMEM]]
71 ; CHECK: call void (...) @llvm.localescape(i32* %e, i32* %NumExceptions.020.reg2mem, [10 x i32]* [[EXCEPTIONVAL]], i32* %inc.reg2mem, i32* [[I_REGMEM]], i32** [[A_REGMEM]], i32** [[B_REGMEM]])
72 ; CHECK: br label %for.body
74 ; Function Attrs: uwtable
75 define void @"\01?test@@YAXXZ"() #0 personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
77 %e = alloca i32, align 4
78 %ExceptionVal = alloca [10 x i32], align 16
79 %Data = alloca i64, align 8
80 %tmpcast = bitcast i64* %Data to %struct.SomeData*
81 %0 = bitcast [10 x i32]* %ExceptionVal to i8*
82 call void @llvm.lifetime.start(i64 40, i8* %0) #1
83 store i64 0, i64* %Data, align 8
84 %a = bitcast i64* %Data to i32*
85 %b = getelementptr inbounds %struct.SomeData, %struct.SomeData* %tmpcast, i64 0, i32 1
89 ; CHECK: [[NUMEXCEPTIONS_PHI:\%.*]] = phi i32 [ 0, %entry ], [ {{\%NumExceptions.*}}, %try.cont ]
90 ; CHECK: [[I_PHI:\%.*]] = phi i32 [ 0, %entry ], [ {{\%inc.*}}, %try.cont ]
91 ; CHECK: store i32 [[I_PHI]], i32* [[I_REGMEM]]
92 ; CHECK: store i32 [[NUMEXCEPTIONS_PHI]], i32* [[NUMEXCEPTIONS_REGMEM]]
93 ; CHECK: invoke void @"\01?may_throw@@YAXXZ"()
94 for.body: ; preds = %entry, %try.cont
95 %NumExceptions.020 = phi i32 [ 0, %entry ], [ %NumExceptions.1, %try.cont ]
96 %i.019 = phi i32 [ 0, %entry ], [ %inc5, %try.cont ]
97 invoke void @"\01?may_throw@@YAXXZ"()
98 to label %invoke.cont unwind label %lpad
100 ; CHECK: invoke.cont: ; preds = %for.body
101 ; CHECK: [[A_RELOAD:\%.+]] = load i32*, i32** [[A_REGMEM]]
102 ; CHECK: [[TMP1:\%.+]] = load i32, i32* [[A_RELOAD]], align 8
103 ; CHECK: [[I_RELOAD:\%.+]] = load i32, i32* [[I_REGMEM]]
104 ; CHECK: [[ADD:\%.+]] = add nsw i32 [[TMP1]], [[I_RELOAD]]
105 ; CHECK: [[A_RELOAD1:\%.+]] = load i32*, i32** [[A_REGMEM]]
106 ; CHECK: [[NUMEXCEPTIONS_RELOAD:\%.+]] = load i32, i32* [[NUMEXCEPTIONS_REGMEM]]
107 ; CHECK: br label %try.cont
108 invoke.cont: ; preds = %for.body
109 %1 = load i32, i32* %a, align 8, !tbaa !2
110 %add = add nsw i32 %1, %i.019
111 store i32 %add, i32* %a, align 8, !tbaa !2
114 ; CHECK: [[LPAD_LABEL:lpad[0-9]*]]:{{[ ]+}}; preds = %for.body
115 ; CHECK: landingpad { i8*, i32 }
116 ; CHECK-NEXT: catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)
117 ; CHECK-NEXT: [[RECOVER:\%.+]] = call i8* (...) @llvm.eh.actions(i32 1, i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*), i32 0, i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch")
118 ; CHECK-NEXT: indirectbr i8* [[RECOVER]], [label %[[SPLIT_RECOVER_BB:.*]]]
120 lpad: ; preds = %for.body
121 %2 = landingpad { i8*, i32 }
122 catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)
123 %3 = extractvalue { i8*, i32 } %2, 1
124 %4 = tail call i32 @llvm.eh.typeid.for(i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)) #1
125 %matches = icmp eq i32 %3, %4
126 br i1 %matches, label %catch, label %eh.resume
130 catch: ; preds = %lpad
131 %5 = extractvalue { i8*, i32 } %2, 0
132 %e.i8 = bitcast i32* %e to i8*
133 call void @llvm.eh.begincatch(i8* %5, i8* %e.i8) #1
134 %tmp8 = load i32, i32* %e, align 4, !tbaa !7
135 %idxprom = sext i32 %NumExceptions.020 to i64
136 %arrayidx = getelementptr inbounds [10 x i32], [10 x i32]* %ExceptionVal, i64 0, i64 %idxprom
137 store i32 %tmp8, i32* %arrayidx, align 4, !tbaa !7
138 %inc = add nsw i32 %NumExceptions.020, 1
139 %cmp1 = icmp eq i32 %tmp8, %i.019
140 br i1 %cmp1, label %if.then, label %if.else
142 if.then: ; preds = %catch
143 %tmp9 = load i32, i32* %b, align 4, !tbaa !8
144 %add2 = add nsw i32 %tmp9, %i.019
145 store i32 %add2, i32* %b, align 4, !tbaa !8
148 ; CHECK-NOT: if.else:
150 if.else: ; preds = %catch
151 %tmp10 = load i32, i32* %a, align 8, !tbaa !2
152 %add4 = add nsw i32 %tmp10, %tmp8
153 store i32 %add4, i32* %a, align 8, !tbaa !2
157 ; CHECK: [[SPLIT_RECOVER_BB]]:
158 ; CHECK: [[INC_RELOAD:\%.*]] = load i32, i32*
159 ; CHECK: br label %try.cont
161 if.end: ; preds = %if.else, %if.then
162 tail call void @llvm.eh.endcatch() #1
165 ; CHECK: try.cont:{{[ ]+}}; preds = %[[SPLIT_RECOVER_BB]], %invoke.cont
166 ; CHECK: [[NUMEXCEPTIONS_PHI:\%.*]] = phi i32 [ [[NUMEXCEPTIONS_RELOAD]], %invoke.cont ], [ [[INC_RELOAD]], %[[SPLIT_RECOVER_BB]] ]
167 ; CHECK: tail call void @"\01?does_not_throw@@YAXH@Z"(i32 [[NUMEXCEPTIONS_PHI]])
168 ; CHECK: [[I_RELOAD:\%.+]] = load i32, i32* [[I_REGMEM]]
169 ; CHECK: [[INC:\%.+]] = add nuw nsw i32 [[I_RELOAD]], 1
170 ; CHECK: [[CMP:\%.+]] = icmp slt i32 [[INC]], 10
171 ; CHECK: br i1 [[CMP]], label %for.body, label %for.end
173 try.cont: ; preds = %if.end, %invoke.cont
174 %NumExceptions.1 = phi i32 [ %NumExceptions.020, %invoke.cont ], [ %inc, %if.end ]
175 tail call void @"\01?does_not_throw@@YAXH@Z"(i32 %NumExceptions.1)
176 %inc5 = add nuw nsw i32 %i.019, 1
177 %cmp = icmp slt i32 %inc5, 10
178 br i1 %cmp, label %for.body, label %for.end
180 for.end: ; preds = %try.cont
181 %NumExceptions.1.lcssa = phi i32 [ %NumExceptions.1, %try.cont ]
182 %arraydecay = getelementptr inbounds [10 x i32], [10 x i32]* %ExceptionVal, i64 0, i64 0
183 call void @"\01?dump@@YAXPEAHHAEAUSomeData@@@Z"(i32* %arraydecay, i32 %NumExceptions.1.lcssa, %struct.SomeData* dereferenceable(8) %tmpcast)
184 call void @llvm.lifetime.end(i64 40, i8* %0) #1
187 eh.resume: ; preds = %lpad
188 %.lcssa = phi { i8*, i32 } [ %2, %lpad ]
189 resume { i8*, i32 } %.lcssa
192 ; The following catch handler should be outlined.
193 ; CHECK: define internal i8* @"\01?test@@YAXXZ.catch"(i8*, i8*)
195 ; CHECK: [[RECOVER_E:\%.+]] = call i8* @llvm.localrecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 0)
196 ; CHECK: [[E_PTR:\%.+]] = bitcast i8* [[RECOVER_E]] to i32*
197 ; CHECK: [[RECOVER_NUMEXCEPTIONS:\%.+]] = call i8* @llvm.localrecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 1)
198 ; CHECK: [[NUMEXCEPTIONS_REGMEM:\%.+]] = bitcast i8* [[RECOVER_NUMEXCEPTIONS]] to i32*
199 ; CHECK: [[RECOVER_EXCEPTIONVAL:\%.+]] = call i8* @llvm.localrecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 2)
200 ; CHECK: [[EXCEPTIONVAL:\%.+]] = bitcast i8* [[RECOVER_EXCEPTIONVAL]] to [10 x i32]*
201 ; CHECK: [[RECOVER_INC:\%.+]] = call i8* @llvm.localrecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 3)
202 ; CHECK: [[INC_REGMEM:\%.+]] = bitcast i8* [[RECOVER_INC]] to i32*
203 ; CHECK: [[RECOVER_I:\%.+]] = call i8* @llvm.localrecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 4)
204 ; CHECK: [[I_REGMEM:\%.+]] = bitcast i8* [[RECOVER_I]] to i32*
205 ; CHECK: [[RECOVER_A:\%.+]] = call i8* @llvm.localrecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 5)
206 ; CHECK: [[A_REGMEM:\%.+]] = bitcast i8* [[RECOVER_A]] to i32**
207 ; CHECK: [[RECOVER_B:\%.+]] = call i8* @llvm.localrecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 6)
208 ; CHECK: [[B_REGMEM:\%.+]] = bitcast i8* [[RECOVER_B]] to i32**
209 ; CHECK: [[E_I8PTR:\%.+]] = bitcast i32* [[E_PTR]] to i8*
210 ; CHECK: [[TMP:\%.+]] = load i32, i32* [[E_PTR]], align 4
211 ; CHECK: [[NUMEXCEPTIONS_RELOAD:\%.+]] = load i32, i32* [[NUMEXCEPTIONS_REGMEM]]
212 ; CHECK: [[IDXPROM:\%.+]] = sext i32 [[NUMEXCEPTIONS_RELOAD]] to i64
213 ; CHECK: [[ARRAYIDX:\%.+]] = getelementptr inbounds [10 x i32], [10 x i32]* [[EXCEPTIONVAL]], i64 0, i64 [[IDXPROM]]
214 ; CHECK: store i32 [[TMP]], i32* [[ARRAYIDX]], align 4
215 ; CHECK: [[NUMEXCEPTIONS_RELOAD:\%.+]] = load i32, i32* [[NUMEXCEPTIONS_REGMEM]]
216 ; CHECK: [[INC:\%.+]] = add nsw i32 [[NUMEXCEPTIONS_RELOAD]], 1
217 ; CHECK: [[CMP:\%.+]] = icmp eq i32 [[TMP]], [[I_RELOAD]]
218 ; CHECK: br i1 [[CMP]], label %if.then, label %if.else
220 ; CHECK: if.then:{{[ ]+}}; preds = %entry
221 ; CHECK: [[B_RELOAD:\%.+]] = load i32*, i32** [[B_REGMEM]]
222 ; CHECK: [[TMP1:\%.+]] = load i32, i32* [[B_RELOAD]], align 4
223 ; CHECK: [[I_RELOAD:\%.+]] = load i32, i32* [[I_REGMEM]]
224 ; CHECK: [[ADD:\%.+]] = add nsw i32 [[TMP1]], [[I_RELOAD]]
225 ; CHECK: [[B_RELOAD:\%.+]] = load i32*, i32** [[B_REGMEM]]
226 ; CHECK: store i32 [[ADD]], i32* [[B_RELOAD]], align 4
227 ; CHECK: br label %if.end
229 ; CHECK: if.else:{{[ ]+}}; preds = %entry
230 ; CHECK: [[A_RELOAD:\%.+]] = load i32*, i32** [[A_REGMEM]]
231 ; CHECK: [[TMP2:\%.+]] = load i32, i32* [[A_RELOAD]], align 8
232 ; CHECK: [[ADD2:\%.+]] = add nsw i32 [[TMP2]], [[TMP]]
233 ; CHECK: [[A_RELOAD:\%.+]] = load i32*, i32** [[A_REGMEM]]
234 ; CHECK: store i32 [[ADD2]], i32* [[A_RELOAD]], align 8
235 ; CHECK: br label %if.end
237 ; CHECK: if.end:{{[ ]+}}; preds = %if.else, %if.then
238 ; CHECK: ret i8* blockaddress(@"\01?test@@YAXXZ", %[[SPLIT_RECOVER_BB]])
241 ; Function Attrs: nounwind
242 declare void @llvm.lifetime.start(i64, i8* nocapture) #1
244 declare void @"\01?may_throw@@YAXXZ"() #2
246 declare i32 @__CxxFrameHandler3(...)
248 ; Function Attrs: nounwind readnone
249 declare i32 @llvm.eh.typeid.for(i8*) #3
251 declare void @llvm.eh.begincatch(i8*, i8*)
253 declare void @llvm.eh.endcatch()
255 declare void @"\01?does_not_throw@@YAXH@Z"(i32) #2
257 declare void @"\01?dump@@YAXPEAHHAEAUSomeData@@@Z"(i32*, i32, %struct.SomeData* dereferenceable(8)) #2
259 ; Function Attrs: nounwind
260 declare void @llvm.lifetime.end(i64, i8* nocapture) #1
262 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" }
263 attributes #1 = { nounwind }
264 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" }
265 attributes #3 = { nounwind readnone }
267 !llvm.module.flags = !{!0}
270 !0 = !{i32 1, !"PIC Level", i32 2}
271 !1 = !{!"clang version 3.7.0 (trunk 228868)"}
272 !2 = !{!3, !4, i64 0}
273 !3 = !{!"?AUSomeData@@", !4, i64 0, !4, i64 4}
274 !4 = !{!"int", !5, i64 0}
275 !5 = !{!"omnipotent char", !6, i64 0}
276 !6 = !{!"Simple C/C++ TBAA"}
277 !7 = !{!4, !4, i64 0}
278 !8 = !{!3, !4, i64 4}