From: Ken Dyck Date: Tue, 1 Feb 2011 01:52:10 +0000 (+0000) Subject: Convert RecordLayout::NonVirtualSize from bit units to CharUnits. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5c3633fa57f27b0909ab5767715c4e66b8920165;p=clang Convert RecordLayout::NonVirtualSize from bit units to CharUnits. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124646 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/RecordLayout.h b/include/clang/AST/RecordLayout.h index 4440ec8d29..940979fa35 100644 --- a/include/clang/AST/RecordLayout.h +++ b/include/clang/AST/RecordLayout.h @@ -52,7 +52,7 @@ class ASTRecordLayout { struct CXXRecordLayoutInfo { /// NonVirtualSize - The non-virtual size (in bits) of an object, which is /// the size of the object without virtual bases. - uint64_t NonVirtualSize; + CharUnits NonVirtualSize; /// NonVirtualAlign - The non-virtual alignment (in bits) of an object, /// which is the alignment of the object without virtual bases. @@ -91,7 +91,7 @@ class ASTRecordLayout { ASTRecordLayout(const ASTContext &Ctx, uint64_t size, unsigned alignment, uint64_t datasize, const uint64_t *fieldoffsets, unsigned fieldcount, - uint64_t nonvirtualsize, unsigned nonvirtualalign, + CharUnits nonvirtualsize, unsigned nonvirtualalign, CharUnits SizeOfLargestEmptySubobject, const CXXRecordDecl *PrimaryBase, bool IsPrimaryBaseVirtual, @@ -128,9 +128,9 @@ public: return DataSize; } - /// getNonVirtualSize - Get the non-virtual size (in bits) of an object, + /// getNonVirtualSize - Get the non-virtual size (in chars) of an object, /// which is the size of the object without virtual bases. - uint64_t getNonVirtualSize() const { + CharUnits getNonVirtualSize() const { assert(CXXInfo && "Record layout does not have C++ specific info!"); return CXXInfo->NonVirtualSize; diff --git a/lib/AST/ItaniumCXXABI.cpp b/lib/AST/ItaniumCXXABI.cpp index ca1fffa062..bed02b4c00 100644 --- a/lib/AST/ItaniumCXXABI.cpp +++ b/lib/AST/ItaniumCXXABI.cpp @@ -52,7 +52,9 @@ public: return false; const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD); - return Layout.getNonVirtualSize() == Context.Target.getPointerWidth(0); + CharUnits PointerSize = + Context.toCharUnitsFromBits(Context.Target.getPointerWidth(0)); + return Layout.getNonVirtualSize() == PointerSize; } }; diff --git a/lib/AST/MicrosoftCXXABI.cpp b/lib/AST/MicrosoftCXXABI.cpp index c4259f43a7..4de93bb4be 100644 --- a/lib/AST/MicrosoftCXXABI.cpp +++ b/lib/AST/MicrosoftCXXABI.cpp @@ -44,8 +44,10 @@ public: const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD); // In the Microsoft ABI, classes can have one or two vtable pointers. - return Layout.getNonVirtualSize() == Context.Target.getPointerWidth(0) || - Layout.getNonVirtualSize() == Context.Target.getPointerWidth(0) * 2; + CharUnits PointerSize = + Context.toCharUnitsFromBits(Context.Target.getPointerWidth(0)); + return Layout.getNonVirtualSize() == PointerSize || + Layout.getNonVirtualSize() == PointerSize * 2; } }; } diff --git a/lib/AST/RecordLayout.cpp b/lib/AST/RecordLayout.cpp index e027c1ab8d..cdecff66f8 100644 --- a/lib/AST/RecordLayout.cpp +++ b/lib/AST/RecordLayout.cpp @@ -45,7 +45,7 @@ ASTRecordLayout::ASTRecordLayout(const ASTContext &Ctx, uint64_t datasize, const uint64_t *fieldoffsets, unsigned fieldcount, - uint64_t nonvirtualsize, + CharUnits nonvirtualsize, unsigned nonvirtualalign, CharUnits SizeOfLargestEmptySubobject, const CXXRecordDecl *PrimaryBase, diff --git a/lib/AST/RecordLayoutBuilder.cpp b/lib/AST/RecordLayoutBuilder.cpp index 8c62ffdcdf..7e15dcce37 100644 --- a/lib/AST/RecordLayoutBuilder.cpp +++ b/lib/AST/RecordLayoutBuilder.cpp @@ -1115,7 +1115,8 @@ CharUnits RecordLayoutBuilder::LayoutBase(const BaseSubobjectInfo *Base) { if (!Base->Class->isEmpty()) { // Update the data size. - DataSize = Offset + Layout.getNonVirtualSize(); + DataSize = Offset + + (Layout.getNonVirtualSize().getQuantity() * Context.getCharWidth()); Size = std::max(Size, DataSize); } else @@ -1665,7 +1666,7 @@ ASTContext::getASTRecordLayout(const RecordDecl *D) const { new (*this) ASTRecordLayout(*this, Builder->Size, Builder->Alignment, DataSize, Builder->FieldOffsets.data(), Builder->FieldOffsets.size(), - NonVirtualSize, + toCharUnitsFromBits(NonVirtualSize), Builder->NonVirtualAlignment, EmptySubobjects.SizeOfLargestEmptySubobject, Builder->PrimaryBase, @@ -1834,7 +1835,7 @@ static void DumpCXXRecordLayout(llvm::raw_ostream &OS, OS << " sizeof=" << Layout.getSize() / 8; OS << ", dsize=" << Layout.getDataSize() / 8; OS << ", align=" << Layout.getAlignment() / 8 << '\n'; - OS << " nvsize=" << Layout.getNonVirtualSize() / 8; + OS << " nvsize=" << Layout.getNonVirtualSize().getQuantity(); OS << ", nvalign=" << Layout.getNonVirtualAlign() / 8 << '\n'; OS << '\n'; } diff --git a/lib/CodeGen/CGRecordLayoutBuilder.cpp b/lib/CodeGen/CGRecordLayoutBuilder.cpp index 5571e43f78..b9b8c9d073 100644 --- a/lib/CodeGen/CGRecordLayoutBuilder.cpp +++ b/lib/CodeGen/CGRecordLayoutBuilder.cpp @@ -500,12 +500,12 @@ void CGRecordLayoutBuilder::LayoutBase(const CXXRecordDecl *BaseDecl, const ASTRecordLayout &Layout = Types.getContext().getASTRecordLayout(BaseDecl); - uint64_t NonVirtualSize = Layout.getNonVirtualSize(); + CharUnits NonVirtualSize = Layout.getNonVirtualSize(); AppendPadding(BaseOffset / 8, 1); // FIXME: Actually use a better type than [sizeof(BaseDecl) x i8] when we can. - AppendBytes(NonVirtualSize / 8); + AppendBytes(NonVirtualSize.getQuantity()); } void @@ -520,12 +520,12 @@ CGRecordLayoutBuilder::LayoutVirtualBase(const CXXRecordDecl *BaseDecl, const ASTRecordLayout &Layout = Types.getContext().getASTRecordLayout(BaseDecl); - uint64_t NonVirtualSize = Layout.getNonVirtualSize(); + CharUnits NonVirtualSize = Layout.getNonVirtualSize(); AppendPadding(BaseOffset / 8, 1); // FIXME: Actually use a better type than [sizeof(BaseDecl) x i8] when we can. - AppendBytes(NonVirtualSize / 8); + AppendBytes(NonVirtualSize.getQuantity()); // FIXME: Add the vbase field info. } @@ -616,8 +616,9 @@ bool CGRecordLayoutBuilder::ComputeNonVirtualBaseType(const CXXRecordDecl *RD) { const ASTRecordLayout &Layout = Types.getContext().getASTRecordLayout(RD); + uint64_t AlignedNonVirtualTypeSize = - llvm::RoundUpToAlignment(Layout.getNonVirtualSize(), + llvm::RoundUpToAlignment(Layout.getNonVirtualSize().getQuantity() * 8, Layout.getNonVirtualAlign()) / 8; @@ -855,7 +856,7 @@ CGRecordLayout *CodeGenTypes::ComputeRecordLayout(const RecordDecl *D) { if (BaseTy) { uint64_t AlignedNonVirtualTypeSizeInBits = - llvm::RoundUpToAlignment(Layout.getNonVirtualSize(), + llvm::RoundUpToAlignment(Layout.getNonVirtualSize().getQuantity() * 8, Layout.getNonVirtualAlign()); assert(AlignedNonVirtualTypeSizeInBits ==