1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple=x86_64-pc-windows-msvc -mconstructor-aliases -fexceptions -fcxx-exceptions | FileCheck -check-prefix WIN64 %s
extern "C" void might_throw();
// Simplify the generated IR with noexcept.
extern "C" void recover() noexcept(true);
extern "C" void handle_exception(void *e) noexcept(true);
extern "C" void catch_all() {
try {
might_throw();
} catch (...) {
recover();
}
}
// WIN64-LABEL: define void @catch_all()
// WIN64: invoke void @might_throw()
// WIN64-NEXT: to label %[[cont:[^ ]*]] unwind label %[[lpad:[^ ]*]]
//
// WIN64: [[cont]]
// WIN64: br label %[[ret:[^ ]*]]
//
// WIN64: [[lpad]]
// WIN64: landingpad { i8*, i32 }
// WIN64-NEXT: catch i8* null
// WIN64: call void @llvm.eh.begincatch(i8* %{{[^,]*}}, i8* null)
// WIN64: call void @recover()
// WIN64: call void @llvm.eh.endcatch()
// WIN64: br label %[[ret]]
//
// WIN64: [[ret]]
// WIN64: ret void
extern "C" void catch_int() {
try {
might_throw();
} catch (int e) {
handle_exception(&e);
}
}
// WIN64-LABEL: define void @catch_int()
// WIN64: landingpad { i8*, i32 }
// WIN64: %[[e_i8:[^ ]*]] = bitcast i32* %[[e_addr:[^ ]*]] to i8*
// WIN64: call void @llvm.eh.begincatch(i8* %{{.*}}, i8* %[[e_i8]])
// WIN64: %[[e_i8:[^ ]*]] = bitcast i32* %[[e_addr]] to i8*
// WIN64: call void @handle_exception(i8* %[[e_i8]])
// WIN64: call void @llvm.eh.endcatch()
extern "C" void catch_int_unnamed() {
try {
might_throw();
} catch (int) {
}
}
// WIN64-LABEL: define void @catch_int_unnamed()
// WIN64: landingpad { i8*, i32 }
// WIN64: call void @llvm.eh.begincatch(i8* %{{.*}}, i8* null)
// WIN64: call void @llvm.eh.endcatch()
struct A {
A();
A(const A &o);
~A();
int a;
};
struct B : A {
B();
B(const B &o);
~B();
int b;
};
extern "C" void catch_a_byval() {
try {
might_throw();
} catch (A e) {
handle_exception(&e);
}
}
// WIN64-LABEL: define void @catch_a_byval()
// WIN64: %[[e_addr:[^ ]*]] = alloca %struct.A
// WIN64: landingpad { i8*, i32 }
// WIN64: %[[e_i8:[^ ]*]] = bitcast %struct.A* %[[e_addr]] to i8*
// WIN64: call void @llvm.eh.begincatch(i8* %{{.*}}, i8* %[[e_i8]])
// WIN64: %[[e_i8:[^ ]*]] = bitcast %struct.A* %[[e_addr]] to i8*
// WIN64: call void @handle_exception(i8* %[[e_i8]])
// WIN64: call void @llvm.eh.endcatch()
extern "C" void catch_a_ref() {
try {
might_throw();
} catch (A &e) {
handle_exception(&e);
}
}
// WIN64-LABEL: define void @catch_a_ref()
// WIN64: %[[e_addr:[^ ]*]] = alloca %struct.A*
// WIN64: landingpad { i8*, i32 }
// WIN64: %[[e_i8:[^ ]*]] = bitcast %struct.A** %[[e_addr]] to i8*
// WIN64: call void @llvm.eh.begincatch(i8* %{{.*}}, i8* %[[e_i8]])
// WIN64: %[[eptr:[^ ]*]] = load %struct.A*, %struct.A** %[[e_addr]]
// WIN64: %[[eptr_i8:[^ ]*]] = bitcast %struct.A* %[[eptr]] to i8*
// WIN64: call void @handle_exception(i8* %[[eptr_i8]])
// WIN64: call void @llvm.eh.endcatch()
extern "C" void fn_with_exc_spec() throw(int) {
might_throw();
}
// WIN64-LABEL: define void @fn_with_exc_spec()
// WIN64: call void @might_throw()
// WIN64-NEXT: ret void
extern "C" void catch_nested() {
try {
might_throw();
} catch (int) {
try {
might_throw();
} catch (int) {
might_throw();
}
}
}
// WIN64-LABEL: define void @catch_nested()
// WIN64: invoke void @might_throw()
// WIN64-NEXT: to label %[[cont1:[^ ]*]] unwind label %[[lp1:[^ ]*]]
// WIN64: [[cont1]]
//
// WIN64: [[lp1]]
// WIN64: landingpad { i8*, i32 }
// WIN64: call void @llvm.eh.begincatch(i8* %{{.*}}, i8* null)
// WIN64: invoke void @might_throw()
// WIN64-NEXT: to label %[[cont2:[^ ]*]] unwind label %[[lp2:[^ ]*]]
//
// WIN64: [[cont2]]
// WIN64-NEXT: br label %[[trycont:[^ ]*]]
//
// WIN64: [[lp2]]
// WIN64: landingpad { i8*, i32 }
// WIN64: call void @llvm.eh.begincatch(i8* %{{.*}}, i8* null)
// WIN64-NEXT: call void @might_throw()
// WIN64-NEXT: call void @llvm.eh.endcatch()
// WIN64-NEXT: br label %[[trycont]]
//
// WIN64: [[trycont]]
// WIN64: call void @llvm.eh.endcatch()
|