Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGenCXX / skip-vtable-pointer-initialization.cpp
blobeb8f21b57aa7b6ef2441c3d7a8208a88b4307515
1 // RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
3 // See Test9 for test description.
4 // CHECK: @_ZTTN5Test91BE = linkonce_odr unnamed_addr constant
5 namespace Test1 {
7 // Check that we don't initialize the vtable pointer in A::~A(), since the destructor body is trivial.
8 struct A {
9 virtual void f();
10 ~A();
13 // CHECK-LABEL: define{{.*}} void @_ZN5Test11AD2Ev
14 // CHECK-NOT: store ptr getelementptr inbounds ({ [3 x ptr] }, ptr @_ZTVN5Test11AE, i64 0, i64 2), ptr
15 A::~A()
21 namespace Test2 {
23 // Check that we do initialize the vtable pointer in A::~A() since the destructor body isn't trivial.
24 struct A {
25 virtual void f();
26 ~A();
29 // CHECK-LABEL: define{{.*}} void @_ZN5Test21AD2Ev
30 // CHECK: store ptr getelementptr inbounds ({ [3 x ptr] }, ptr @_ZTVN5Test21AE, i32 0, inrange i32 0, i32 2), ptr
31 A::~A() {
32 f();
37 namespace Test3 {
39 // Check that we don't initialize the vtable pointer in A::~A(), since the destructor body is trivial
40 // and Field's destructor body is also trivial.
41 struct Field {
42 ~Field() { }
45 struct A {
46 virtual void f();
47 ~A();
49 Field field;
52 // CHECK-LABEL: define{{.*}} void @_ZN5Test31AD2Ev
53 // CHECK-NOT: store ptr getelementptr inbounds ({ [3 x ptr] }, ptr @_ZTVN5Test31AE, i32 0, inrange i32 0, i32 2), ptr
54 A::~A() {
60 namespace Test4 {
62 // Check that we do initialize the vtable pointer in A::~A(), since Field's destructor body
63 // isn't trivial.
65 void f();
67 struct Field {
68 ~Field() { f(); }
71 struct A {
72 virtual void f();
73 ~A();
75 Field field;
78 // CHECK-LABEL: define{{.*}} void @_ZN5Test41AD2Ev
79 // CHECK: store ptr getelementptr inbounds ({ [3 x ptr] }, ptr @_ZTVN5Test41AE, i32 0, inrange i32 0, i32 2), ptr
80 A::~A()
86 namespace Test5 {
88 // Check that we do initialize the vtable pointer in A::~A(), since Field's destructor isn't
89 // available in this translation unit.
91 struct Field {
92 ~Field();
95 struct A {
96 virtual void f();
97 ~A();
99 Field field;
102 // CHECK-LABEL: define{{.*}} void @_ZN5Test51AD2Ev
103 // CHECK: store ptr getelementptr inbounds ({ [3 x ptr] }, ptr @_ZTVN5Test51AE, i32 0, inrange i32 0, i32 2), ptr
104 A::~A()
110 namespace Test6 {
112 // Check that we do initialize the vtable pointer in A::~A(), since Field has a member
113 // variable with a non-trivial destructor body.
115 struct NonTrivialDestructorBody {
116 ~NonTrivialDestructorBody();
119 struct Field {
120 NonTrivialDestructorBody nonTrivialDestructorBody;
123 struct A {
124 virtual void f();
125 ~A();
127 Field field;
130 // CHECK-LABEL: define{{.*}} void @_ZN5Test61AD2Ev
131 // CHECK: store ptr getelementptr inbounds ({ [3 x ptr] }, ptr @_ZTVN5Test61AE, i32 0, inrange i32 0, i32 2), ptr
132 A::~A()
138 namespace Test7 {
140 // Check that we do initialize the vtable pointer in A::~A(), since Field has a base
141 // class with a non-trivial destructor body.
143 struct NonTrivialDestructorBody {
144 ~NonTrivialDestructorBody();
147 struct Field : NonTrivialDestructorBody { };
149 struct A {
150 virtual void f();
151 ~A();
153 Field field;
156 // CHECK-LABEL: define{{.*}} void @_ZN5Test71AD2Ev
157 // CHECK: store ptr getelementptr inbounds ({ [3 x ptr] }, ptr @_ZTVN5Test71AE, i32 0, inrange i32 0, i32 2), ptr
158 A::~A()
164 namespace Test8 {
166 // Check that we do initialize the vtable pointer in A::~A(), since Field has a virtual base
167 // class with a non-trivial destructor body.
169 struct NonTrivialDestructorBody {
170 ~NonTrivialDestructorBody();
173 struct Field : virtual NonTrivialDestructorBody { };
175 struct A {
176 virtual void f();
177 ~A();
179 Field field;
182 // CHECK-LABEL: define{{.*}} void @_ZN5Test81AD2Ev
183 // CHECK: store ptr getelementptr inbounds ({ [3 x ptr] }, ptr @_ZTVN5Test81AE, i32 0, inrange i32 0, i32 2), ptr
184 A::~A()
190 namespace Test9 {
192 // Check that we emit a VTT for B, even though we don't initialize the vtable pointer in the destructor.
193 struct A { virtual ~A () { } };
194 struct B : virtual A {};
195 struct C : virtual B {
196 virtual ~C();
198 C::~C() {}