r270591 - [RecordLayout] Use an ASTVector instead of using a separate pointer and counter

David Majnemer via cfe-commits cfe-commits at lists.llvm.org
Tue May 24 11:10:51 PDT 2016


Author: majnemer
Date: Tue May 24 13:10:50 2016
New Revision: 270591

URL: http://llvm.org/viewvc/llvm-project?rev=270591&view=rev
Log:
[RecordLayout] Use an ASTVector instead of using a separate pointer and counter

No functional change is intended.

Modified:
    cfe/trunk/include/clang/AST/RecordLayout.h
    cfe/trunk/lib/AST/RecordLayout.cpp
    cfe/trunk/lib/AST/RecordLayoutBuilder.cpp

Modified: cfe/trunk/include/clang/AST/RecordLayout.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecordLayout.h?rev=270591&r1=270590&r2=270591&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/RecordLayout.h (original)
+++ cfe/trunk/include/clang/AST/RecordLayout.h Tue May 24 13:10:50 2016
@@ -71,10 +71,7 @@ private:
   CharUnits RequiredAlignment;
 
   /// FieldOffsets - Array of field offsets in bits.
-  uint64_t *FieldOffsets;
-
-  // FieldCount - Number of fields.
-  unsigned FieldCount;
+  ASTVector<uint64_t> FieldOffsets;
 
   /// CXXRecordLayoutInfo - Contains C++ specific layout information.
   struct CXXRecordLayoutInfo {
@@ -136,9 +133,8 @@ private:
   friend class ASTContext;
 
   ASTRecordLayout(const ASTContext &Ctx, CharUnits size, CharUnits alignment,
-                  CharUnits requiredAlignment,
-                  CharUnits datasize, const uint64_t *fieldoffsets,
-                  unsigned fieldcount);
+                  CharUnits requiredAlignment, CharUnits datasize,
+                  ArrayRef<uint64_t> fieldoffsets);
 
   // Constructor for C++ records.
   typedef CXXRecordLayoutInfo::BaseOffsetsMapTy BaseOffsetsMapTy;
@@ -148,7 +144,7 @@ private:
                   bool hasOwnVFPtr, bool hasExtendableVFPtr,
                   CharUnits vbptroffset,
                   CharUnits datasize,
-                  const uint64_t *fieldoffsets, unsigned fieldcount,
+                  ArrayRef<uint64_t> fieldoffsets,
                   CharUnits nonvirtualsize, CharUnits nonvirtualalignment,
                   CharUnits SizeOfLargestEmptySubobject,
                   const CXXRecordDecl *PrimaryBase,
@@ -174,12 +170,11 @@ public:
   CharUnits getSize() const { return Size; }
 
   /// getFieldCount - Get the number of fields in the layout.
-  unsigned getFieldCount() const { return FieldCount; }
+  unsigned getFieldCount() const { return FieldOffsets.size(); }
 
   /// getFieldOffset - Get the offset of the given field index, in
   /// bits.
   uint64_t getFieldOffset(unsigned FieldNo) const {
-    assert (FieldNo < FieldCount && "Invalid Field No");
     return FieldOffsets[FieldNo];
   }
 

Modified: cfe/trunk/lib/AST/RecordLayout.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayout.cpp?rev=270591&r1=270590&r2=270591&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RecordLayout.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayout.cpp Tue May 24 13:10:50 2016
@@ -18,8 +18,6 @@
 using namespace clang;
 
 void ASTRecordLayout::Destroy(ASTContext &Ctx) {
-  if (FieldOffsets)
-    Ctx.Deallocate(FieldOffsets);
   if (CXXInfo) {
     CXXInfo->~CXXRecordLayoutInfo();
     Ctx.Deallocate(CXXInfo);
@@ -29,18 +27,13 @@ void ASTRecordLayout::Destroy(ASTContext
 }
 
 ASTRecordLayout::ASTRecordLayout(const ASTContext &Ctx, CharUnits size,
-                                 CharUnits alignment, 
+                                 CharUnits alignment,
                                  CharUnits requiredAlignment,
                                  CharUnits datasize,
-                                 const uint64_t *fieldoffsets,
-                                 unsigned fieldcount)
-  : Size(size), DataSize(datasize), Alignment(alignment),
-    RequiredAlignment(requiredAlignment), FieldOffsets(nullptr),
-    FieldCount(fieldcount), CXXInfo(nullptr) {
-  if (FieldCount > 0)  {
-    FieldOffsets = new (Ctx) uint64_t[FieldCount];
-    memcpy(FieldOffsets, fieldoffsets, FieldCount * sizeof(*FieldOffsets));
-  }
+                                 ArrayRef<uint64_t> fieldoffsets)
+    : Size(size), DataSize(datasize), Alignment(alignment),
+      RequiredAlignment(requiredAlignment), CXXInfo(nullptr) {
+  FieldOffsets.append(Ctx, fieldoffsets.begin(), fieldoffsets.end());
 }
 
 // Constructor for C++ records.
@@ -50,8 +43,7 @@ ASTRecordLayout::ASTRecordLayout(const A
                                  bool hasOwnVFPtr, bool hasExtendableVFPtr,
                                  CharUnits vbptroffset,
                                  CharUnits datasize,
-                                 const uint64_t *fieldoffsets,
-                                 unsigned fieldcount,
+                                 ArrayRef<uint64_t> fieldoffsets,
                                  CharUnits nonvirtualsize,
                                  CharUnits nonvirtualalignment,
                                  CharUnits SizeOfLargestEmptySubobject,
@@ -63,13 +55,9 @@ ASTRecordLayout::ASTRecordLayout(const A
                                  const BaseOffsetsMapTy& BaseOffsets,
                                  const VBaseOffsetsMapTy& VBaseOffsets)
   : Size(size), DataSize(datasize), Alignment(alignment),
-    RequiredAlignment(requiredAlignment), FieldOffsets(nullptr),
-    FieldCount(fieldcount), CXXInfo(new (Ctx) CXXRecordLayoutInfo)
+    RequiredAlignment(requiredAlignment), CXXInfo(new (Ctx) CXXRecordLayoutInfo)
 {
-  if (FieldCount > 0)  {
-    FieldOffsets = new (Ctx) uint64_t[FieldCount];
-    memcpy(FieldOffsets, fieldoffsets, FieldCount * sizeof(*FieldOffsets));
-  }
+  FieldOffsets.append(Ctx, fieldoffsets.begin(), fieldoffsets.end());
 
   CXXInfo->PrimaryBase.setPointer(PrimaryBase);
   CXXInfo->PrimaryBase.setInt(IsPrimaryBaseVirtual);

Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=270591&r1=270590&r2=270591&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Tue May 24 13:10:50 2016
@@ -2949,8 +2949,7 @@ ASTContext::getASTRecordLayout(const Rec
       NewEntry = new (*this) ASTRecordLayout(
           *this, Builder.Size, Builder.Alignment, Builder.RequiredAlignment,
           Builder.HasOwnVFPtr, Builder.HasOwnVFPtr || Builder.PrimaryBase,
-          Builder.VBPtrOffset, Builder.DataSize,
-          Builder.FieldOffsets.data(), Builder.FieldOffsets.size(),
+          Builder.VBPtrOffset, Builder.DataSize, Builder.FieldOffsets,
           Builder.NonVirtualSize, Builder.Alignment, CharUnits::Zero(),
           Builder.PrimaryBase, false, Builder.SharedVBPtrBase,
           Builder.EndsWithZeroSizedObject, Builder.LeadsWithZeroSizedBase,
@@ -2959,8 +2958,7 @@ ASTContext::getASTRecordLayout(const Rec
       Builder.layout(D);
       NewEntry = new (*this) ASTRecordLayout(
           *this, Builder.Size, Builder.Alignment, Builder.RequiredAlignment,
-          Builder.Size, Builder.FieldOffsets.data(),
-          Builder.FieldOffsets.size());
+          Builder.Size, Builder.FieldOffsets);
     }
   } else {
     if (const auto *RD = dyn_cast<CXXRecordDecl>(D)) {
@@ -2983,9 +2981,8 @@ ASTContext::getASTRecordLayout(const Rec
           *this, Builder.getSize(), Builder.Alignment,
           /*RequiredAlignment : used by MS-ABI)*/
           Builder.Alignment, Builder.HasOwnVFPtr, RD->isDynamicClass(),
-          CharUnits::fromQuantity(-1), DataSize, Builder.FieldOffsets.data(),
-          Builder.FieldOffsets.size(), NonVirtualSize,
-          Builder.NonVirtualAlignment,
+          CharUnits::fromQuantity(-1), DataSize, Builder.FieldOffsets,
+          NonVirtualSize, Builder.NonVirtualAlignment,
           EmptySubobjects.SizeOfLargestEmptySubobject, Builder.PrimaryBase,
           Builder.PrimaryBaseIsVirtual, nullptr, false, false, Builder.Bases,
           Builder.VBases);
@@ -2996,8 +2993,7 @@ ASTContext::getASTRecordLayout(const Rec
       NewEntry = new (*this) ASTRecordLayout(
           *this, Builder.getSize(), Builder.Alignment,
           /*RequiredAlignment : used by MS-ABI)*/
-          Builder.Alignment, Builder.getSize(), Builder.FieldOffsets.data(),
-          Builder.FieldOffsets.size());
+          Builder.Alignment, Builder.getSize(), Builder.FieldOffsets);
     }
   }
 
@@ -3112,13 +3108,12 @@ ASTContext::getObjCLayout(const ObjCInte
   Builder.Layout(D);
 
   const ASTRecordLayout *NewEntry =
-    new (*this) ASTRecordLayout(*this, Builder.getSize(), 
+    new (*this) ASTRecordLayout(*this, Builder.getSize(),
                                 Builder.Alignment,
                                 /*RequiredAlignment : used by MS-ABI)*/
                                 Builder.Alignment,
                                 Builder.getDataSize(),
-                                Builder.FieldOffsets.data(),
-                                Builder.FieldOffsets.size());
+                                Builder.FieldOffsets);
 
   ObjCLayouts[Key] = NewEntry;
 




More information about the cfe-commits mailing list