[cfe-commits] r79198 - in /cfe/trunk: lib/AST/RecordLayoutBuilder.cpp lib/AST/RecordLayoutBuilder.h test/CodeGenCXX/virt.cpp

Mike Stump mrs at apple.com
Sun Aug 16 12:04:13 PDT 2009


Author: mrs
Date: Sun Aug 16 14:04:13 2009
New Revision: 79198

URL: http://llvm.org/viewvc/llvm-project?rev=79198&view=rev
Log:
Refine vbase offset calculations.  WIP.

Modified:
    cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
    cfe/trunk/lib/AST/RecordLayoutBuilder.h
    cfe/trunk/test/CodeGenCXX/virt.cpp

Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=79198&r1=79197&r2=79198&view=diff

==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Sun Aug 16 14:04:13 2009
@@ -168,6 +168,7 @@
 }
 
 void ASTRecordLayoutBuilder::LayoutVirtualBases(const CXXRecordDecl *RD,
+                                                const CXXRecordDecl *PB,
                                                 int64_t Offset,
                                  llvm::SmallSet<const CXXRecordDecl*, 32> &mark,
                     llvm::SmallSet<const CXXRecordDecl*, 32> &IndirectPrimary) {
@@ -187,22 +188,36 @@
       VBaseOffsets.push_back(BaseOffset);
     }
 #endif
+    int64_t BaseOffset = Offset;;
+    // FIXME: Calculate BaseOffset.
     if (i->isVirtual()) {
-      // Mark it so we don't lay it out twice.
-      if (mark.count(Base))
-        continue;
-      if (IndirectPrimary.count(Base)) {
-        int64_t BaseOffset;
-        // FIXME: audit
-        BaseOffset = Offset;
-        // BaseOffset = (1<<63) | (1<<31);
+      if (Base == PB) {
+        // Only lay things out once.
+        if (mark.count(Base))
+          continue;
+        // Mark it so we don't lay it out twice.
+        mark.insert(Base);
+        assert (IndirectPrimary.count(Base) && "IndirectPrimary was wrong");
         VBases.push_back(Base);
-        VBaseOffsets.push_back(BaseOffset);
-      } else
+        VBaseOffsets.push_back(Offset);
+      } else if (IndirectPrimary.count(Base)) {
+        // Someone else will eventually lay this out.
+        ;
+      } else {
+        // Only lay things out once.
+        if (mark.count(Base))
+          continue;
+        // Mark it so we don't lay it out twice.
+        mark.insert(Base);
         LayoutVirtualBase(Base);
+        BaseOffset = *(VBaseOffsets.end()-1);
+      }
+    }
+    if (Base->getNumVBases()) {
+      const ASTRecordLayout &L = Ctx.getASTRecordLayout(Base);
+      const CXXRecordDecl *PB = L.getPrimaryBase();
+      LayoutVirtualBases(Base, PB, BaseOffset, mark, IndirectPrimary);
     }
-    if (Base->getNumVBases())
-      LayoutVirtualBases(Base, Offset, mark, IndirectPrimary);
   }
 }
 
@@ -227,6 +242,7 @@
     BaseOffsets.push_back(Size);
   }
 
+#if 0
   // And now add offsets for all our primary virtual bases as well, so
   // they all have offsets.
   const ASTRecordLayout *L = &BaseInfo;
@@ -240,6 +256,7 @@
     if (PB)
       L = &Ctx.getASTRecordLayout(PB);
   }
+#endif
 
   // Reserve space for this base.
   Size += BaseSize;
@@ -285,7 +302,7 @@
 
   if (RD) {
     llvm::SmallSet<const CXXRecordDecl*, 32> mark;
-    LayoutVirtualBases(RD, 0, mark, IndirectPrimary);
+    LayoutVirtualBases(RD, PrimaryBase, 0, mark, IndirectPrimary);
   }
 
   // Finally, round the size of the total struct up to the alignment of the

Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.h?rev=79198&r1=79197&r2=79198&view=diff

==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.h (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.h Sun Aug 16 14:04:13 2009
@@ -73,7 +73,7 @@
   void LayoutNonVirtualBases(const CXXRecordDecl *RD);
   void LayoutBaseNonVirtually(const CXXRecordDecl *RD, bool IsVBase);
   void LayoutVirtualBase(const CXXRecordDecl *RD);
-  void LayoutVirtualBases(const CXXRecordDecl *RD,
+  void LayoutVirtualBases(const CXXRecordDecl *RD, const CXXRecordDecl *PB,
                           int64_t Offset,
                                  llvm::SmallSet<const CXXRecordDecl*, 32> &mark,
                      llvm::SmallSet<const CXXRecordDecl*, 32> &IndirectPrimary);

Modified: cfe/trunk/test/CodeGenCXX/virt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/virt.cpp?rev=79198&r1=79197&r2=79198&view=diff

==============================================================================
--- cfe/trunk/test/CodeGenCXX/virt.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/virt.cpp Sun Aug 16 14:04:13 2009
@@ -206,13 +206,13 @@
 // CHECK-LP32:__ZTV7test5_D:
 // CHECK-LP32-NEXT: .long 16
 // CHECK-LP32-NEXT: .long 12
-// CHECK-LP32: .long 8
-// CHECK-LP32 .long 8
-// CHECK-LP32 .long 8
-// CHECK-LP32: .long 4
-// CHECK-LP32 .long 4
-// CHECK-LP32 .long 4
-// CHECK-LP32: .space 4
+// CHECK-LP32-NEXT: .long 8
+// CHECK-LP32-NEXT: .long 8
+// CHECK-LP32-NEXT: .long 8
+// CHECK-LP32-NEXT: .long 4
+// CHECK-LP32-NEXT: .long 4
+// CHECK-LP32-NEXT: .long 4
+// CHECK-LP32-NEXT: .space 4
 // CHECK-LP32-NEXT: .space 4
 // CHECK-LP32-NEXT: .space 4
 // CHECK-LP32-NEXT: .space 4
@@ -224,13 +224,13 @@
 // CHECK-LP32-NEXT: .long __ZN8test5_B26funcB2Ev
 // CHECK-LP32-NEXT: .long __ZN8test5_B16funcB1Ev
 // CHECK-LP32-NEXT: .long __ZN7test5_D5funcDEv
-// CHECK-LP32: .space 4
 // CHECK-LP32-NEXT: .space 4
 // CHECK-LP32-NEXT: .space 4
 // CHECK-LP32-NEXT: .space 4
 // CHECK-LP32-NEXT: .space 4
-// CHECK-LP32 .long 4294967292
-// CHECK-LP32: .long __ZTI7test5_D
+// CHECK-LP32-NEXT: .space 4
+// CHECK-LP32: .long 4294967292
+// CHECK-LP32-NEXT: .long __ZTI7test5_D
 // CHECK-LP32-NEXT: .long __ZN9test5_B237funcB23Ev
 // CHECK-LP32-NEXT: .long __ZN9test5_B227funcB22Ev
 // CHECK-LP32-NEXT: .long __ZN9test5_B217funcB21Ev
@@ -241,8 +241,8 @@
 // CHECK-LP32: .long 4
 // CHECK-LP32-NEXT: .space 4
 // CHECK-LP32-NEXT: .space 4
-// CHECK-LP32 .long 4294967288
-// CHECK-LP32: .long __ZTI7test5_D
+// CHECK-LP32: .long 4294967288
+// CHECK-LP32-NEXT: .long __ZTI7test5_D
 // CHECK-LP32-NEXT: .long __ZN9test5_B337funcB33Ev
 // CHECK-LP32-NEXT: .long __ZN9test5_B327funcB32Ev
 // CHECK-LP32-NEXT: .long __ZN9test5_B317funcB31Ev
@@ -258,13 +258,13 @@
 // CHECK-LP64:__ZTV7test5_D:
 // CHECK-LP64-NEXT: .quad 32
 // CHECK-LP64-NEXT: .quad 24
-// CHECK-LP64: .quad 16
-// CHECK-LP64 .quad 16
-// CHECK-LP64 .quad 16
-// CHECK-LP64: .quad 8
-// CHECK-LP64 .quad 8
-// CHECK-LP64 .quad 8
-// CHECK-LP64: .space 8
+// CHECK-LP64-NEXT: .quad 16
+// CHECK-LP64-NEXT: .quad 16
+// CHECK-LP64-NEXT: .quad 16
+// CHECK-LP64-NEXT: .quad 8
+// CHECK-LP64-NEXT: .quad 8
+// CHECK-LP64-NEXT: .quad 8
+// CHECK-LP64-NEXT: .space 8
 // CHECK-LP64-NEXT: .space 8
 // CHECK-LP64-NEXT: .space 8
 // CHECK-LP64-NEXT: .space 8
@@ -276,13 +276,13 @@
 // CHECK-LP64-NEXT: .quad __ZN8test5_B26funcB2Ev
 // CHECK-LP64-NEXT: .quad __ZN8test5_B16funcB1Ev
 // CHECK-LP64-NEXT: .quad __ZN7test5_D5funcDEv
-// CHECK-LP64: .space 8
 // CHECK-LP64-NEXT: .space 8
 // CHECK-LP64-NEXT: .space 8
 // CHECK-LP64-NEXT: .space 8
 // CHECK-LP64-NEXT: .space 8
-// CHECK-LP64 .quad 18446744073709551608
-// CHECK-LP64: .quad __ZTI7test5_D
+// CHECK-LP64-NEXT: .space 8
+// CHECK-LP64: .quad 18446744073709551608
+// CHECK-LP64-NEXT: .quad __ZTI7test5_D
 // CHECK-LP64-NEXT: .quad __ZN9test5_B237funcB23Ev
 // CHECK-LP64-NEXT: .quad __ZN9test5_B227funcB22Ev
 // CHECK-LP64-NEXT: .quad __ZN9test5_B217funcB21Ev
@@ -293,8 +293,8 @@
 // CHECK-LP64: .quad 8
 // CHECK-LP64-NEXT: .space 8
 // CHECK-LP64-NEXT: .space 8
-// CHECK-LP64 .quad 18446744073709551600
-// CHECK-LP64: .quad __ZTI7test5_D
+// CHECK-LP64: .quad 18446744073709551600
+// CHECK-LP64-NEXT: .quad __ZTI7test5_D
 // CHECK-LP64-NEXT: .quad __ZN9test5_B337funcB33Ev
 // CHECK-LP64-NEXT: .quad __ZN9test5_B327funcB32Ev
 // CHECK-LP64-NEXT: .quad __ZN9test5_B317funcB31Ev





More information about the cfe-commits mailing list