[cfe-commits] r97406 - in /cfe/trunk: lib/CodeGen/CGVtable.cpp test/CodeGenCXX/vtable-layout.cpp

Anders Carlsson andersca at mac.com
Sun Feb 28 10:37:33 PST 2010


Author: andersca
Date: Sun Feb 28 12:37:33 2010
New Revision: 97406

URL: http://llvm.org/viewvc/llvm-project?rev=97406&view=rev
Log:
Handle unused functions in construction vtables correctly.

Modified:
    cfe/trunk/lib/CodeGen/CGVtable.cpp
    cfe/trunk/test/CodeGenCXX/vtable-layout.cpp

Modified: cfe/trunk/lib/CodeGen/CGVtable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGVtable.cpp?rev=97406&r1=97405&r2=97406&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGVtable.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGVtable.cpp Sun Feb 28 12:37:33 2010
@@ -1203,11 +1203,13 @@
   ///   necessary.
   bool IsOverriderUsed(BaseSubobject Base, 
                        BaseSubobject FirstBaseInPrimaryBaseChain,
+                       uint64_t OffsetInLayoutClass,
                        FinalOverriders::OverriderInfo Overrider) const;
   
   /// AddMethods - Add the methods of this base subobject and all its
   /// primary bases to the vtable components vector.
   void AddMethods(BaseSubobject Base, BaseSubobject FirstBaseInPrimaryBaseChain,
+                  uint64_t OffsetInLayoutClass,
                   PrimaryBasesSetVectorTy &PrimaryBases);
 
   // LayoutVtable - Layout the vtable for the given base class, including its
@@ -1501,10 +1503,11 @@
 bool 
 VtableBuilder::IsOverriderUsed(BaseSubobject Base, 
                                BaseSubobject FirstBaseInPrimaryBaseChain,
+                               uint64_t OffsetInLayoutClass,
                                FinalOverriders::OverriderInfo Overrider) const {
   // If the base and the first base in the primary base chain have the same
   // offsets, then this overrider will be used.
-  if (Base.getBaseOffset() == FirstBaseInPrimaryBaseChain.getBaseOffset())
+  if (Base.getBaseOffset() == OffsetInLayoutClass)
    return true;
 
   // We know now that Base (or a direct or indirect base of it) is a primary
@@ -1534,13 +1537,13 @@
       assert(Layout.getVBaseClassOffset(PrimaryBase) == 0 && 
              "Primary base should always be at offset 0!");
 
-      const ASTRecordLayout &MostDerivedClassLayout = 
-        Context.getASTRecordLayout(MostDerivedClass);
+      const ASTRecordLayout &LayoutClassLayout =
+        Context.getASTRecordLayout(LayoutClass);
 
       // Now check if this is the primary base that is not a primary base in the
       // most derived class.
-      if (MostDerivedClassLayout.getVBaseClassOffset(PrimaryBase) !=
-          FirstBaseInPrimaryBaseChain.getBaseOffset()) {
+      if (LayoutClassLayout.getVBaseClassOffset(PrimaryBase) !=
+          OffsetInLayoutClass) {
         // We found it, stop walking the chain.
         break;
       }
@@ -1585,6 +1588,7 @@
 void 
 VtableBuilder::AddMethods(BaseSubobject Base, 
                           BaseSubobject FirstBaseInPrimaryBaseChain,
+                          uint64_t OffsetInLayoutClass,                          
                           PrimaryBasesSetVectorTy &PrimaryBases) {
   const CXXRecordDecl *RD = Base.getBase();
 
@@ -1606,9 +1610,10 @@
 
       BaseOffset = Base.getBaseOffset();
     }
-    
+
+    // FIXME: OffsetInLayoutClass is not right here.
     AddMethods(BaseSubobject(PrimaryBase, BaseOffset), 
-               FirstBaseInPrimaryBaseChain, PrimaryBases);
+               FirstBaseInPrimaryBaseChain, OffsetInLayoutClass, PrimaryBases);
     
     if (!PrimaryBases.insert(PrimaryBase))
       assert(false && "Found a duplicate primary base!");
@@ -1659,7 +1664,8 @@
     MethodInfoMap.insert(std::make_pair(MD, MethodInfo));
 
     // Check if this overrider is going to be used.
-    if (!IsOverriderUsed(Base, FirstBaseInPrimaryBaseChain, Overrider)) {
+    if (!IsOverriderUsed(Base, FirstBaseInPrimaryBaseChain, OffsetInLayoutClass,
+                         Overrider)) {
       const CXXMethodDecl *OverriderMD = Overrider.Method;
       Components.push_back(VtableComponent::MakeUnusedFunction(OverriderMD));
       continue;
@@ -1722,7 +1728,9 @@
 
   // Now go through all virtual member functions and add them.
   PrimaryBasesSetVectorTy PrimaryBases;
-  AddMethods(Base, Base, PrimaryBases);
+  printf("adding methods, offset in layout class is %llu\n", 
+         OffsetInLayoutClass);
+  AddMethods(Base, Base, OffsetInLayoutClass, PrimaryBases);
 
   // Compute 'this' pointer adjustments.
   ComputeThisAdjustments();

Modified: cfe/trunk/test/CodeGenCXX/vtable-layout.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/vtable-layout.cpp?rev=97406&r1=97405&r2=97406&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/vtable-layout.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/vtable-layout.cpp Sun Feb 28 12:37:33 2010
@@ -966,8 +966,15 @@
 // CHECK-NEXT:    3 | Test24::C RTTI
 // CHECK-NEXT:        -- (Test24::A, 8) vtable address --
 // CHECK-NEXT:        -- (Test24::C, 8) vtable address --
+// CHECK-NEXT:    4 | [unused] void Test24::A::f()
+// CHECK-NEXT:    5 | vcall_offset (0)
+// CHECK-NEXT: 6 | offset_to_top (8)
+// CHECK-NEXT: 7 | Test24::C RTTI
+// CHECK-NEXT:     -- (Test24::A, 0) vtable address --
+// CHECK-NEXT: 8 | void Test24::A::f()
 struct D : B, C {
   virtual void f();
 };
 void D::f() { }
+
 }





More information about the cfe-commits mailing list