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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
|
// RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -emit-llvm -o - -mconstructor-aliases -fexceptions | FileCheck %s
// CHECK: @_ZN5test01AD1Ev = alias {{.*}} @_ZN5test01AD2Ev
// CHECK: @_ZN5test11MD2Ev = alias {{.*}} @_ZN5test11AD2Ev
// CHECK: @_ZN5test11ND2Ev = alias {{.*}} @_ZN5test11AD2Ev
// CHECK: @_ZN5test11OD2Ev = alias {{.*}} @_ZN5test11AD2Ev
// CHECK: @_ZN5test11SD2Ev = alias bitcast {{.*}} @_ZN5test11AD2Ev
// CHECK: @_ZN5test312_GLOBAL__N_11DD1Ev = alias internal {{.*}} @_ZN5test312_GLOBAL__N_11DD2Ev
// CHECK: @_ZN5test312_GLOBAL__N_11DD2Ev = alias internal bitcast {{.*}} @_ZN5test312_GLOBAL__N_11CD2Ev
// CHECK: @_ZN5test312_GLOBAL__N_11CD1Ev = alias internal {{.*}} @_ZN5test312_GLOBAL__N_11CD2Ev
struct A {
int a;
~A();
};
// Base with non-trivial destructor
struct B : A {
~B();
};
B::~B() { }
// Field with non-trivial destructor
struct C {
A a;
~C();
};
C::~C() { }
namespace PR7526 {
extern void foo();
struct allocator {
~allocator() throw();
};
struct allocator_derived : allocator { };
// CHECK: define void @_ZN6PR75269allocatorD2Ev
// CHECK: call void @__cxa_call_unexpected
allocator::~allocator() throw() { foo(); }
// CHECK: define linkonce_odr void @_ZN6PR752617allocator_derivedD1Ev
// CHECK-NOT: call void @__cxa_call_unexpected
// CHECK: }
void foo() {
allocator_derived ad;
}
}
// PR5084
template<typename T>
class A1 {
~A1();
};
template<> A1<char>::~A1();
// PR5529
namespace PR5529 {
struct A {
~A();
};
A::~A() { }
struct B : A {
virtual ~B();
};
B::~B() {}
}
// FIXME: there's a known problem in the codegen here where, if one
// destructor throws, the remaining destructors aren't run. Fix it,
// then make this code check for it.
namespace test0 {
void foo();
struct VBase { ~VBase(); };
struct Base { ~Base(); };
struct Member { ~Member(); };
struct A : Base {
Member M;
~A();
};
// The function-try-block won't suppress -mconstructor-aliases here.
A::~A() try { } catch (int i) {}
// complete destructor alias tested above
// CHECK: define void @_ZN5test01AD2Ev
// CHECK: invoke void @_ZN5test06MemberD1Ev
// CHECK: unwind label [[MEM_UNWIND:%[a-zA-Z0-9.]+]]
// CHECK: invoke void @_ZN5test04BaseD2Ev
// CHECK: unwind label [[BASE_UNWIND:%[a-zA-Z0-9.]+]]
struct B : Base, virtual VBase {
Member M;
~B();
};
B::~B() try { } catch (int i) {}
// It will suppress the delegation optimization here, though.
// CHECK: define void @_ZN5test01BD1Ev
// CHECK: invoke void @_ZN5test06MemberD1Ev
// CHECK: unwind label [[MEM_UNWIND:%[a-zA-Z0-9.]+]]
// CHECK: invoke void @_ZN5test04BaseD2Ev
// CHECK: unwind label [[BASE_UNWIND:%[a-zA-Z0-9.]+]]
// CHECK: invoke void @_ZN5test05VBaseD2Ev
// CHECK: unwind label [[VBASE_UNWIND:%[a-zA-Z0-9.]+]]
// CHECK: define void @_ZN5test01BD2Ev
// CHECK: invoke void @_ZN5test06MemberD1Ev
// CHECK: unwind label [[MEM_UNWIND:%[a-zA-Z0-9.]+]]
// CHECK: invoke void @_ZN5test04BaseD2Ev
// CHECK: unwind label [[BASE_UNWIND:%[a-zA-Z0-9.]+]]
}
// Test base-class aliasing.
namespace test1 {
struct A { ~A(); char ***m; }; // non-trivial destructor
struct B { ~B(); }; // non-trivial destructor
struct Empty { }; // trivial destructor, empty
struct NonEmpty { int x; }; // trivial destructor, non-empty
// There must be a definition in this translation unit for the alias
// optimization to apply.
A::~A() { delete m; }
struct M : A { ~M(); };
M::~M() {} // alias tested above
struct N : A, Empty { ~N(); };
N::~N() {} // alias tested above
struct O : Empty, A { ~O(); };
O::~O() {} // alias tested above
struct P : NonEmpty, A { ~P(); };
P::~P() {} // CHECK: define void @_ZN5test11PD2Ev
struct Q : A, B { ~Q(); };
Q::~Q() {} // CHECK: define void @_ZN5test11QD2Ev
struct R : A { ~R(); };
R::~R() { A a; } // CHECK: define void @_ZN5test11RD2Ev
struct S : A { ~S(); int x; };
S::~S() {} // alias tested above
struct T : A { ~T(); B x; };
T::~T() {} // CHECK: define void @_ZN5test11TD2Ev
// The VTT parameter prevents this. We could still make this work
// for calling conventions that are safe against extra parameters.
struct U : A, virtual B { ~U(); };
U::~U() {} // CHECK: define void @_ZN5test11UD2Ev
}
// PR6471
namespace test2 {
struct A { ~A(); char ***m; };
struct B : A { ~B(); };
B::~B() {}
// CHECK: define void @_ZN5test21BD2Ev
// CHECK: call void @_ZN5test21AD2Ev
}
// PR7142
namespace test3 {
struct A { virtual ~A(); };
struct B { virtual ~B(); };
namespace { // internal linkage => deferred
struct C : A, B {}; // ~B() in D requires a this-adjustment thunk
struct D : C {}; // D::~D() is an alias to C::~C()
}
void test() {
new D; // Force emission of D's vtable
}
// Checked at top of file:
// @_ZN5test312_GLOBAL__N_11CD1Ev = alias internal {{.*}} @_ZN5test312_GLOBAL__N_11CD2Ev
// More checks at end of file.
}
namespace test4 {
struct A { ~A(); };
// CHECK: define void @_ZN5test43fooEv()
// CHECK: call void @_ZN5test41AD1Ev
// CHECK: ret void
void foo() {
{
A a;
goto failure;
}
failure:
return;
}
// CHECK: define void @_ZN5test43barEi(
// CHECK: [[X:%.*]] = alloca i32
// CHECK-NEXT: [[A:%.*]] = alloca
// CHECK: br label
// CHECK: [[TMP:%.*]] = load i32* [[X]]
// CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[TMP]], 0
// CHECK-NEXT: br i1
// CHECK: call void @_ZN5test41AD1Ev(
// CHECK: br label
// CHECK: [[TMP:%.*]] = load i32* [[X]]
// CHECK: [[TMP2:%.*]] = add nsw i32 [[TMP]], -1
// CHECK: store i32 [[TMP2]], i32* [[X]]
// CHECK: br label
// CHECK: ret void
void bar(int x) {
for (A a; x; ) {
x--;
}
}
}
// PR7575
namespace test5 {
struct A { ~A(); };
// This is really unnecessarily verbose; we should be using phis,
// even at -O0.
// CHECK: define void @_ZN5test53fooEv()
// CHECK: [[ELEMS:%.*]] = alloca [5 x [[A:%.*]]], align
// CHECK-NEXT: [[IVAR:%.*]] = alloca i64
// CHECK: [[ELEMSARRAY:%.*]] = bitcast [5 x [[A]]]* [[ELEMS]] to [[A]]
// CHECK-NEXT: store i64 5, i64* [[IVAR]]
// CHECK-NEXT: br label
// CHECK: [[I:%.*]] = load i64* [[IVAR]]
// CHECK-NEXT: icmp ne i64 [[I]], 0
// CHECK-NEXT: br i1
// CHECK: [[I:%.*]] = load i64* [[IVAR]]
// CHECK-NEXT: [[I2:%.*]] = sub i64 [[I]], 1
// CHECK-NEXT: getelementptr inbounds [[A]]* [[ELEMSARRAY]], i64 [[I2]]
// CHECK-NEXT: call void @_ZN5test51AD1Ev(
// CHECK-NEXT: br label
// CHECK: [[I:%.*]] = load i64* [[IVAR]]
// CHECK-NEXT: [[I1:%.*]] = sub i64 [[I]], 1
// CHECK-NEXT: store i64 [[I1]], i64* [[IVAR]]
// CHECK-NEXT: br label
// CHECK: ret void
void foo() {
A elems[5];
}
}
// Checks from test3:
// CHECK: define internal void @_ZN5test312_GLOBAL__N_11CD2Ev(
// CHECK: call void @_ZN5test31BD2Ev(
// CHECK: call void @_ZN5test31AD2Ev(
// CHECK: ret void
// CHECK: define internal void @_ZN5test312_GLOBAL__N_11DD0Ev(
// CHECK: invoke void @_ZN5test312_GLOBAL__N_11DD1Ev(
// CHECK: call void @_ZdlPv({{.*}}) nounwind
// CHECK: ret void
// CHECK: call i8* @llvm.eh.exception(
// CHECK: call void @_ZdlPv({{.*}}) nounwind
// CHECK: call void @_Unwind_Resume_or_Rethrow
// Checked at top of file:
// @_ZN5test312_GLOBAL__N_11DD1Ev = alias internal {{.*}} @_ZN5test312_GLOBAL__N_11DD2Ev
// @_ZN5test312_GLOBAL__N_11DD2Ev = alias internal bitcast {{.*}} @_ZN5test312_GLOBAL__N_11CD2Ev
// CHECK: define internal void @_ZThn8_N5test312_GLOBAL__N_11DD1Ev(
// CHECK: getelementptr inbounds i8* {{.*}}, i64 -8
// CHECK: call void @_ZN5test312_GLOBAL__N_11DD1Ev(
// CHECK: ret void
// CHECK: define internal void @_ZThn8_N5test312_GLOBAL__N_11DD0Ev(
// CHECK: getelementptr inbounds i8* {{.*}}, i64 -8
// CHECK: call void @_ZN5test312_GLOBAL__N_11DD0Ev(
// CHECK: ret void
// CHECK: declare void @_ZN5test31BD2Ev(
// CHECK: declare void @_ZN5test31AD2Ev(
// CHECK: define internal void @_ZN5test312_GLOBAL__N_11CD0Ev(
// CHECK: invoke void @_ZN5test312_GLOBAL__N_11CD1Ev(
// CHECK: call void @_ZdlPv({{.*}}) nounwind
// CHECK: ret void
// CHECK: call i8* @llvm.eh.exception()
// CHECK: call void @_ZdlPv({{.*}}) nounwind
// CHECK: call void @_Unwind_Resume_or_Rethrow(
// CHECK: define internal void @_ZThn8_N5test312_GLOBAL__N_11CD1Ev(
// CHECK: getelementptr inbounds i8* {{.*}}, i64 -8
// CHECK: call void @_ZN5test312_GLOBAL__N_11CD1Ev(
// CHECK: ret void
// CHECK: define internal void @_ZThn8_N5test312_GLOBAL__N_11CD0Ev(
// CHECK: getelementptr inbounds i8* {{.*}}, i64 -8
// CHECK: call void @_ZN5test312_GLOBAL__N_11CD0Ev(
// CHECK: ret void
|