blob: 25224551cadc6d5d6d5cbb24945dea622cbe71f2 [file] [log] [blame]
Andrew Kaylor64622aa2015-04-01 17:21:25 +00001; 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'
23target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
24target 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
David Majnemer7fddecc2015-06-17 20:52:32 +000048; CHECK: define void @"\01?test@@YAXXZ"() #0 personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
Andrew Kaylor64622aa2015-04-01 17:21:25 +000049; CHECK: entry:
Andrew Kaylor64622aa2015-04-01 17:21:25 +000050; CHECK: [[OBJ_PTR:\%.+]] = alloca %class.SomeClass*, align 8
51; CHECK: [[LL_PTR:\%.+]] = alloca i64, align 8
52; CHECK: [[I_PTR:\%.+]] = alloca i32, align 4
David Blaikie23af6482015-04-16 23:24:18 +000053; CHECK: call void (...) @llvm.frameescape(i32* [[I_PTR]], i64* [[LL_PTR]], %class.SomeClass** [[OBJ_PTR]])
Andrew Kaylor64622aa2015-04-01 17:21:25 +000054; CHECK: invoke void @"\01?may_throw@@YAXXZ"()
Reid Kleckner2c3ccaa2015-04-24 16:22:19 +000055; CHECK: to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]*]]
Andrew Kaylor64622aa2015-04-01 17:21:25 +000056
57; Function Attrs: uwtable
David Majnemer7fddecc2015-06-17 20:52:32 +000058define void @"\01?test@@YAXXZ"() #0 personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
Andrew Kaylor64622aa2015-04-01 17:21:25 +000059entry:
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
68invoke.cont: ; preds = %entry
69 br label %try.cont
70
71; CHECK: [[LPAD_LABEL]]:{{[ ]+}}; preds = %entry
David Majnemer7fddecc2015-06-17 20:52:32 +000072; CHECK: landingpad { i8*, i32 }
Andrew Kaylor64622aa2015-04-01 17:21:25 +000073; 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
David Blaikie23af6482015-04-16 23:24:18 +000077; CHECK-NEXT: [[RECOVER:\%.+]] = call i8* (...) @llvm.eh.actions(
Reid Kleckner3567d272015-04-02 21:13:31 +000078; CHECK-SAME: i32 1, i8* bitcast (%eh.HandlerMapEntry* @llvm.eh.handlermapentry.H to i8*), i32 0, i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch",
Sunil Srivastavad79dfcb2015-05-12 16:47:30 +000079; CHECK-SAME: i32 1, i8* bitcast (%eh.HandlerMapEntry* @llvm.eh.handlermapentry._J to i8*), i32 1, i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch.1",
80; CHECK-SAME: i32 1, i8* bitcast (%eh.HandlerMapEntry* @"llvm.eh.handlermapentry.reference.?AVSomeClass@@" to i8*), i32 2, i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch.2",
81; CHECK-SAME: i32 1, i8* null, i32 -1, i8* (i8*, i8*)* @"\01?test@@YAXXZ.catch.3")
Reid Klecknerfd7df282015-04-22 21:05:21 +000082; CHECK-NEXT: indirectbr i8* [[RECOVER]], [label %ret]
Andrew Kaylor64622aa2015-04-01 17:21:25 +000083
84lpad: ; preds = %entry
David Majnemer7fddecc2015-06-17 20:52:32 +000085 %0 = landingpad { i8*, i32 }
Andrew Kaylor64622aa2015-04-01 17:21:25 +000086 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:
97catch.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
Reid Klecknerfd7df282015-04-22 21:05:21 +0000103ret:
104 ret void
105
Andrew Kaylor64622aa2015-04-01 17:21:25 +0000106; CHECK-NOT: catch14:
Reid Klecknerfd7df282015-04-22 21:05:21 +0000107; CHECK: ret:
Andrew Kaylor64622aa2015-04-01 17:21:25 +0000108; CHECK-NEXT: ret void
109catch14: ; preds = %catch.dispatch
110 %exn15 = load i8*, i8** %exn.slot
111 %4 = bitcast i32* %i to i8*
112 call void @llvm.eh.begincatch(i8* %exn15, i8* %4) #3
113 %5 = load i32, i32* %i, align 4
114 call void @"\01?handle_int@@YAXH@Z"(i32 %5)
115 call void @llvm.eh.endcatch() #3
Reid Klecknerfd7df282015-04-22 21:05:21 +0000116 br label %ret
Andrew Kaylor64622aa2015-04-01 17:21:25 +0000117
118try.cont: ; preds = %invoke.cont
Reid Klecknerfd7df282015-04-22 21:05:21 +0000119 br label %ret
Andrew Kaylor64622aa2015-04-01 17:21:25 +0000120
121; CHECK-NOT: catch.fallthrough:
122catch.fallthrough: ; preds = %catch.dispatch
123 %6 = call i32 @llvm.eh.typeid.for(i8* bitcast (%eh.HandlerMapEntry* @llvm.eh.handlermapentry._J to i8*)) #3
124 %matches1 = icmp eq i32 %sel, %6
125 br i1 %matches1, label %catch10, label %catch.fallthrough2
126
127; CHECK-NOT: catch10:
Andrew Kaylor64622aa2015-04-01 17:21:25 +0000128catch10: ; preds = %catch.fallthrough
129 %exn11 = load i8*, i8** %exn.slot
130 %7 = bitcast i64* %ll to i8*
131 call void @llvm.eh.begincatch(i8* %exn11, i8* %7) #3
132 %8 = load i64, i64* %ll, align 8
133 call void @"\01?handle_long_long@@YAX_J@Z"(i64 %8)
134 call void @llvm.eh.endcatch() #3
Reid Klecknerfd7df282015-04-22 21:05:21 +0000135 br label %ret
Andrew Kaylor64622aa2015-04-01 17:21:25 +0000136
137; CHECK-NOT: catch.fallthrough2:
138catch.fallthrough2: ; preds = %catch.fallthrough
139 %9 = call i32 @llvm.eh.typeid.for(i8* bitcast (%eh.HandlerMapEntry* @"llvm.eh.handlermapentry.reference.?AVSomeClass@@" to i8*)) #3
140 %matches3 = icmp eq i32 %sel, %9
141 br i1 %matches3, label %catch6, label %catch
142
143; CHECK-NOT: catch6:
Andrew Kaylor64622aa2015-04-01 17:21:25 +0000144catch6: ; preds = %catch.fallthrough2
145 %exn7 = load i8*, i8** %exn.slot
146 %10 = bitcast %class.SomeClass** %obj to i8*
147 call void @llvm.eh.begincatch(i8* %exn7, i8* %10) #3
148 %11 = load %class.SomeClass*, %class.SomeClass** %obj, align 8
149 call void @"\01?handle_obj@@YAXPEAVSomeClass@@@Z"(%class.SomeClass* %11)
150 call void @llvm.eh.endcatch() #3
Reid Klecknerfd7df282015-04-22 21:05:21 +0000151 br label %ret
Andrew Kaylor64622aa2015-04-01 17:21:25 +0000152
153; CHECK-NOT: catch:
Andrew Kaylor64622aa2015-04-01 17:21:25 +0000154catch: ; preds = %catch.fallthrough2
155 %exn = load i8*, i8** %exn.slot
156 call void @llvm.eh.begincatch(i8* %exn, i8* null) #3
157 call void @"\01?handle_exception@@YAXXZ"() call void @llvm.eh.endcatch() #3
Reid Klecknerfd7df282015-04-22 21:05:21 +0000158 br label %ret
Andrew Kaylor64622aa2015-04-01 17:21:25 +0000159; CHECK: }
160}
161
162; CHECK-LABEL: define internal i8* @"\01?test@@YAXXZ.catch"(i8*, i8*)
163; CHECK: entry:
164; CHECK: [[RECOVER_I:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 0)
165; CHECK: [[I_PTR:\%.+]] = bitcast i8* [[RECOVER_I]] to i32*
166; CHECK: [[TMP1:\%.+]] = load i32, i32* [[I_PTR]], align 4
167; CHECK: call void @"\01?handle_int@@YAXH@Z"(i32 [[TMP1]])
Reid Klecknerfd7df282015-04-22 21:05:21 +0000168; CHECK: ret i8* blockaddress(@"\01?test@@YAXXZ", %ret)
Andrew Kaylor64622aa2015-04-01 17:21:25 +0000169; CHECK: }
170
Sunil Srivastavad79dfcb2015-05-12 16:47:30 +0000171; CHECK-LABEL: define internal i8* @"\01?test@@YAXXZ.catch.1"(i8*, i8*)
Andrew Kaylor64622aa2015-04-01 17:21:25 +0000172; CHECK: entry:
173; CHECK: [[RECOVER_LL:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 1)
174; CHECK: [[LL_PTR:\%.+]] = bitcast i8* [[RECOVER_LL]] to i64*
175; CHECK: [[TMP2:\%.+]] = load i64, i64* [[LL_PTR]], align 8
176; CHECK: call void @"\01?handle_long_long@@YAX_J@Z"(i64 [[TMP2]])
Reid Klecknerfd7df282015-04-22 21:05:21 +0000177; CHECK: ret i8* blockaddress(@"\01?test@@YAXXZ", %ret)
Andrew Kaylor64622aa2015-04-01 17:21:25 +0000178; CHECK: }
179
Sunil Srivastavad79dfcb2015-05-12 16:47:30 +0000180; CHECK-LABEL: define internal i8* @"\01?test@@YAXXZ.catch.2"(i8*, i8*)
Andrew Kaylor64622aa2015-04-01 17:21:25 +0000181; CHECK: entry:
182; CHECK: [[RECOVER_OBJ:\%.+]] = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 2)
183; CHECK: [[OBJ_PTR:\%.+]] = bitcast i8* [[RECOVER_OBJ]] to %class.SomeClass**
184; CHECK: [[TMP3:\%.+]] = load %class.SomeClass*, %class.SomeClass** [[OBJ_PTR]], align 8
185; CHECK: call void @"\01?handle_obj@@YAXPEAVSomeClass@@@Z"(%class.SomeClass* [[TMP3]])
Reid Klecknerfd7df282015-04-22 21:05:21 +0000186; CHECK: ret i8* blockaddress(@"\01?test@@YAXXZ", %ret)
Andrew Kaylor64622aa2015-04-01 17:21:25 +0000187; CHECK: }
188
Sunil Srivastavad79dfcb2015-05-12 16:47:30 +0000189; CHECK-LABEL: define internal i8* @"\01?test@@YAXXZ.catch.3"(i8*, i8*)
Andrew Kaylor64622aa2015-04-01 17:21:25 +0000190; CHECK: entry:
191; CHECK: call void @"\01?handle_exception@@YAXXZ"()
Reid Klecknerfd7df282015-04-22 21:05:21 +0000192; CHECK: ret i8* blockaddress(@"\01?test@@YAXXZ", %ret)
Andrew Kaylor64622aa2015-04-01 17:21:25 +0000193; CHECK: }
194
195
196declare void @"\01?may_throw@@YAXXZ"() #1
197
198declare i32 @__CxxFrameHandler3(...)
199
200; Function Attrs: nounwind readnone
201declare i32 @llvm.eh.typeid.for(i8*) #2
202
203; Function Attrs: nounwind
204declare void @llvm.eh.begincatch(i8* nocapture, i8* nocapture) #3
205
206declare void @"\01?handle_exception@@YAXXZ"() #1
207
208; Function Attrs: nounwind
209declare void @llvm.eh.endcatch() #3
210
211declare void @"\01?handle_obj@@YAXPEAVSomeClass@@@Z"(%class.SomeClass*) #1
212
213declare void @"\01?handle_long_long@@YAX_J@Z"(i64) #1
214
215declare void @"\01?handle_int@@YAXH@Z"(i32) #1
216
217attributes #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" }
218attributes #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" }
219attributes #2 = { nounwind readnone }
220attributes #3 = { nounwind }
221
222!llvm.module.flags = !{!0}
223!llvm.ident = !{!1}
224
225!0 = !{i32 1, !"PIC Level", i32 2}
226!1 = !{!"clang version 3.7.0 (trunk 233155) (llvm/trunk 233153)"}