[cfe-commits] r82770 - in /cfe/trunk: lib/AST/RecordLayoutBuilder.cpp test/SemaCXX/empty-class-layout.cpp

Anders Carlsson andersca at mac.com
Fri Sep 25 08:39:00 PDT 2009


Author: andersca
Date: Fri Sep 25 10:39:00 2009
New Revision: 82770

URL: http://llvm.org/viewvc/llvm-project?rev=82770&view=rev
Log:
Even more work on empty classes.

Modified:
    cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
    cfe/trunk/test/SemaCXX/empty-class-layout.cpp

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

==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Fri Sep 25 10:39:00 2009
@@ -247,7 +247,18 @@
       return false;
   }
   
-  // FIXME: fields.
+  // Check fields.
+  unsigned FieldNo = 0;
+  for (CXXRecordDecl::field_iterator I = RD->field_begin(), E = RD->field_end(); 
+       I != E; ++I, ++FieldNo) {
+    const FieldDecl *FD = *I;
+    
+    uint64_t FieldOffset = Info.getFieldOffset(FieldNo);
+    
+    if (!canPlaceFieldAtOffset(FD, Offset + FieldOffset))
+      return false;
+  }
+
   // FIXME: virtual bases.
   return true;
 }
@@ -304,7 +315,17 @@
     UpdateEmptyClassOffsets(Base, Offset + BaseClassOffset);
   }
   
-  // FIXME: Update fields and virtual bases.
+  // Update fields.
+  unsigned FieldNo = 0;
+  for (CXXRecordDecl::field_iterator I = RD->field_begin(), E = RD->field_end(); 
+       I != E; ++I, ++FieldNo) {
+    const FieldDecl *FD = *I;
+    
+    uint64_t FieldOffset = Info.getFieldOffset(FieldNo);
+    UpdateEmptyClassOffsets(FD, Offset + FieldOffset);
+  }
+  
+  // FIXME: Update virtual bases.
 }
 
 void
@@ -348,7 +369,7 @@
     // We were able to place the class at offset 0.
     UpdateEmptyClassOffsets(RD, 0);
 
-    Size = std::max(Size, BaseInfo.getNonVirtualSize());
+    Size = std::max(Size, BaseInfo.getSize());
 
     return 0;
   }
@@ -366,11 +387,14 @@
     Offset += BaseAlign;
   }
 
-  // Remember the next available offset.
-  NextOffset = Offset + BaseInfo.getNonVirtualSize();
+  if (!RD->isEmpty()) {
+    // Remember the next available offset.
+    NextOffset = Offset + BaseInfo.getNonVirtualSize();
+
+    Size = std::max(Size, NextOffset);
+  } else
+    Size = std::max(Size, Offset + BaseInfo.getSize());
 
-  Size = std::max(Size, NextOffset);
-  
   // Remember max struct/class alignment.
   UpdateAlignment(BaseAlign);
 

Modified: cfe/trunk/test/SemaCXX/empty-class-layout.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/empty-class-layout.cpp?rev=82770&r1=82769&r2=82770&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/empty-class-layout.cpp (original)
+++ cfe/trunk/test/SemaCXX/empty-class-layout.cpp Fri Sep 25 10:39:00 2009
@@ -43,3 +43,17 @@
   Empty e[2];
 };
 SA(7, sizeof(S2) == 24);
+
+struct S3 {
+  Empty e;
+};
+
+struct S4 : Empty, S3 { 
+};
+SA(8, sizeof(S4) == 2);
+
+struct S5 : S3, Empty {};
+SA(9, sizeof(S5) == 2);
+
+struct S6 : S5 { };
+SA(10, sizeof(S6) == 2);





More information about the cfe-commits mailing list