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 ; ModuleID = 'cppeh-frame-vars.cpp'
38 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
39 target triple = "x86_64-pc-windows-msvc"
41 %rtti.TypeDescriptor2 = type { i8**, i8*, [3 x i8] }
42 %struct.SomeData = type { i32, i32 }
44 $"\01??_R0H@8" = comdat any
46 @"\01??_7type_info@@6B@" = external constant i8*
47 @"\01??_R0H@8" = linkonce_odr global %rtti.TypeDescriptor2 { i8** @"\01??_7type_info@@6B@", i8* null, [3 x i8] c".H\00" }, comdat
49 ; The function entry should be rewritten like this.
50 ; CHECK: define void @"\01?test@@YAXXZ"() #0 {
52 ; CHECK: %NumExceptions = alloca i32, align 4
53 ; CHECK: %ExceptionVal = alloca [10 x i32], align 16
54 ; CHECK: %Data = alloca %struct.SomeData, align 4
55 ; CHECK: %i = alloca i32, align 4
56 ; CHECK: %exn.slot = alloca i8*
57 ; CHECK: %ehselector.slot = alloca i32
58 ; CHECK: %e = alloca i32, align 4
59 ; CHECK: store i32 0, i32* %NumExceptions, align 4
60 ; CHECK: %tmp = bitcast %struct.SomeData* %Data to i8*
61 ; CHECK: call void @llvm.memset(i8* %tmp, i8 0, i64 8, i32 4, i1 false)
62 ; CHECK: store i32 0, i32* %i, align 4
63 ; CHECK: call void (...)* @llvm.frameescape(i32* %e, i32* %NumExceptions, [10 x i32]* %ExceptionVal, i32* %i, %struct.SomeData* %Data)
64 ; CHECK: br label %for.cond
66 ; Function Attrs: uwtable
67 define void @"\01?test@@YAXXZ"() #0 {
69 %NumExceptions = alloca i32, align 4
70 %ExceptionVal = alloca [10 x i32], align 16
71 %Data = alloca %struct.SomeData, align 4
72 %i = alloca i32, align 4
73 %exn.slot = alloca i8*
74 %ehselector.slot = alloca i32
75 %e = alloca i32, align 4
76 store i32 0, i32* %NumExceptions, align 4
77 %tmp = bitcast %struct.SomeData* %Data to i8*
78 call void @llvm.memset(i8* %tmp, i8 0, i64 8, i32 4, i1 false)
79 store i32 0, i32* %i, align 4
82 for.cond: ; preds = %for.inc, %entry
83 %tmp1 = load i32, i32* %i, align 4
84 %cmp = icmp slt i32 %tmp1, 10
85 br i1 %cmp, label %for.body, label %for.end
87 for.body: ; preds = %for.cond
88 invoke void @"\01?may_throw@@YAXXZ"()
89 to label %invoke.cont unwind label %lpad
91 invoke.cont: ; preds = %for.body
92 %tmp2 = load i32, i32* %i, align 4
93 %a = getelementptr inbounds %struct.SomeData, %struct.SomeData* %Data, i32 0, i32 0
94 %tmp3 = load i32, i32* %a, align 4
95 %add = add nsw i32 %tmp3, %tmp2
96 store i32 %add, i32* %a, align 4
99 lpad: ; preds = %for.body
100 %tmp4 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
101 catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)
102 %tmp5 = extractvalue { i8*, i32 } %tmp4, 0
103 store i8* %tmp5, i8** %exn.slot
104 %tmp6 = extractvalue { i8*, i32 } %tmp4, 1
105 store i32 %tmp6, i32* %ehselector.slot
106 br label %catch.dispatch
108 catch.dispatch: ; preds = %lpad
109 %sel = load i32, i32* %ehselector.slot
110 %tmp7 = call i32 @llvm.eh.typeid.for(i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)) #1
111 %matches = icmp eq i32 %sel, %tmp7
112 br i1 %matches, label %catch, label %eh.resume
114 catch: ; preds = %catch.dispatch
115 %exn = load i8*, i8** %exn.slot
116 %e.i8 = bitcast i32* %e to i8*
117 call void @llvm.eh.begincatch(i8* %exn, i8* %e.i8) #1
118 %tmp11 = load i32, i32* %e, align 4
119 %tmp12 = load i32, i32* %NumExceptions, align 4
120 %idxprom = sext i32 %tmp12 to i64
121 %arrayidx = getelementptr inbounds [10 x i32], [10 x i32]* %ExceptionVal, i32 0, i64 %idxprom
122 store i32 %tmp11, i32* %arrayidx, align 4
123 %tmp13 = load i32, i32* %NumExceptions, align 4
124 %inc = add nsw i32 %tmp13, 1
125 store i32 %inc, i32* %NumExceptions, align 4
126 %tmp14 = load i32, i32* %e, align 4
127 %tmp15 = load i32, i32* %i, align 4
128 %cmp1 = icmp eq i32 %tmp14, %tmp15
129 br i1 %cmp1, label %if.then, label %if.else
131 if.then: ; preds = %catch
132 %tmp16 = load i32, i32* %e, align 4
133 %b = getelementptr inbounds %struct.SomeData, %struct.SomeData* %Data, i32 0, i32 1
134 %tmp17 = load i32, i32* %b, align 4
135 %add2 = add nsw i32 %tmp17, %tmp16
136 store i32 %add2, i32* %b, align 4
139 if.else: ; preds = %catch
140 %tmp18 = load i32, i32* %e, align 4
141 %a3 = getelementptr inbounds %struct.SomeData, %struct.SomeData* %Data, i32 0, i32 0
142 %tmp19 = load i32, i32* %a3, align 4
143 %add4 = add nsw i32 %tmp19, %tmp18
144 store i32 %add4, i32* %a3, align 4
147 if.end: ; preds = %if.else, %if.then
148 call void @llvm.eh.endcatch() #1
151 try.cont: ; preds = %if.end, %invoke.cont
152 %tmp20 = load i32, i32* %NumExceptions, align 4
153 call void @"\01?does_not_throw@@YAXH@Z"(i32 %tmp20)
156 for.inc: ; preds = %try.cont
157 %tmp21 = load i32, i32* %i, align 4
158 %inc5 = add nsw i32 %tmp21, 1
159 store i32 %inc5, i32* %i, align 4
162 for.end: ; preds = %for.cond
163 %tmp22 = load i32, i32* %NumExceptions, align 4
164 %arraydecay = getelementptr inbounds [10 x i32], [10 x i32]* %ExceptionVal, i32 0, i32 0
165 call void @"\01?dump@@YAXPEAHHAEAUSomeData@@@Z"(i32* %arraydecay, i32 %tmp22, %struct.SomeData* dereferenceable(8) %Data)
168 eh.resume: ; preds = %catch.dispatch
169 %exn6 = load i8*, i8** %exn.slot
170 %sel7 = load i32, i32* %ehselector.slot
171 %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn6, 0
172 %lpad.val8 = insertvalue { i8*, i32 } %lpad.val, i32 %sel7, 1
173 resume { i8*, i32 } %lpad.val8
176 ; The following catch handler should be outlined.
177 ; CHECK-LABEL: define internal i8* @"\01?test@@YAXXZ.catch"(i8*, i8*) {
179 ; CHECK: %e.i81 = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 0)
180 ; CHECK: %e = bitcast i8* %e.i81 to i32*
181 ; CHECK: %NumExceptions.i8 = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 1)
182 ; CHECK: %NumExceptions = bitcast i8* %NumExceptions.i8 to i32*
183 ; CHECK: %ExceptionVal.i8 = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 2)
184 ; CHECK: %ExceptionVal = bitcast i8* %ExceptionVal.i8 to [10 x i32]*
185 ; CHECK: %i.i8 = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 3)
186 ; CHECK: %i = bitcast i8* %i.i8 to i32*
187 ; CHECK: %Data.i8 = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 4)
188 ; CHECK: %Data = bitcast i8* %Data.i8 to %struct.SomeData*
189 ; CHECK: %tmp11 = load i32, i32* %e, align 4
190 ; CHECK: %tmp12 = load i32, i32* %NumExceptions, align 4
191 ; CHECK: %idxprom = sext i32 %tmp12 to i64
192 ; CHECK: %arrayidx = getelementptr inbounds [10 x i32], [10 x i32]* %ExceptionVal, i32 0, i64 %idxprom
193 ; CHECK: store i32 %tmp11, i32* %arrayidx, align 4
194 ; CHECK: %tmp13 = load i32, i32* %NumExceptions, align 4
195 ; CHECK: %inc = add nsw i32 %tmp13, 1
196 ; CHECK: store i32 %inc, i32* %NumExceptions, align 4
197 ; CHECK: %tmp14 = load i32, i32* %e, align 4
198 ; CHECK: %tmp15 = load i32, i32* %i, align 4
199 ; CHECK: %cmp1 = icmp eq i32 %tmp14, %tmp15
200 ; CHECK: br i1 %cmp1, label %if.then, label %if.else
202 ; CHECK: if.then: ; preds = %entry
203 ; CHECK: %tmp16 = load i32, i32* %e, align 4
204 ; CHECK: %b = getelementptr inbounds %struct.SomeData, %struct.SomeData* %Data, i32 0, i32 1
205 ; CHECK: %tmp17 = load i32, i32* %b, align 4
206 ; CHECK: %add2 = add nsw i32 %tmp17, %tmp16
207 ; CHECK: store i32 %add2, i32* %b, align 4
208 ; CHECK: br label %if.end
210 ; CHECK: if.else: ; preds = %entry
211 ; CHECK: %tmp18 = load i32, i32* %e, align 4
212 ; CHECK: %a3 = getelementptr inbounds %struct.SomeData, %struct.SomeData* %Data, i32 0, i32 0
213 ; CHECK: %tmp19 = load i32, i32* %a3, align 4
214 ; CHECK: %add4 = add nsw i32 %tmp19, %tmp18
215 ; CHECK: store i32 %add4, i32* %a3, align 4
216 ; CHECK: br label %if.end
218 ; CHECK: if.end: ; preds = %if.else, %if.then
219 ; CHECK: ret i8* blockaddress(@"\01?test@@YAXXZ", %try.cont)
227 ; Function Attrs: nounwind
228 declare void @llvm.memset(i8* nocapture, i8, i64, i32, i1) #1
230 declare void @"\01?may_throw@@YAXXZ"() #2
232 declare i32 @__CxxFrameHandler3(...)
234 ; Function Attrs: nounwind readnone
235 declare i32 @llvm.eh.typeid.for(i8*) #3
237 declare void @llvm.eh.begincatch(i8*, i8*)
239 declare void @llvm.eh.endcatch()
241 declare void @"\01?does_not_throw@@YAXH@Z"(i32) #2
243 declare void @"\01?dump@@YAXPEAHHAEAUSomeData@@@Z"(i32*, i32, %struct.SomeData* dereferenceable(8)) #2
245 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" }
246 attributes #1 = { nounwind }
247 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" }
248 attributes #3 = { nounwind readnone }
250 !llvm.module.flags = !{!0}
253 !0 = !{i32 1, !"PIC Level", i32 2}
254 !1 = !{!"clang version 3.7.0 (trunk 228868)"}