xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/destructors.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -emit-llvm -o - -mconstructor-aliases -fcxx-exceptions -fexceptions -O1 -disable-llvm-optzns > %t
2*0a6a1f1dSLionel Sambuc // RUN: FileCheck --check-prefix=CHECK1 --input-file=%t %s
3*0a6a1f1dSLionel Sambuc // RUN: FileCheck --check-prefix=CHECK2 --input-file=%t %s
4*0a6a1f1dSLionel Sambuc // RUN: FileCheck --check-prefix=CHECK3 --input-file=%t %s
5*0a6a1f1dSLionel Sambuc // RUN: FileCheck --check-prefix=CHECK4 --input-file=%t %s
6*0a6a1f1dSLionel Sambuc // RUN: FileCheck --check-prefix=CHECK5 --input-file=%t %s
7f4a2713aSLionel Sambuc 
8f4a2713aSLionel Sambuc struct A {
9f4a2713aSLionel Sambuc   int a;
10f4a2713aSLionel Sambuc 
11f4a2713aSLionel Sambuc   ~A();
12f4a2713aSLionel Sambuc };
13f4a2713aSLionel Sambuc 
14f4a2713aSLionel Sambuc // Base with non-trivial destructor
15f4a2713aSLionel Sambuc struct B : A {
16f4a2713aSLionel Sambuc   ~B();
17f4a2713aSLionel Sambuc };
18f4a2713aSLionel Sambuc 
~B()19f4a2713aSLionel Sambuc B::~B() { }
20f4a2713aSLionel Sambuc 
21f4a2713aSLionel Sambuc // Field with non-trivial destructor
22f4a2713aSLionel Sambuc struct C {
23f4a2713aSLionel Sambuc   A a;
24f4a2713aSLionel Sambuc 
25f4a2713aSLionel Sambuc   ~C();
26f4a2713aSLionel Sambuc };
27f4a2713aSLionel Sambuc 
~C()28f4a2713aSLionel Sambuc C::~C() { }
29f4a2713aSLionel Sambuc 
30f4a2713aSLionel Sambuc namespace PR7526 {
31f4a2713aSLionel Sambuc   extern void foo();
32f4a2713aSLionel Sambuc   struct allocator {
33f4a2713aSLionel Sambuc     ~allocator() throw();
34f4a2713aSLionel Sambuc   };
35f4a2713aSLionel Sambuc 
36f4a2713aSLionel Sambuc   struct allocator_derived : allocator { };
37f4a2713aSLionel Sambuc 
38*0a6a1f1dSLionel Sambuc   // CHECK1-LABEL: define void @_ZN6PR75263fooEv()
39*0a6a1f1dSLionel Sambuc   // CHECK1: call void {{.*}} @_ZN6PR75269allocatorD2Ev
40f4a2713aSLionel Sambuc 
41*0a6a1f1dSLionel Sambuc   // CHECK1-LABEL: define void @_ZN6PR75269allocatorD2Ev(%"struct.PR7526::allocator"* %this) unnamed_addr
42*0a6a1f1dSLionel Sambuc   // CHECK1: call void @__cxa_call_unexpected
~allocator()43f4a2713aSLionel Sambuc   allocator::~allocator() throw() { foo(); }
44f4a2713aSLionel Sambuc 
foo()45f4a2713aSLionel Sambuc   void foo() {
46f4a2713aSLionel Sambuc     allocator_derived ad;
47f4a2713aSLionel Sambuc   }
48f4a2713aSLionel Sambuc }
49f4a2713aSLionel Sambuc 
50f4a2713aSLionel Sambuc // PR5084
51f4a2713aSLionel Sambuc template<typename T>
52f4a2713aSLionel Sambuc class A1 {
53f4a2713aSLionel Sambuc   ~A1();
54f4a2713aSLionel Sambuc };
55f4a2713aSLionel Sambuc 
56f4a2713aSLionel Sambuc template<> A1<char>::~A1();
57f4a2713aSLionel Sambuc 
58f4a2713aSLionel Sambuc // PR5529
59f4a2713aSLionel Sambuc namespace PR5529 {
60f4a2713aSLionel Sambuc   struct A {
61f4a2713aSLionel Sambuc     ~A();
62f4a2713aSLionel Sambuc   };
63f4a2713aSLionel Sambuc 
~A()64f4a2713aSLionel Sambuc   A::~A() { }
65f4a2713aSLionel Sambuc   struct B : A {
66f4a2713aSLionel Sambuc     virtual ~B();
67f4a2713aSLionel Sambuc   };
68f4a2713aSLionel Sambuc 
~B()69f4a2713aSLionel Sambuc   B::~B()  {}
70f4a2713aSLionel Sambuc }
71f4a2713aSLionel Sambuc 
72f4a2713aSLionel Sambuc // FIXME: there's a known problem in the codegen here where, if one
73f4a2713aSLionel Sambuc // destructor throws, the remaining destructors aren't run.  Fix it,
74f4a2713aSLionel Sambuc // then make this code check for it.
75f4a2713aSLionel Sambuc namespace test0 {
76f4a2713aSLionel Sambuc   void foo();
77f4a2713aSLionel Sambuc   struct VBase { ~VBase(); };
78f4a2713aSLionel Sambuc   struct Base { ~Base(); };
79f4a2713aSLionel Sambuc   struct Member { ~Member(); };
80f4a2713aSLionel Sambuc 
81f4a2713aSLionel Sambuc   struct A : Base {
82f4a2713aSLionel Sambuc     Member M;
83f4a2713aSLionel Sambuc     ~A();
84f4a2713aSLionel Sambuc   };
85f4a2713aSLionel Sambuc 
86f4a2713aSLionel Sambuc   // The function-try-block won't suppress -mconstructor-aliases here.
~A()87f4a2713aSLionel Sambuc   A::~A() try { } catch (int i) {}
88f4a2713aSLionel Sambuc 
89f4a2713aSLionel Sambuc // complete destructor alias tested above
90f4a2713aSLionel Sambuc 
91*0a6a1f1dSLionel Sambuc // CHECK2-LABEL: @_ZN5test01AD1Ev = alias {{.*}} @_ZN5test01AD2Ev
92*0a6a1f1dSLionel Sambuc // CHECK2-LABEL: define void @_ZN5test01AD2Ev(%"struct.test0::A"* %this) unnamed_addr
93*0a6a1f1dSLionel Sambuc // CHECK2: invoke void @_ZN5test06MemberD1Ev
94*0a6a1f1dSLionel Sambuc // CHECK2:   unwind label [[MEM_UNWIND:%[a-zA-Z0-9.]+]]
95*0a6a1f1dSLionel Sambuc // CHECK2: invoke void @_ZN5test04BaseD2Ev
96*0a6a1f1dSLionel Sambuc // CHECK2:   unwind label [[BASE_UNWIND:%[a-zA-Z0-9.]+]]
97f4a2713aSLionel Sambuc 
98f4a2713aSLionel Sambuc   struct B : Base, virtual VBase {
99f4a2713aSLionel Sambuc     Member M;
100f4a2713aSLionel Sambuc     ~B();
101f4a2713aSLionel Sambuc   };
~B()102f4a2713aSLionel Sambuc   B::~B() try { } catch (int i) {}
103f4a2713aSLionel Sambuc   // It will suppress the delegation optimization here, though.
104f4a2713aSLionel Sambuc 
105*0a6a1f1dSLionel Sambuc // CHECK2-LABEL: define void @_ZN5test01BD2Ev(%"struct.test0::B"* %this, i8** %vtt) unnamed_addr
106*0a6a1f1dSLionel Sambuc // CHECK2: invoke void @_ZN5test06MemberD1Ev
107*0a6a1f1dSLionel Sambuc // CHECK2:   unwind label [[MEM_UNWIND:%[a-zA-Z0-9.]+]]
108*0a6a1f1dSLionel Sambuc // CHECK2: invoke void @_ZN5test04BaseD2Ev
109*0a6a1f1dSLionel Sambuc // CHECK2:   unwind label [[BASE_UNWIND:%[a-zA-Z0-9.]+]]
110f4a2713aSLionel Sambuc 
111*0a6a1f1dSLionel Sambuc // CHECK2-LABEL: define void @_ZN5test01BD1Ev(%"struct.test0::B"* %this) unnamed_addr
112*0a6a1f1dSLionel Sambuc // CHECK2: invoke void @_ZN5test06MemberD1Ev
113*0a6a1f1dSLionel Sambuc // CHECK2:   unwind label [[MEM_UNWIND:%[a-zA-Z0-9.]+]]
114*0a6a1f1dSLionel Sambuc // CHECK2: invoke void @_ZN5test04BaseD2Ev
115*0a6a1f1dSLionel Sambuc // CHECK2:   unwind label [[BASE_UNWIND:%[a-zA-Z0-9.]+]]
116*0a6a1f1dSLionel Sambuc // CHECK2: invoke void @_ZN5test05VBaseD2Ev
117*0a6a1f1dSLionel Sambuc // CHECK2:   unwind label [[VBASE_UNWIND:%[a-zA-Z0-9.]+]]
118f4a2713aSLionel Sambuc }
119f4a2713aSLionel Sambuc 
120f4a2713aSLionel Sambuc // Test base-class aliasing.
121f4a2713aSLionel Sambuc namespace test1 {
122f4a2713aSLionel Sambuc   struct A { ~A(); char ***m; }; // non-trivial destructor
123f4a2713aSLionel Sambuc   struct B { ~B(); }; // non-trivial destructor
124f4a2713aSLionel Sambuc   struct Empty { }; // trivial destructor, empty
125f4a2713aSLionel Sambuc   struct NonEmpty { int x; }; // trivial destructor, non-empty
126f4a2713aSLionel Sambuc 
127f4a2713aSLionel Sambuc   // There must be a definition in this translation unit for the alias
128f4a2713aSLionel Sambuc   // optimization to apply.
~A()129f4a2713aSLionel Sambuc   A::~A() { delete m; }
130f4a2713aSLionel Sambuc 
131f4a2713aSLionel Sambuc   struct M : A { ~M(); };
~M()132*0a6a1f1dSLionel Sambuc   M::~M() {}
133*0a6a1f1dSLionel Sambuc   // CHECK3: @_ZN5test11MD2Ev = alias {{.*}} @_ZN5test11AD2Ev
134f4a2713aSLionel Sambuc 
135f4a2713aSLionel Sambuc   struct N : A, Empty { ~N(); };
~N()136*0a6a1f1dSLionel Sambuc   N::~N() {}
137*0a6a1f1dSLionel Sambuc   // CHECK3: @_ZN5test11ND2Ev = alias {{.*}} @_ZN5test11AD2Ev
138f4a2713aSLionel Sambuc 
139f4a2713aSLionel Sambuc   struct O : Empty, A { ~O(); };
~O()140*0a6a1f1dSLionel Sambuc   O::~O() {}
141*0a6a1f1dSLionel Sambuc   // CHECK3: @_ZN5test11OD2Ev = alias {{.*}} @_ZN5test11AD2Ev
142f4a2713aSLionel Sambuc 
143f4a2713aSLionel Sambuc   struct P : NonEmpty, A { ~P(); };
~P()144*0a6a1f1dSLionel Sambuc   P::~P() {} // CHECK3-LABEL: define void @_ZN5test11PD2Ev(%"struct.test1::P"* %this) unnamed_addr
145f4a2713aSLionel Sambuc 
146f4a2713aSLionel Sambuc   struct Q : A, B { ~Q(); };
~Q()147*0a6a1f1dSLionel Sambuc   Q::~Q() {} // CHECK3-LABEL: define void @_ZN5test11QD2Ev(%"struct.test1::Q"* %this) unnamed_addr
148f4a2713aSLionel Sambuc 
149f4a2713aSLionel Sambuc   struct R : A { ~R(); };
~R()150*0a6a1f1dSLionel Sambuc   R::~R() { A a; } // CHECK3-LABEL: define void @_ZN5test11RD2Ev(%"struct.test1::R"* %this) unnamed_addr
151f4a2713aSLionel Sambuc 
152f4a2713aSLionel Sambuc   struct S : A { ~S(); int x; };
~S()153*0a6a1f1dSLionel Sambuc   S::~S() {}
154*0a6a1f1dSLionel Sambuc   // CHECK4: @_ZN5test11SD2Ev = alias bitcast {{.*}} @_ZN5test11AD2Ev
155f4a2713aSLionel Sambuc 
156f4a2713aSLionel Sambuc   struct T : A { ~T(); B x; };
~T()157*0a6a1f1dSLionel Sambuc   T::~T() {} // CHECK4-LABEL: define void @_ZN5test11TD2Ev(%"struct.test1::T"* %this) unnamed_addr
158f4a2713aSLionel Sambuc 
159f4a2713aSLionel Sambuc   // The VTT parameter prevents this.  We could still make this work
160f4a2713aSLionel Sambuc   // for calling conventions that are safe against extra parameters.
161f4a2713aSLionel Sambuc   struct U : A, virtual B { ~U(); };
~U()162*0a6a1f1dSLionel Sambuc   U::~U() {} // CHECK4-LABEL: define void @_ZN5test11UD2Ev(%"struct.test1::U"* %this, i8** %vtt) unnamed_addr
163f4a2713aSLionel Sambuc }
164f4a2713aSLionel Sambuc 
165f4a2713aSLionel Sambuc // PR6471
166f4a2713aSLionel Sambuc namespace test2 {
167f4a2713aSLionel Sambuc   struct A { ~A(); char ***m; };
168f4a2713aSLionel Sambuc   struct B : A { ~B(); };
169f4a2713aSLionel Sambuc 
~B()170f4a2713aSLionel Sambuc   B::~B() {}
171*0a6a1f1dSLionel Sambuc   // CHECK4-LABEL: define void @_ZN5test21BD2Ev(%"struct.test2::B"* %this) unnamed_addr
172*0a6a1f1dSLionel Sambuc   // CHECK4: call void @_ZN5test21AD2Ev
173f4a2713aSLionel Sambuc }
174f4a2713aSLionel Sambuc 
175f4a2713aSLionel Sambuc // PR7142
176f4a2713aSLionel Sambuc namespace test3 {
177f4a2713aSLionel Sambuc   struct A { virtual ~A(); };
178f4a2713aSLionel Sambuc   struct B { virtual ~B(); };
179f4a2713aSLionel Sambuc   namespace { // internal linkage => deferred
180f4a2713aSLionel Sambuc     struct C : A, B {}; // ~B() in D requires a this-adjustment thunk
181f4a2713aSLionel Sambuc     struct D : C {};    // D::~D() is an alias to C::~C()
182f4a2713aSLionel Sambuc   }
183f4a2713aSLionel Sambuc 
test()184f4a2713aSLionel Sambuc   void test() {
185f4a2713aSLionel Sambuc     new D; // Force emission of D's vtable
186f4a2713aSLionel Sambuc   }
187*0a6a1f1dSLionel Sambuc 
188*0a6a1f1dSLionel Sambuc   // CHECK4-LABEL: define internal void @_ZN5test312_GLOBAL__N_11DD0Ev(%"struct.test3::(anonymous namespace)::D"* %this) unnamed_addr
189*0a6a1f1dSLionel Sambuc   // CHECK4: invoke void {{.*}} @_ZN5test312_GLOBAL__N_11CD2Ev
190*0a6a1f1dSLionel Sambuc   // CHECK4: call void @_ZdlPv({{.*}}) [[NUW:#[0-9]+]]
191*0a6a1f1dSLionel Sambuc   // CHECK4: ret void
192*0a6a1f1dSLionel Sambuc   // CHECK4: landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
193*0a6a1f1dSLionel Sambuc   // CHECK4-NEXT: cleanup
194*0a6a1f1dSLionel Sambuc   // CHECK4: call void @_ZdlPv({{.*}}) [[NUW]]
195*0a6a1f1dSLionel Sambuc   // CHECK4: resume { i8*, i32 }
196*0a6a1f1dSLionel Sambuc 
197*0a6a1f1dSLionel Sambuc   // CHECK4-LABEL: define internal void @_ZThn8_N5test312_GLOBAL__N_11DD1Ev(
198*0a6a1f1dSLionel Sambuc   // CHECK4: getelementptr inbounds i8* {{.*}}, i64 -8
199*0a6a1f1dSLionel Sambuc   // CHECK4: call void {{.*}} @_ZN5test312_GLOBAL__N_11CD2Ev
200*0a6a1f1dSLionel Sambuc   // CHECK4: ret void
201*0a6a1f1dSLionel Sambuc 
202*0a6a1f1dSLionel Sambuc   // CHECK4-LABEL: define internal void @_ZThn8_N5test312_GLOBAL__N_11DD0Ev(
203*0a6a1f1dSLionel Sambuc   // CHECK4: getelementptr inbounds i8* {{.*}}, i64 -8
204*0a6a1f1dSLionel Sambuc   // CHECK4: call void @_ZN5test312_GLOBAL__N_11DD0Ev(
205*0a6a1f1dSLionel Sambuc   // CHECK4: ret void
206*0a6a1f1dSLionel Sambuc 
207*0a6a1f1dSLionel Sambuc   // CHECK4-LABEL: declare void @_ZN5test31BD2Ev(
208*0a6a1f1dSLionel Sambuc   // CHECK4-LABEL: declare void @_ZN5test31AD2Ev(
209*0a6a1f1dSLionel Sambuc 
210*0a6a1f1dSLionel Sambuc   // CHECK4-LABEL: define internal void @_ZN5test312_GLOBAL__N_11CD2Ev(%"struct.test3::(anonymous namespace)::C"* %this) unnamed_addr
211*0a6a1f1dSLionel Sambuc   // CHECK4: invoke void @_ZN5test31BD2Ev(
212*0a6a1f1dSLionel Sambuc   // CHECK4: call void @_ZN5test31AD2Ev(
213*0a6a1f1dSLionel Sambuc   // CHECK4: ret void
214*0a6a1f1dSLionel Sambuc 
215*0a6a1f1dSLionel Sambuc 
216*0a6a1f1dSLionel Sambuc   // CHECK4-LABEL: define internal void @_ZN5test312_GLOBAL__N_11CD0Ev(%"struct.test3::(anonymous namespace)::C"* %this) unnamed_addr
217*0a6a1f1dSLionel Sambuc   // CHECK4: invoke void @_ZN5test312_GLOBAL__N_11CD2Ev(
218*0a6a1f1dSLionel Sambuc   // CHECK4: call void @_ZdlPv({{.*}}) [[NUW]]
219*0a6a1f1dSLionel Sambuc   // CHECK4: ret void
220*0a6a1f1dSLionel Sambuc   // CHECK4: landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
221*0a6a1f1dSLionel Sambuc   // CHECK4-NEXT: cleanup
222*0a6a1f1dSLionel Sambuc   // CHECK4: call void @_ZdlPv({{.*}}) [[NUW]]
223*0a6a1f1dSLionel Sambuc   // CHECK4: resume { i8*, i32 }
224*0a6a1f1dSLionel Sambuc 
225*0a6a1f1dSLionel Sambuc   // CHECK4-LABEL: define internal void @_ZThn8_N5test312_GLOBAL__N_11CD1Ev(
226*0a6a1f1dSLionel Sambuc   // CHECK4: getelementptr inbounds i8* {{.*}}, i64 -8
227*0a6a1f1dSLionel Sambuc   // CHECK4: call void @_ZN5test312_GLOBAL__N_11CD2Ev(
228*0a6a1f1dSLionel Sambuc   // CHECK4: ret void
229*0a6a1f1dSLionel Sambuc 
230*0a6a1f1dSLionel Sambuc   // CHECK4-LABEL: define internal void @_ZThn8_N5test312_GLOBAL__N_11CD0Ev(
231*0a6a1f1dSLionel Sambuc   // CHECK4: getelementptr inbounds i8* {{.*}}, i64 -8
232*0a6a1f1dSLionel Sambuc   // CHECK4: call void @_ZN5test312_GLOBAL__N_11CD0Ev(
233*0a6a1f1dSLionel Sambuc   // CHECK4: ret void
234*0a6a1f1dSLionel Sambuc 
235*0a6a1f1dSLionel Sambuc   // CHECK4: attributes [[NUW]] = {{[{].*}} nounwind {{.*[}]}}
236f4a2713aSLionel Sambuc }
237f4a2713aSLionel Sambuc 
238f4a2713aSLionel Sambuc namespace test4 {
239f4a2713aSLionel Sambuc   struct A { ~A(); };
240f4a2713aSLionel Sambuc 
241*0a6a1f1dSLionel Sambuc   // CHECK5-LABEL: define void @_ZN5test43fooEv()
242*0a6a1f1dSLionel Sambuc   // CHECK5: call void @_ZN5test41AD1Ev
243*0a6a1f1dSLionel Sambuc   // CHECK5: ret void
foo()244f4a2713aSLionel Sambuc   void foo() {
245f4a2713aSLionel Sambuc     {
246f4a2713aSLionel Sambuc       A a;
247f4a2713aSLionel Sambuc       goto failure;
248f4a2713aSLionel Sambuc     }
249f4a2713aSLionel Sambuc 
250f4a2713aSLionel Sambuc   failure:
251f4a2713aSLionel Sambuc     return;
252f4a2713aSLionel Sambuc   }
253f4a2713aSLionel Sambuc 
254*0a6a1f1dSLionel Sambuc   // CHECK5-LABEL: define void @_ZN5test43barEi(
255*0a6a1f1dSLionel Sambuc   // CHECK5:      [[X:%.*]] = alloca i32
256*0a6a1f1dSLionel Sambuc   // CHECK5-NEXT: [[A:%.*]] = alloca
257*0a6a1f1dSLionel Sambuc   // CHECK5:      br label
258*0a6a1f1dSLionel Sambuc   // CHECK5:      [[TMP:%.*]] = load i32* [[X]]
259*0a6a1f1dSLionel Sambuc   // CHECK5-NEXT: [[CMP:%.*]] = icmp ne i32 [[TMP]], 0
260*0a6a1f1dSLionel Sambuc   // CHECK5-NEXT: br i1
261*0a6a1f1dSLionel Sambuc   // CHECK5:      call void @_ZN5test41AD1Ev(
262*0a6a1f1dSLionel Sambuc   // CHECK5:      br label
263*0a6a1f1dSLionel Sambuc   // CHECK5:      [[TMP:%.*]] = load i32* [[X]]
264*0a6a1f1dSLionel Sambuc   // CHECK5:      [[TMP2:%.*]] = add nsw i32 [[TMP]], -1
265*0a6a1f1dSLionel Sambuc   // CHECK5:      store i32 [[TMP2]], i32* [[X]]
266*0a6a1f1dSLionel Sambuc   // CHECK5:      br label
267*0a6a1f1dSLionel Sambuc   // CHECK5:      ret void
bar(int x)268f4a2713aSLionel Sambuc   void bar(int x) {
269f4a2713aSLionel Sambuc     for (A a; x; ) {
270f4a2713aSLionel Sambuc       x--;
271f4a2713aSLionel Sambuc     }
272f4a2713aSLionel Sambuc   }
273f4a2713aSLionel Sambuc }
274f4a2713aSLionel Sambuc 
275f4a2713aSLionel Sambuc // PR7575
276f4a2713aSLionel Sambuc namespace test5 {
277f4a2713aSLionel Sambuc   struct A { ~A(); };
278f4a2713aSLionel Sambuc 
279*0a6a1f1dSLionel Sambuc   // CHECK5-LABEL: define void @_ZN5test53fooEv()
280*0a6a1f1dSLionel Sambuc   // CHECK5:      [[ELEMS:%.*]] = alloca [5 x [[A:%.*]]], align
281*0a6a1f1dSLionel Sambuc   // CHECK5-NEXT: [[EXN:%.*]] = alloca i8*
282*0a6a1f1dSLionel Sambuc   // CHECK5-NEXT: [[SEL:%.*]] = alloca i32
283*0a6a1f1dSLionel Sambuc   // CHECK5-NEXT: [[BEGIN:%.*]] = getelementptr inbounds [5 x [[A]]]* [[ELEMS]], i32 0, i32 0
284*0a6a1f1dSLionel Sambuc   // CHECK5-NEXT: [[END:%.*]] = getelementptr inbounds [[A]]* [[BEGIN]], i64 5
285*0a6a1f1dSLionel Sambuc   // CHECK5-NEXT: br label
286*0a6a1f1dSLionel Sambuc   // CHECK5:      [[POST:%.*]] = phi [[A]]* [ [[END]], {{%.*}} ], [ [[ELT:%.*]], {{%.*}} ]
287*0a6a1f1dSLionel Sambuc   // CHECK5-NEXT: [[ELT]] = getelementptr inbounds [[A]]* [[POST]], i64 -1
288*0a6a1f1dSLionel Sambuc   // CHECK5-NEXT: invoke void @_ZN5test51AD1Ev([[A]]* [[ELT]])
289*0a6a1f1dSLionel Sambuc   // CHECK5:      [[T0:%.*]] = icmp eq [[A]]* [[ELT]], [[BEGIN]]
290*0a6a1f1dSLionel Sambuc   // CHECK5-NEXT: br i1 [[T0]],
291*0a6a1f1dSLionel Sambuc   // CHECK5:      ret void
292f4a2713aSLionel Sambuc   // lpad
293*0a6a1f1dSLionel Sambuc   // CHECK5:      [[EMPTY:%.*]] = icmp eq [[A]]* [[BEGIN]], [[ELT]]
294*0a6a1f1dSLionel Sambuc   // CHECK5-NEXT: br i1 [[EMPTY]]
295*0a6a1f1dSLionel Sambuc   // CHECK5:      [[AFTER:%.*]] = phi [[A]]* [ [[ELT]], {{%.*}} ], [ [[CUR:%.*]], {{%.*}} ]
296*0a6a1f1dSLionel Sambuc   // CHECK5-NEXT: [[CUR:%.*]] = getelementptr inbounds [[A]]* [[AFTER]], i64 -1
297*0a6a1f1dSLionel Sambuc   // CHECK5-NEXT: invoke void @_ZN5test51AD1Ev([[A]]* [[CUR]])
298*0a6a1f1dSLionel Sambuc   // CHECK5:      [[DONE:%.*]] = icmp eq [[A]]* [[CUR]], [[BEGIN]]
299*0a6a1f1dSLionel Sambuc   // CHECK5-NEXT: br i1 [[DONE]],
foo()300f4a2713aSLionel Sambuc   void foo() {
301f4a2713aSLionel Sambuc     A elems[5];
302f4a2713aSLionel Sambuc   }
303f4a2713aSLionel Sambuc }
304f4a2713aSLionel Sambuc 
305f4a2713aSLionel Sambuc namespace test6 {
306f4a2713aSLionel Sambuc   void opaque();
307f4a2713aSLionel Sambuc 
308f4a2713aSLionel Sambuc   struct A { ~A(); };
309f4a2713aSLionel Sambuc   template <unsigned> struct B { B(); ~B(); int _; };
310f4a2713aSLionel Sambuc   struct C : B<0>, B<1>, virtual B<2>, virtual B<3> {
311f4a2713aSLionel Sambuc     A x, y, z;
312f4a2713aSLionel Sambuc 
313f4a2713aSLionel Sambuc     C();
314f4a2713aSLionel Sambuc     ~C();
315f4a2713aSLionel Sambuc   };
316f4a2713aSLionel Sambuc 
C()317f4a2713aSLionel Sambuc   C::C() { opaque(); }
318*0a6a1f1dSLionel Sambuc   // CHECK5-LABEL: define void @_ZN5test61CC1Ev(%"struct.test6::C"* %this) unnamed_addr
319*0a6a1f1dSLionel Sambuc   // CHECK5:   call void @_ZN5test61BILj2EEC2Ev
320*0a6a1f1dSLionel Sambuc   // CHECK5:   invoke void @_ZN5test61BILj3EEC2Ev
321*0a6a1f1dSLionel Sambuc   // CHECK5:   invoke void @_ZN5test61BILj0EEC2Ev
322*0a6a1f1dSLionel Sambuc   // CHECK5:   invoke void @_ZN5test61BILj1EEC2Ev
323*0a6a1f1dSLionel Sambuc   // CHECK5:   invoke void @_ZN5test66opaqueEv
324*0a6a1f1dSLionel Sambuc   // CHECK5:   ret void
325f4a2713aSLionel Sambuc   // FIXME: way too much EH cleanup code follows
326f4a2713aSLionel Sambuc 
~C()327f4a2713aSLionel Sambuc   C::~C() { opaque(); }
328*0a6a1f1dSLionel Sambuc   // CHECK5-LABEL: define void @_ZN5test61CD2Ev(%"struct.test6::C"* %this, i8** %vtt) unnamed_addr
329*0a6a1f1dSLionel Sambuc   // CHECK5:   invoke void @_ZN5test66opaqueEv
330*0a6a1f1dSLionel Sambuc   // CHECK5:   invoke void @_ZN5test61AD1Ev
331*0a6a1f1dSLionel Sambuc   // CHECK5:   invoke void @_ZN5test61AD1Ev
332*0a6a1f1dSLionel Sambuc   // CHECK5:   invoke void @_ZN5test61AD1Ev
333*0a6a1f1dSLionel Sambuc   // CHECK5:   invoke void @_ZN5test61BILj1EED2Ev
334*0a6a1f1dSLionel Sambuc   // CHECK5:   call void @_ZN5test61BILj0EED2Ev
335*0a6a1f1dSLionel Sambuc   // CHECK5:   ret void
336*0a6a1f1dSLionel Sambuc   // CHECK5:   invoke void @_ZN5test61AD1Ev
337*0a6a1f1dSLionel Sambuc   // CHECK5:   invoke void @_ZN5test61AD1Ev
338*0a6a1f1dSLionel Sambuc   // CHECK5:   invoke void @_ZN5test61AD1Ev
339*0a6a1f1dSLionel Sambuc   // CHECK5:   invoke void @_ZN5test61BILj1EED2Ev
340*0a6a1f1dSLionel Sambuc   // CHECK5:   invoke void @_ZN5test61BILj0EED2Ev
341f4a2713aSLionel Sambuc 
342*0a6a1f1dSLionel Sambuc   // CHECK5-LABEL: define void @_ZN5test61CD1Ev(%"struct.test6::C"* %this) unnamed_addr
343*0a6a1f1dSLionel Sambuc   // CHECK5:   invoke void @_ZN5test61CD2Ev
344*0a6a1f1dSLionel Sambuc   // CHECK5:   invoke void @_ZN5test61BILj3EED2Ev
345*0a6a1f1dSLionel Sambuc   // CHECK5:   call void @_ZN5test61BILj2EED2Ev
346*0a6a1f1dSLionel Sambuc   // CHECK5:   ret void
347*0a6a1f1dSLionel Sambuc   // CHECK5:   invoke void @_ZN5test61BILj3EED2Ev
348*0a6a1f1dSLionel Sambuc   // CHECK5:   invoke void @_ZN5test61BILj2EED2Ev
349f4a2713aSLionel Sambuc }
350f4a2713aSLionel Sambuc 
351f4a2713aSLionel Sambuc // PR 9197
352f4a2713aSLionel Sambuc namespace test7 {
353f4a2713aSLionel Sambuc   struct D { ~D(); };
354f4a2713aSLionel Sambuc 
355f4a2713aSLionel Sambuc   struct A { ~A(); };
~A()356f4a2713aSLionel Sambuc   A::~A() { }
357f4a2713aSLionel Sambuc 
358f4a2713aSLionel Sambuc   struct B : public A {
359f4a2713aSLionel Sambuc     ~B();
360f4a2713aSLionel Sambuc     D arr[1];
361f4a2713aSLionel Sambuc   };
362f4a2713aSLionel Sambuc 
363f4a2713aSLionel Sambuc   // Verify that this doesn't get emitted as an alias
364*0a6a1f1dSLionel Sambuc   // CHECK5-LABEL: define void @_ZN5test71BD2Ev(
365*0a6a1f1dSLionel Sambuc   // CHECK5:   invoke void @_ZN5test71DD1Ev(
366*0a6a1f1dSLionel Sambuc   // CHECK5:   call void @_ZN5test71AD2Ev(
~B()367f4a2713aSLionel Sambuc   B::~B() {}
368f4a2713aSLionel Sambuc }
369f4a2713aSLionel Sambuc 
370f4a2713aSLionel Sambuc // PR10467
371f4a2713aSLionel Sambuc namespace test8 {
372f4a2713aSLionel Sambuc   struct A { A(); ~A(); };
373f4a2713aSLionel Sambuc 
374f4a2713aSLionel Sambuc   void die() __attribute__((noreturn));
test()375f4a2713aSLionel Sambuc   void test() {
376f4a2713aSLionel Sambuc     A x;
377f4a2713aSLionel Sambuc     while (1) {
378f4a2713aSLionel Sambuc       A y;
379f4a2713aSLionel Sambuc       goto l;
380f4a2713aSLionel Sambuc     }
381f4a2713aSLionel Sambuc   l: die();
382f4a2713aSLionel Sambuc   }
383f4a2713aSLionel Sambuc 
384*0a6a1f1dSLionel Sambuc   // CHECK5-LABEL:    define void @_ZN5test84testEv()
385*0a6a1f1dSLionel Sambuc   // CHECK5:      [[X:%.*]] = alloca [[A:%.*]], align 1
386*0a6a1f1dSLionel Sambuc   // CHECK5-NEXT: [[Y:%.*]] = alloca [[A:%.*]], align 1
387*0a6a1f1dSLionel Sambuc   // CHECK5:      call void @_ZN5test81AC1Ev([[A]]* [[X]])
388*0a6a1f1dSLionel Sambuc   // CHECK5-NEXT: br label
389*0a6a1f1dSLionel Sambuc   // CHECK5:      invoke void @_ZN5test81AC1Ev([[A]]* [[Y]])
390*0a6a1f1dSLionel Sambuc   // CHECK5:      invoke void @_ZN5test81AD1Ev([[A]]* [[Y]])
391*0a6a1f1dSLionel Sambuc   // CHECK5-NOT:  switch
392*0a6a1f1dSLionel Sambuc   // CHECK5:      invoke void @_ZN5test83dieEv()
393*0a6a1f1dSLionel Sambuc   // CHECK5:      unreachable
394f4a2713aSLionel Sambuc }
395f4a2713aSLionel Sambuc 
396f4a2713aSLionel Sambuc // PR12710
397f4a2713aSLionel Sambuc namespace test9 {
398f4a2713aSLionel Sambuc   struct ArgType {
399f4a2713aSLionel Sambuc     ~ArgType();
400f4a2713aSLionel Sambuc   };
401f4a2713aSLionel Sambuc   template<typename T>
402f4a2713aSLionel Sambuc   void f1(const ArgType& = ArgType());
403f4a2713aSLionel Sambuc   void f2();
bar()404f4a2713aSLionel Sambuc   void bar() {
405f4a2713aSLionel Sambuc     f1<int>();
406f4a2713aSLionel Sambuc     f2();
407f4a2713aSLionel Sambuc   }
408*0a6a1f1dSLionel Sambuc   // CHECK5: call void @_ZN5test97ArgTypeD1Ev(%"struct.test9::ArgType"* %
409*0a6a1f1dSLionel Sambuc   // CHECK5: call void @_ZN5test92f2Ev()
410f4a2713aSLionel Sambuc }
411f4a2713aSLionel Sambuc 
412f4a2713aSLionel Sambuc namespace test10 {
413f4a2713aSLionel Sambuc   // We used to crash trying to replace _ZN6test106OptionD1Ev with
414f4a2713aSLionel Sambuc   // _ZN6test106OptionD2Ev twice.
415f4a2713aSLionel Sambuc   struct Option {
~Optiontest10::Option416f4a2713aSLionel Sambuc     virtual ~Option() {}
417f4a2713aSLionel Sambuc   };
418f4a2713aSLionel Sambuc   template <class DataType> class opt : public Option {};
419f4a2713aSLionel Sambuc   template class opt<int>;
420*0a6a1f1dSLionel Sambuc   // CHECK5-LABEL: define zeroext i1 @_ZN6test1016handleOccurrenceEv(
handleOccurrence()421f4a2713aSLionel Sambuc   bool handleOccurrence() {
422*0a6a1f1dSLionel Sambuc     // CHECK5: call void @_ZN6test106OptionD2Ev(
423f4a2713aSLionel Sambuc     Option x;
424f4a2713aSLionel Sambuc     return true;
425f4a2713aSLionel Sambuc   }
426f4a2713aSLionel Sambuc }
427