[WinEH] Make llvm.eh.actions use frameescape indices for catch params
[oota-llvm.git] / test / CodeGen / WinEH / cppeh-multi-catch.ll
1 ; RUN: opt -mtriple=x86_64-pc-windows-msvc -winehprepare -S -o - < %s | FileCheck %s
2
3 ; This test is based on the following code:
4 ;
5 ; void test()
6 ; {
7 ;   try {
8 ;     may_throw();
9 ;   } catch (int i) {
10 ;     handle_int(i);
11 ;   } catch (long long ll) {
12 ;     handle_long_long(ll);
13 ;   } catch (SomeClass &obj) {
14 ;     handle_obj(&obj);
15 ;   } catch (...) {
16 ;     handle_exception();
17 ;   }
18 ; }
19 ;
20 ; The catch handlers were edited to insert 'ret void' after the endcatch call.
21
22 ; ModuleID = 'catch-with-type.cpp'
23 target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
24 target triple = "x86_64-pc-windows-msvc"
25
26 %rtti.TypeDescriptor2 = type { i8**, i8*, [3 x i8] }
27 %eh.HandlerMapEntry = type { i32, i32 }
28 %rtti.TypeDescriptor3 = type { i8**, i8*, [4 x i8] }
29 %rtti.TypeDescriptor15 = type { i8**, i8*, [16 x i8] }
30 %class.SomeClass = type { i8 }
31
32 $"\01??_R0H@8" = comdat any
33
34 $"\01??_R0_J@8" = comdat any
35
36 $"\01??_R0?AVSomeClass@@@8" = comdat any
37
38 @"\01??_7type_info@@6B@" = external constant i8*
39 @"\01??_R0H@8" = linkonce_odr global %rtti.TypeDescriptor2 { i8** @"\01??_7type_info@@6B@", i8* null, [3 x i8] c".H\00" }, comdat
40 @__ImageBase = external constant i8
41 @llvm.eh.handlermapentry.H = private unnamed_addr constant %eh.HandlerMapEntry { i32 0, i32 trunc (i64 sub nuw nsw (i64 ptrtoint (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i64), i64 ptrtoint (i8* @__ImageBase to i64)) to i32) }, section "llvm.metadata"
42 @"\01??_R0_J@8" = linkonce_odr global %rtti.TypeDescriptor3 { i8** @"\01??_7type_info@@6B@", i8* null, [4 x i8] c"._J\00" }, comdat
43 @llvm.eh.handlermapentry._J = private unnamed_addr constant %eh.HandlerMapEntry { i32 0, i32 trunc (i64 sub nuw nsw (i64 ptrtoint (%rtti.TypeDescriptor3* @"\01??_R0_J@8" to i64), i64 ptrtoint (i8* @__ImageBase to i64)) to i32) }, section "llvm.metadata"
44 @"\01??_R0?AVSomeClass@@@8" = linkonce_odr global %rtti.TypeDescriptor15 { i8** @"\01??_7type_info@@6B@", i8* null, [16 x i8] c".?AVSomeClass@@\00" }, comdat
45 @"llvm.eh.handlermapentry.reference.?AVSomeClass@@" = private unnamed_addr constant %eh.HandlerMapEntry { i32 8, i32 trunc (i64 sub nuw nsw (i64 ptrtoint (%rtti.TypeDescriptor15* @"\01??_R0?AVSomeClass@@@8" to i64), i64 ptrtoint (i8* @__ImageBase to i64)) to i32) }, section "llvm.metadata"
46
47
48 ; CHECK: define void @"\01?test@@YAXXZ"() #0 {
49 ; CHECK: entry:
50 ; CHECK:   [[UNWINDHELP:\%.+]] = alloca i64
51 ; CHECK:   [[OBJ_PTR:\%.+]] = alloca %class.SomeClass*, align 8
52 ; CHECK:   [[LL_PTR:\%.+]] = alloca i64, align 8
53 ; CHECK:   [[I_PTR:\%.+]] = alloca i32, align 4
54 ; CHECK:   call void (...)* @llvm.frameescape(i32* [[I_PTR]], i64* [[LL_PTR]], %class.SomeClass** [[OBJ_PTR]])
55 ; CHECK:   store volatile i64 -2, i64* [[UNWINDHELP]]
56 ; CHECK:   [[TMP:\%.+]] = bitcast i64* [[UNWINDHELP]] to i8*
57 ; CHECK:   call void @llvm.eh.unwindhelp(i8* [[TMP]])
58 ; CHECK:   invoke void @"\01?may_throw@@YAXXZ"()
59 ; CHECK:           to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]+]]
60
61 ; Function Attrs: uwtable
62 define void @"\01?test@@YAXXZ"() #0 {
63 entry:
64   %exn.slot = alloca i8*
65   %ehselector.slot = alloca i32
66   %obj = alloca %class.SomeClass*, align 8
67   %ll = alloca i64, align 8
68   %i = alloca i32, align 4
69   invoke void @"\01?may_throw@@YAXXZ"()
70           to label %invoke.cont unwind label %lpad
71
72 invoke.cont:                                      ; preds = %entry
73   br label %try.cont
74
75 ; CHECK: [[LPAD_LABEL]]:{{[ ]+}}; preds = %entry
76 ; CHECK:   landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
77 ; CHECK-NEXT:           catch %eh.HandlerMapEntry* @llvm.eh.handlermapentry.H
78 ; CHECK-NEXT:           catch %eh.HandlerMapEntry* @llvm.eh.handlermapentry._J
79 ; CHECK-NEXT:           catch %eh.HandlerMapEntry* @"llvm.eh.handlermapentry.reference.?AVSomeClass@@"
80 ; CHECK-NEXT:           catch i8* null
81 ; CHECK-NEXT:   [[RECOVER:\%.+]] = call i8* (...)* @llvm.eh.actions(
82 ; CHECK-SAME:        i32 1, i8* bitcast (%eh.HandlerMapEntry* @llvm.eh.handlermapentry.H to i8*), i32 0, i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch",
83 ; CHECK-SAME:        i32 1, i8* bitcast (%eh.HandlerMapEntry* @llvm.eh.handlermapentry._J to i8*), i32 1, i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch1",
84 ; CHECK-SAME:        i32 1, i8* bitcast (%eh.HandlerMapEntry* @"llvm.eh.handlermapentry.reference.?AVSomeClass@@" to i8*), i32 2, i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch2",
85 ; CHECK-SAME:        i32 1, i8* null, i32 -1, i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch3")
86 ; CHECK-NEXT:   indirectbr i8* [[RECOVER]], [label %catch14.split, label %catch10.split, label %catch6.split, label %catch.split]
87
88 lpad:                                             ; preds = %entry
89   %0 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
90           catch %eh.HandlerMapEntry* @llvm.eh.handlermapentry.H
91           catch %eh.HandlerMapEntry* @llvm.eh.handlermapentry._J
92           catch %eh.HandlerMapEntry* @"llvm.eh.handlermapentry.reference.?AVSomeClass@@"
93           catch i8* null
94   %1 = extractvalue { i8*, i32 } %0, 0
95   store i8* %1, i8** %exn.slot
96   %2 = extractvalue { i8*, i32 } %0, 1
97   store i32 %2, i32* %ehselector.slot
98   br label %catch.dispatch
99
100 ; CHECK-NOT: catch.dispatch:
101 catch.dispatch:                                   ; preds = %lpad
102   %sel = load i32, i32* %ehselector.slot
103   %3 = call i32 @llvm.eh.typeid.for(i8* bitcast (%eh.HandlerMapEntry* @llvm.eh.handlermapentry.H to i8*)) #3
104   %matches = icmp eq i32 %sel, %3
105   br i1 %matches, label %catch14, label %catch.fallthrough
106
107 ; CHECK-NOT: catch14:
108 ; CHECK: catch14.split:
109 ; CHECK-NEXT:   ret void
110 catch14:                                          ; preds = %catch.dispatch
111   %exn15 = load i8*, i8** %exn.slot
112   %4 = bitcast i32* %i to i8*
113   call void @llvm.eh.begincatch(i8* %exn15, i8* %4) #3
114   %5 = load i32, i32* %i, align 4
115   call void @"\01?handle_int@@YAXH@Z"(i32 %5)
116   call void @llvm.eh.endcatch() #3
117   ret void
118
119 try.cont:                                         ; preds = %invoke.cont
120   ret void
121
122 ; CHECK-NOT: catch.fallthrough:
123 catch.fallthrough:                                ; preds = %catch.dispatch
124   %6 = call i32 @llvm.eh.typeid.for(i8* bitcast (%eh.HandlerMapEntry* @llvm.eh.handlermapentry._J to i8*)) #3
125   %matches1 = icmp eq i32 %sel, %6
126   br i1 %matches1, label %catch10, label %catch.fallthrough2
127
128 ; CHECK-NOT: catch10:
129 ; CHECK: catch10.split:
130 ; CHECK-NEXT:   ret void
131 catch10:                                          ; preds = %catch.fallthrough
132   %exn11 = load i8*, i8** %exn.slot
133   %7 = bitcast i64* %ll to i8*
134   call void @llvm.eh.begincatch(i8* %exn11, i8* %7) #3
135   %8 = load i64, i64* %ll, align 8
136   call void @"\01?handle_long_long@@YAX_J@Z"(i64 %8)
137   call void @llvm.eh.endcatch() #3
138   ret void
139
140 ; CHECK-NOT: catch.fallthrough2:
141 catch.fallthrough2:                               ; preds = %catch.fallthrough
142   %9 = call i32 @llvm.eh.typeid.for(i8* bitcast (%eh.HandlerMapEntry* @"llvm.eh.handlermapentry.reference.?AVSomeClass@@" to i8*)) #3
143   %matches3 = icmp eq i32 %sel, %9
144   br i1 %matches3, label %catch6, label %catch
145
146 ; CHECK-NOT: catch6:
147 ; CHECK: catch6.split:
148 ; CHECK-NEXT:   ret void
149 catch6:                                           ; preds = %catch.fallthrough2
150   %exn7 = load i8*, i8** %exn.slot
151   %10 = bitcast %class.SomeClass** %obj to i8*
152   call void @llvm.eh.begincatch(i8* %exn7, i8* %10) #3
153   %11 = load %class.SomeClass*, %class.SomeClass** %obj, align 8
154   call void @"\01?handle_obj@@YAXPEAVSomeClass@@@Z"(%class.SomeClass* %11)
155   call void @llvm.eh.endcatch() #3
156   ret void
157
158 ; CHECK-NOT: catch:
159 ; CHECK: catch.split:
160 ; CHECK-NEXT:   ret void
161 catch:                                            ; preds = %catch.fallthrough2
162   %exn = load i8*, i8** %exn.slot
163   call void @llvm.eh.begincatch(i8* %exn, i8* null) #3
164   call void @"\01?handle_exception@@YAXXZ"()  call void @llvm.eh.endcatch() #3
165   ret void
166 ; CHECK: }
167 }
168
169 ; CHECK-LABEL: define internal i8* @"\01?test@@YAXXZ.catch"(i8*, i8*)
170 ; CHECK: entry:
171 ; CHECK:   [[RECOVER_I:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 0)
172 ; CHECK:   [[I_PTR:\%.+]] = bitcast i8* [[RECOVER_I]] to i32*
173 ; CHECK:   [[TMP1:\%.+]] = load i32, i32* [[I_PTR]], align 4
174 ; CHECK:   call void @"\01?handle_int@@YAXH@Z"(i32 [[TMP1]])
175 ; CHECK:   ret i8* blockaddress(@"\01?test@@YAXXZ", %catch14.split)
176 ; CHECK: }
177
178 ; CHECK-LABEL: define internal i8* @"\01?test@@YAXXZ.catch1"(i8*, i8*)
179 ; CHECK: entry:
180 ; CHECK:   [[RECOVER_LL:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 1)
181 ; CHECK:   [[LL_PTR:\%.+]] = bitcast i8* [[RECOVER_LL]] to i64*
182 ; CHECK:   [[TMP2:\%.+]] = load i64, i64* [[LL_PTR]], align 8
183 ; CHECK:   call void @"\01?handle_long_long@@YAX_J@Z"(i64 [[TMP2]])
184 ; CHECK:   ret i8* blockaddress(@"\01?test@@YAXXZ", %catch10.split)
185 ; CHECK: }
186
187 ; CHECK-LABEL: define internal i8* @"\01?test@@YAXXZ.catch2"(i8*, i8*)
188 ; CHECK: entry:
189 ; CHECK:   [[RECOVER_OBJ:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 2)
190 ; CHECK:   [[OBJ_PTR:\%.+]] = bitcast i8* [[RECOVER_OBJ]] to %class.SomeClass**
191 ; CHECK:   [[TMP3:\%.+]] = load %class.SomeClass*, %class.SomeClass** [[OBJ_PTR]], align 8
192 ; CHECK:   call void @"\01?handle_obj@@YAXPEAVSomeClass@@@Z"(%class.SomeClass* [[TMP3]])
193 ; CHECK:   ret i8* blockaddress(@"\01?test@@YAXXZ", %catch6.split)
194 ; CHECK: }
195
196 ; CHECK-LABEL: define internal i8* @"\01?test@@YAXXZ.catch3"(i8*, i8*)
197 ; CHECK: entry:
198 ; CHECK:   call void @"\01?handle_exception@@YAXXZ"()
199 ; CHECK:   ret i8* blockaddress(@"\01?test@@YAXXZ", %catch.split)
200 ; CHECK: }
201
202
203 declare void @"\01?may_throw@@YAXXZ"() #1
204
205 declare i32 @__CxxFrameHandler3(...)
206
207 ; Function Attrs: nounwind readnone
208 declare i32 @llvm.eh.typeid.for(i8*) #2
209
210 ; Function Attrs: nounwind
211 declare void @llvm.eh.begincatch(i8* nocapture, i8* nocapture) #3
212
213 declare void @"\01?handle_exception@@YAXXZ"() #1
214
215 ; Function Attrs: nounwind
216 declare void @llvm.eh.endcatch() #3
217
218 declare void @"\01?handle_obj@@YAXPEAVSomeClass@@@Z"(%class.SomeClass*) #1
219
220 declare void @"\01?handle_long_long@@YAX_J@Z"(i64) #1
221
222 declare void @"\01?handle_int@@YAXH@Z"(i32) #1
223
224 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" }
225 attributes #1 = { "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" }
226 attributes #2 = { nounwind readnone }
227 attributes #3 = { nounwind }
228
229 !llvm.module.flags = !{!0}
230 !llvm.ident = !{!1}
231
232 !0 = !{i32 1, !"PIC Level", i32 2}
233 !1 = !{!"clang version 3.7.0 (trunk 233155) (llvm/trunk 233153)"}