blob: d40b174012ffc6371df4674180e795bc799afa39 [file] [log] [blame]
John McCall9fc6a772010-02-19 09:25:03 +00001// RUN: %clang_cc1 %s -emit-llvm -o - -mconstructor-aliases | FileCheck %s
John McCallc0bf4622010-02-23 00:48:20 +00002
3// CHECK: @_ZN5test01AD1Ev = alias {{.*}} @_ZN5test01AD2Ev
4// CHECK: @_ZN5test11MD2Ev = alias {{.*}} @_ZN5test11AD2Ev
5// CHECK: @_ZN5test11ND2Ev = alias {{.*}} @_ZN5test11AD2Ev
6// CHECK: @_ZN5test11OD2Ev = alias {{.*}} @_ZN5test11AD2Ev
7// CHECK: @_ZN5test11SD2Ev = alias bitcast {{.*}} @_ZN5test11AD2Ev
8
Anders Carlsson174754c2009-09-01 18:33:46 +00009struct A {
10 int a;
11
12 ~A();
13};
14
15// Base with non-trivial destructor
16struct B : A {
17 ~B();
18};
19
20B::~B() { }
21
22// Field with non-trivial destructor
23struct C {
24 A a;
25
26 ~C();
27};
28
Douglas Gregor45132722009-10-01 20:44:19 +000029C::~C() { }
30
31// PR5084
32template<typename T>
33class A1 {
34 ~A1();
35};
36
37template<> A1<char>::~A1();
Anders Carlsson9f853df2009-11-17 04:44:12 +000038
39// PR5529
40namespace PR5529 {
41 struct A {
42 ~A();
43 };
44
45 A::~A() { }
46 struct B : A {
47 virtual ~B();
48 };
49
50 B::~B() {}
51}
John McCall9fc6a772010-02-19 09:25:03 +000052
53// FIXME: there's a known problem in the codegen here where, if one
54// destructor throws, the remaining destructors aren't run. Fix it,
55// then make this code check for it.
56namespace test0 {
57 void foo();
58 struct VBase { ~VBase(); };
59 struct Base { ~Base(); };
60 struct Member { ~Member(); };
61
62 struct A : Base {
63 Member M;
64 ~A();
65 };
66
67 // The function-try-block won't suppress -mconstructor-aliases here.
68 A::~A() try { } catch (int i) {}
69
John McCallc0bf4622010-02-23 00:48:20 +000070// complete destructor alias tested above
John McCall9fc6a772010-02-19 09:25:03 +000071
72// CHECK: define void @_ZN5test01AD2Ev
73// CHECK: invoke void @_ZN5test06MemberD1Ev
74// CHECK: unwind label [[MEM_UNWIND:%[a-zA-Z0-9.]+]]
75// CHECK: invoke void @_ZN5test04BaseD2Ev
76// CHECK: unwind label [[BASE_UNWIND:%[a-zA-Z0-9.]+]]
77
78 struct B : Base, virtual VBase {
79 Member M;
80 ~B();
81 };
82 B::~B() try { } catch (int i) {}
83 // It will suppress the delegation optimization here, though.
84
85// CHECK: define void @_ZN5test01BD1Ev
86// CHECK: invoke void @_ZN5test06MemberD1Ev
87// CHECK: unwind label [[MEM_UNWIND:%[a-zA-Z0-9.]+]]
88// CHECK: invoke void @_ZN5test04BaseD2Ev
89// CHECK: unwind label [[BASE_UNWIND:%[a-zA-Z0-9.]+]]
90// CHECK: invoke void @_ZN5test05VBaseD2Ev
91// CHECK: unwind label [[VBASE_UNWIND:%[a-zA-Z0-9.]+]]
92
93// CHECK: define void @_ZN5test01BD2Ev
94// CHECK: invoke void @_ZN5test06MemberD1Ev
95// CHECK: unwind label [[MEM_UNWIND:%[a-zA-Z0-9.]+]]
96// CHECK: invoke void @_ZN5test04BaseD2Ev
97// CHECK: unwind label [[BASE_UNWIND:%[a-zA-Z0-9.]+]]
98}
John McCallc0bf4622010-02-23 00:48:20 +000099
100// Test base-class aliasing.
101namespace test1 {
102 struct A { ~A(); char ***m; }; // non-trivial destructor
103 struct B { ~B(); }; // non-trivial destructor
104 struct Empty { }; // trivial destructor, empty
105 struct NonEmpty { int x; }; // trivial destructor, non-empty
106
John McCall9a708462010-03-03 03:40:11 +0000107 // There must be a definition in this translation unit for the alias
108 // optimization to apply.
109 A::~A() { delete m; }
110
John McCallc0bf4622010-02-23 00:48:20 +0000111 struct M : A { ~M(); };
112 M::~M() {} // alias tested above
113
114 struct N : A, Empty { ~N(); };
115 N::~N() {} // alias tested above
116
117 struct O : Empty, A { ~O(); };
118 O::~O() {} // alias tested above
119
120 struct P : NonEmpty, A { ~P(); };
121 P::~P() {} // CHECK: define void @_ZN5test11PD2Ev
122
123 struct Q : A, B { ~Q(); };
124 Q::~Q() {} // CHECK: define void @_ZN5test11QD2Ev
125
126 struct R : A { ~R(); };
127 R::~R() { A a; } // CHECK: define void @_ZN5test11RD2Ev
128
129 struct S : A { ~S(); int x; };
130 S::~S() {} // alias tested above
131
132 struct T : A { ~T(); B x; };
133 T::~T() {} // CHECK: define void @_ZN5test11TD2Ev
134
135 // The VTT parameter prevents this. We could still make this work
136 // for calling conventions that are safe against extra parameters.
137 struct U : A, virtual B { ~U(); };
138 U::~U() {} // CHECK: define void @_ZN5test11UD2Ev
139}
John McCall9a708462010-03-03 03:40:11 +0000140
141// PR6471
142namespace test2 {
143 struct A { ~A(); char ***m; };
144 struct B : A { ~B(); };
145
146 B::~B() {}
147 // CHECK: define void @_ZN5test21BD2Ev
148 // CHECK: call void @_ZN5test21AD2Ev
149}