]> granicus.if.org Git - clang/commitdiff
Fix another regression from the "skip vtable pointer initialization"
authorAnders Carlsson <andersca@mac.com>
Mon, 16 May 2011 04:08:36 +0000 (04:08 +0000)
committerAnders Carlsson <andersca@mac.com>
Mon, 16 May 2011 04:08:36 +0000 (04:08 +0000)
optimization. Make sure to require a vtable when trying to get the address
of a VTT, otherwise we would never end up emitting the VTT.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@131400 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGClass.cpp
lib/CodeGen/CGVTT.cpp
lib/CodeGen/CGVTables.cpp
test/CodeGenCXX/mangle-subst-std.cpp
test/CodeGenCXX/skip-vtable-pointer-initialization.cpp
test/CodeGenCXX/virtual-base-destructor-call.cpp

index 8b4684cb38776a3b89e38b8bec1cfcb528b13ccf..0d2500894e9197c151f87eebcd6d9a182d812c80 100644 (file)
@@ -812,7 +812,7 @@ FieldHasTrivialDestructorBody(ASTContext &Context,
 /// CanSkipVTablePointerInitialization - Check whether we need to initialize
 /// any vtable pointers before calling this destructor.
 static bool CanSkipVTablePointerInitialization(ASTContext &Context,
-                                           const CXXDestructorDecl *Dtor) {
+                                               const CXXDestructorDecl *Dtor) {
   if (!Dtor->hasTrivialBody())
     return false;
 
index a6849f8f3d2118365ae638a4a315411f19829b3a..aefc41e50002a22b1fa276a0dcb701de88ff2445 100644 (file)
@@ -411,6 +411,8 @@ llvm::GlobalVariable *CodeGenVTables::GetAddrOfVTT(const CXXRecordDecl *RD) {
   Out.flush();
   llvm::StringRef Name = OutName.str();
 
+  ComputeVTableRelatedInformation(RD, /*VTableRequired=*/true);
+
   VTTBuilder Builder(CGM, RD, /*GenerateDefinition=*/false);
 
   const llvm::Type *Int8PtrTy = 
index c7ef9c74183d368bcfa44ac07c0d823fd51ec235..9ac5e67ada4de739d05d65b2748c50ca5c8a11d9 100644 (file)
@@ -3175,7 +3175,7 @@ llvm::GlobalVariable *CodeGenVTables::GetAddrOfVTable(const CXXRecordDecl *RD) {
   Out.flush();
   llvm::StringRef Name = OutName.str();
 
-  ComputeVTableRelatedInformation(RD, true);
+  ComputeVTableRelatedInformation(RD, /*VTableRequired=*/true);
   
   const llvm::Type *Int8PtrTy = llvm::Type::getInt8PtrTy(CGM.getLLVMContext());
   llvm::ArrayType *ArrayType = 
index c54d3e5297f0e2d1cc1cd81dd656a2d394bc1bd1..837d4fa8570de04679102b523132af388a48fa56 100644 (file)
@@ -8,9 +8,10 @@
 // CHECK: @_ZTCSd0_Si = linkonce_odr unnamed_addr constant 
 // CHECK: @_ZTCSd16_So = linkonce_odr unnamed_addr constant
 // CHECK: @_ZTTSo = linkonce_odr unnamed_addr constant
-// CHECK: @_ZTTSi = linkonce_odr unnamed_addr constant
 // CHECK: @_ZTVSo = linkonce_odr unnamed_addr constant
+// CHECK: @_ZTTSi = linkonce_odr unnamed_addr constant
 // CHECK: @_ZTVSi = linkonce_odr unnamed_addr constant
+
 namespace std {
   struct A { A(); };
   
index 3520b912cf925a87b7c29da5cce95dccd6c4e3dd..84697be4a4cd7cccead357b43af812d372c75760 100644 (file)
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
 
+// See Test9 for test description.
+// CHECK: @_ZTTN5Test91BE = linkonce_odr unnamed_addr constant
 namespace Test1 {
 
 // Check that we don't initialize the vtable pointer in A::~A(), since the destructor body is trivial.
@@ -184,3 +186,15 @@ A::~A()
 }
 
 }
+
+namespace Test9 {
+
+// Check that we emit a VTT for B, even though we don't initialize the vtable pointer in the destructor.
+struct A { virtual ~A () { } };
+struct B : virtual A {};
+struct C : virtual B { 
+  virtual ~C();
+};
+C::~C() {}
+
+}
index 807eaff0d1d293e4417e158b236b37a7b0c41945..f028e4c733fecda7bf42d8b4026848aef59a7133 100644 (file)
@@ -27,11 +27,6 @@ int main() {
 //  CHECK: call void @_ZN13basic_istreamIcED2Ev
 //  CHECK: }
 
-// basic_istream's base dtor is a no-op.
-//  CHECK: define linkonce_odr void @_ZN13basic_istreamIcED2Ev(%struct.basic_istream* %this, i8** %vtt) unnamed_addr
-//  CHECK-NOT: call
-//  CHECK: }
-
 // basic_iostream's deleting dtor calls its complete dtor, then
 // operator delete().
 //  CHECK: define linkonce_odr void @_ZN14basic_iostreamIcED0Ev(%struct.basic_iostream* %this) unnamed_addr
@@ -49,3 +44,8 @@ int main() {
 //  CHECK: define linkonce_odr void @_ZN13basic_istreamIcED0Ev(%struct.basic_istream* %this) unnamed_addr
 //  CHECK: call void @_ZN13basic_istreamIcED1Ev
 //  CHECK: call void @_ZdlPv
+
+// basic_istream's base dtor is a no-op.
+//  CHECK: define linkonce_odr void @_ZN13basic_istreamIcED2Ev(%struct.basic_istream* %this, i8** %vtt) unnamed_addr
+//  CHECK-NOT: call
+//  CHECK: }