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 ; } catch (long long ll) {
12 ; handle_long_long(ll);
13 ; } catch (SomeClass &obj) {
20 ; The catch handlers were edited to insert 'ret void' after the endcatch call.
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"
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 }
32 $"\01??_R0H@8" = comdat any
34 $"\01??_R0_J@8" = comdat any
36 $"\01??_R0?AVSomeClass@@@8" = comdat any
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"
48 ; CHECK: define void @"\01?test@@YAXXZ"() #0 {
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]+]]
61 ; Function Attrs: uwtable
62 define void @"\01?test@@YAXXZ"() #0 {
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
72 invoke.cont: ; preds = %entry
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]
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@@"
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
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
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
119 try.cont: ; preds = %invoke.cont
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
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
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
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
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
169 ; CHECK-LABEL: define internal i8* @"\01?test@@YAXXZ.catch"(i8*, i8*)
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)
178 ; CHECK-LABEL: define internal i8* @"\01?test@@YAXXZ.catch1"(i8*, i8*)
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)
187 ; CHECK-LABEL: define internal i8* @"\01?test@@YAXXZ.catch2"(i8*, i8*)
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)
196 ; CHECK-LABEL: define internal i8* @"\01?test@@YAXXZ.catch3"(i8*, i8*)
198 ; CHECK: call void @"\01?handle_exception@@YAXXZ"()
199 ; CHECK: ret i8* blockaddress(@"\01?test@@YAXXZ", %catch.split)
203 declare void @"\01?may_throw@@YAXXZ"() #1
205 declare i32 @__CxxFrameHandler3(...)
207 ; Function Attrs: nounwind readnone
208 declare i32 @llvm.eh.typeid.for(i8*) #2
210 ; Function Attrs: nounwind
211 declare void @llvm.eh.begincatch(i8* nocapture, i8* nocapture) #3
213 declare void @"\01?handle_exception@@YAXXZ"() #1
215 ; Function Attrs: nounwind
216 declare void @llvm.eh.endcatch() #3
218 declare void @"\01?handle_obj@@YAXPEAVSomeClass@@@Z"(%class.SomeClass*) #1
220 declare void @"\01?handle_long_long@@YAX_J@Z"(i64) #1
222 declare void @"\01?handle_int@@YAXH@Z"(i32) #1
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 }
229 !llvm.module.flags = !{!0}
232 !0 = !{i32 1, !"PIC Level", i32 2}
233 !1 = !{!"clang version 3.7.0 (trunk 233155) (llvm/trunk 233153)"}