[opaque pointer type] Add textual IR support for explicit type parameter to the call...
[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:   [[OBJ_PTR:\%.+]] = alloca %class.SomeClass*, align 8
51 ; CHECK:   [[LL_PTR:\%.+]] = alloca i64, align 8
52 ; CHECK:   [[I_PTR:\%.+]] = alloca i32, align 4
53 ; CHECK:   call void (...) @llvm.frameescape(i32* [[I_PTR]], i64* [[LL_PTR]], %class.SomeClass** [[OBJ_PTR]])
54 ; CHECK:   invoke void @"\01?may_throw@@YAXXZ"()
55 ; CHECK:           to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]+]]
56
57 ; Function Attrs: uwtable
58 define void @"\01?test@@YAXXZ"() #0 {
59 entry:
60   %exn.slot = alloca i8*
61   %ehselector.slot = alloca i32
62   %obj = alloca %class.SomeClass*, align 8
63   %ll = alloca i64, align 8
64   %i = alloca i32, align 4
65   invoke void @"\01?may_throw@@YAXXZ"()
66           to label %invoke.cont unwind label %lpad
67
68 invoke.cont:                                      ; preds = %entry
69   br label %try.cont
70
71 ; CHECK: [[LPAD_LABEL]]:{{[ ]+}}; preds = %entry
72 ; CHECK:   landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
73 ; CHECK-NEXT:           catch %eh.HandlerMapEntry* @llvm.eh.handlermapentry.H
74 ; CHECK-NEXT:           catch %eh.HandlerMapEntry* @llvm.eh.handlermapentry._J
75 ; CHECK-NEXT:           catch %eh.HandlerMapEntry* @"llvm.eh.handlermapentry.reference.?AVSomeClass@@"
76 ; CHECK-NEXT:           catch i8* null
77 ; CHECK-NEXT:   [[RECOVER:\%.+]] = call i8* (...) @llvm.eh.actions(
78 ; CHECK-SAME:        i32 1, i8* bitcast (%eh.HandlerMapEntry* @llvm.eh.handlermapentry.H to i8*), i32 0, i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch",
79 ; CHECK-SAME:        i32 1, i8* bitcast (%eh.HandlerMapEntry* @llvm.eh.handlermapentry._J to i8*), i32 1, i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch1",
80 ; CHECK-SAME:        i32 1, i8* bitcast (%eh.HandlerMapEntry* @"llvm.eh.handlermapentry.reference.?AVSomeClass@@" to i8*), i32 2, i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch2",
81 ; CHECK-SAME:        i32 1, i8* null, i32 -1, i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch3")
82 ; CHECK-NEXT:   indirectbr i8* [[RECOVER]], [label %catch14.split, label %catch10.split, label %catch6.split, label %catch.split]
83
84 lpad:                                             ; preds = %entry
85   %0 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
86           catch %eh.HandlerMapEntry* @llvm.eh.handlermapentry.H
87           catch %eh.HandlerMapEntry* @llvm.eh.handlermapentry._J
88           catch %eh.HandlerMapEntry* @"llvm.eh.handlermapentry.reference.?AVSomeClass@@"
89           catch i8* null
90   %1 = extractvalue { i8*, i32 } %0, 0
91   store i8* %1, i8** %exn.slot
92   %2 = extractvalue { i8*, i32 } %0, 1
93   store i32 %2, i32* %ehselector.slot
94   br label %catch.dispatch
95
96 ; CHECK-NOT: catch.dispatch:
97 catch.dispatch:                                   ; preds = %lpad
98   %sel = load i32, i32* %ehselector.slot
99   %3 = call i32 @llvm.eh.typeid.for(i8* bitcast (%eh.HandlerMapEntry* @llvm.eh.handlermapentry.H to i8*)) #3
100   %matches = icmp eq i32 %sel, %3
101   br i1 %matches, label %catch14, label %catch.fallthrough
102
103 ; CHECK-NOT: catch14:
104 ; CHECK: catch14.split:
105 ; CHECK-NEXT:   ret void
106 catch14:                                          ; preds = %catch.dispatch
107   %exn15 = load i8*, i8** %exn.slot
108   %4 = bitcast i32* %i to i8*
109   call void @llvm.eh.begincatch(i8* %exn15, i8* %4) #3
110   %5 = load i32, i32* %i, align 4
111   call void @"\01?handle_int@@YAXH@Z"(i32 %5)
112   call void @llvm.eh.endcatch() #3
113   ret void
114
115 try.cont:                                         ; preds = %invoke.cont
116   ret void
117
118 ; CHECK-NOT: catch.fallthrough:
119 catch.fallthrough:                                ; preds = %catch.dispatch
120   %6 = call i32 @llvm.eh.typeid.for(i8* bitcast (%eh.HandlerMapEntry* @llvm.eh.handlermapentry._J to i8*)) #3
121   %matches1 = icmp eq i32 %sel, %6
122   br i1 %matches1, label %catch10, label %catch.fallthrough2
123
124 ; CHECK-NOT: catch10:
125 ; CHECK: catch10.split:
126 ; CHECK-NEXT:   ret void
127 catch10:                                          ; preds = %catch.fallthrough
128   %exn11 = load i8*, i8** %exn.slot
129   %7 = bitcast i64* %ll to i8*
130   call void @llvm.eh.begincatch(i8* %exn11, i8* %7) #3
131   %8 = load i64, i64* %ll, align 8
132   call void @"\01?handle_long_long@@YAX_J@Z"(i64 %8)
133   call void @llvm.eh.endcatch() #3
134   ret void
135
136 ; CHECK-NOT: catch.fallthrough2:
137 catch.fallthrough2:                               ; preds = %catch.fallthrough
138   %9 = call i32 @llvm.eh.typeid.for(i8* bitcast (%eh.HandlerMapEntry* @"llvm.eh.handlermapentry.reference.?AVSomeClass@@" to i8*)) #3
139   %matches3 = icmp eq i32 %sel, %9
140   br i1 %matches3, label %catch6, label %catch
141
142 ; CHECK-NOT: catch6:
143 ; CHECK: catch6.split:
144 ; CHECK-NEXT:   ret void
145 catch6:                                           ; preds = %catch.fallthrough2
146   %exn7 = load i8*, i8** %exn.slot
147   %10 = bitcast %class.SomeClass** %obj to i8*
148   call void @llvm.eh.begincatch(i8* %exn7, i8* %10) #3
149   %11 = load %class.SomeClass*, %class.SomeClass** %obj, align 8
150   call void @"\01?handle_obj@@YAXPEAVSomeClass@@@Z"(%class.SomeClass* %11)
151   call void @llvm.eh.endcatch() #3
152   ret void
153
154 ; CHECK-NOT: catch:
155 ; CHECK: catch.split:
156 ; CHECK-NEXT:   ret void
157 catch:                                            ; preds = %catch.fallthrough2
158   %exn = load i8*, i8** %exn.slot
159   call void @llvm.eh.begincatch(i8* %exn, i8* null) #3
160   call void @"\01?handle_exception@@YAXXZ"()  call void @llvm.eh.endcatch() #3
161   ret void
162 ; CHECK: }
163 }
164
165 ; CHECK-LABEL: define internal i8* @"\01?test@@YAXXZ.catch"(i8*, i8*)
166 ; CHECK: entry:
167 ; CHECK:   [[RECOVER_I:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 0)
168 ; CHECK:   [[I_PTR:\%.+]] = bitcast i8* [[RECOVER_I]] to i32*
169 ; CHECK:   [[TMP1:\%.+]] = load i32, i32* [[I_PTR]], align 4
170 ; CHECK:   call void @"\01?handle_int@@YAXH@Z"(i32 [[TMP1]])
171 ; CHECK:   ret i8* blockaddress(@"\01?test@@YAXXZ", %catch14.split)
172 ; CHECK: }
173
174 ; CHECK-LABEL: define internal i8* @"\01?test@@YAXXZ.catch1"(i8*, i8*)
175 ; CHECK: entry:
176 ; CHECK:   [[RECOVER_LL:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 1)
177 ; CHECK:   [[LL_PTR:\%.+]] = bitcast i8* [[RECOVER_LL]] to i64*
178 ; CHECK:   [[TMP2:\%.+]] = load i64, i64* [[LL_PTR]], align 8
179 ; CHECK:   call void @"\01?handle_long_long@@YAX_J@Z"(i64 [[TMP2]])
180 ; CHECK:   ret i8* blockaddress(@"\01?test@@YAXXZ", %catch10.split)
181 ; CHECK: }
182
183 ; CHECK-LABEL: define internal i8* @"\01?test@@YAXXZ.catch2"(i8*, i8*)
184 ; CHECK: entry:
185 ; CHECK:   [[RECOVER_OBJ:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 2)
186 ; CHECK:   [[OBJ_PTR:\%.+]] = bitcast i8* [[RECOVER_OBJ]] to %class.SomeClass**
187 ; CHECK:   [[TMP3:\%.+]] = load %class.SomeClass*, %class.SomeClass** [[OBJ_PTR]], align 8
188 ; CHECK:   call void @"\01?handle_obj@@YAXPEAVSomeClass@@@Z"(%class.SomeClass* [[TMP3]])
189 ; CHECK:   ret i8* blockaddress(@"\01?test@@YAXXZ", %catch6.split)
190 ; CHECK: }
191
192 ; CHECK-LABEL: define internal i8* @"\01?test@@YAXXZ.catch3"(i8*, i8*)
193 ; CHECK: entry:
194 ; CHECK:   call void @"\01?handle_exception@@YAXXZ"()
195 ; CHECK:   ret i8* blockaddress(@"\01?test@@YAXXZ", %catch.split)
196 ; CHECK: }
197
198
199 declare void @"\01?may_throw@@YAXXZ"() #1
200
201 declare i32 @__CxxFrameHandler3(...)
202
203 ; Function Attrs: nounwind readnone
204 declare i32 @llvm.eh.typeid.for(i8*) #2
205
206 ; Function Attrs: nounwind
207 declare void @llvm.eh.begincatch(i8* nocapture, i8* nocapture) #3
208
209 declare void @"\01?handle_exception@@YAXXZ"() #1
210
211 ; Function Attrs: nounwind
212 declare void @llvm.eh.endcatch() #3
213
214 declare void @"\01?handle_obj@@YAXPEAVSomeClass@@@Z"(%class.SomeClass*) #1
215
216 declare void @"\01?handle_long_long@@YAX_J@Z"(i64) #1
217
218 declare void @"\01?handle_int@@YAXH@Z"(i32) #1
219
220 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" }
221 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" }
222 attributes #2 = { nounwind readnone }
223 attributes #3 = { nounwind }
224
225 !llvm.module.flags = !{!0}
226 !llvm.ident = !{!1}
227
228 !0 = !{i32 1, !"PIC Level", i32 2}
229 !1 = !{!"clang version 3.7.0 (trunk 233155) (llvm/trunk 233153)"}