[cfe-commits] r103402 - in /cfe/trunk/lib/AST: RecordLayoutBuilder.cpp RecordLayoutBuilder.h

Anders Carlsson andersca at mac.com
Mon May 10 08:26:14 PDT 2010


Author: andersca
Date: Mon May 10 10:26:14 2010
New Revision: 103402

URL: http://llvm.org/viewvc/llvm-project?rev=103402&view=rev
Log:
More work on handling empty classes.

Modified:
    cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
    cfe/trunk/lib/AST/RecordLayoutBuilder.h

Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=103402&r1=103401&r2=103402&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Mon May 10 10:26:14 2010
@@ -375,7 +375,7 @@
   const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD);
 
   // If we have an empty base class, try to place it at offset 0.
-  if (RD->isEmpty() && canPlaceRecordAtOffset(RD, 0)) {
+  if (RD->isEmpty() && canPlaceRecordAtOffset(RD, 0, /*CheckVBases=*/false)) {
     // We were able to place the class at offset 0.
     UpdateEmptyClassOffsets(RD, 0);
 
@@ -391,7 +391,7 @@
 
   // Try to place the base.
   while (true) {
-    if (canPlaceRecordAtOffset(RD, Offset))
+    if (canPlaceRecordAtOffset(RD, Offset, /*CheckVBases=*/false))
       break;
 
     Offset += BaseAlign;
@@ -412,8 +412,10 @@
   return Offset;
 }
 
-bool ASTRecordLayoutBuilder::canPlaceRecordAtOffset(const CXXRecordDecl *RD,
-                                                    uint64_t Offset) const {
+bool 
+ASTRecordLayoutBuilder::canPlaceRecordAtOffset(const CXXRecordDecl *RD,
+                                               uint64_t Offset, 
+                                               bool CheckVBases) const {
   // Look for an empty class with the same type at the same offset.
   for (EmptyClassOffsetsTy::const_iterator I =
          EmptyClassOffsets.lower_bound(Offset),
@@ -438,7 +440,8 @@
 
     uint64_t BaseOffset = Layout.getBaseClassOffset(BaseDecl);
 
-    if (!canPlaceRecordAtOffset(BaseDecl, Offset + BaseOffset))
+    if (!canPlaceRecordAtOffset(BaseDecl, Offset + BaseOffset,
+                                /*CheckVBases=*/false))
       return false;
   }
 
@@ -454,7 +457,10 @@
       return false;
   }
 
-  // FIXME: virtual bases.
+  if (CheckVBases) {
+    // FIXME: virtual bases.
+  }
+
   return true;
 }
 
@@ -463,7 +469,7 @@
   QualType T = FD->getType();
   if (const RecordType *RT = T->getAs<RecordType>()) {
     if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(RT->getDecl()))
-      return canPlaceRecordAtOffset(RD, Offset);
+      return canPlaceRecordAtOffset(RD, Offset, /*CheckVBases=*/true);
   }
 
   if (const ConstantArrayType *AT = Context.getAsConstantArrayType(T)) {
@@ -480,7 +486,7 @@
     uint64_t NumElements = Context.getConstantArrayElementCount(AT);
     uint64_t ElementOffset = Offset;
     for (uint64_t I = 0; I != NumElements; ++I) {
-      if (!canPlaceRecordAtOffset(RD, ElementOffset))
+      if (!canPlaceRecordAtOffset(RD, ElementOffset, /*CheckVBases=*/true))
         return false;
 
       ElementOffset += Layout.getSize();

Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.h?rev=103402&r1=103401&r2=103402&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.h (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.h Mon May 10 10:26:14 2010
@@ -140,7 +140,8 @@
   /// or a field) can be placed at the given offset. 
   /// Returns false if placing the record will result in two components 
   /// (direct or indirect) of the same type having the same offset.
-  bool canPlaceRecordAtOffset(const CXXRecordDecl *RD, uint64_t Offset) const;
+  bool canPlaceRecordAtOffset(const CXXRecordDecl *RD, uint64_t Offset,
+                              bool CheckVBases) const;
 
   /// canPlaceFieldAtOffset - Return whether a field can be placed at the given
   /// offset.





More information about the cfe-commits mailing list