From 1d40d62f137d3831729131e56562fc490b7f9591 Mon Sep 17 00:00:00 2001 From: Warren Hunt Date: Wed, 13 Nov 2013 22:16:13 +0000 Subject: [PATCH] No functional change. Renaming a variable in RecordLayoutBuilder and improving comments to make documentation more accurate. Differential Revision:http://llvm-reviews.chandlerc.com/D2172 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@194609 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/RecordLayout.h | 17 ++++++++++------- lib/AST/RecordLayout.cpp | 4 ++-- lib/AST/RecordLayoutBuilder.cpp | 23 +++++++++++++---------- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/include/clang/AST/RecordLayout.h b/include/clang/AST/RecordLayout.h index bf4a91ad9c..7268b3a824 100644 --- a/include/clang/AST/RecordLayout.h +++ b/include/clang/AST/RecordLayout.h @@ -95,9 +95,10 @@ private: /// its base classes? bool HasOwnVFPtr : 1; - /// HasVFPtr - Does this class have a vftable at all (could be inherited - /// from its primary base.) - bool HasVFPtr : 1; + /// HasVFPtr - Does this class have a vftable that could be extended by + /// a derived class. The class may have inherited this pointer from + /// a primary base class. + bool HasExtendableVFPtr : 1; /// AlignAfterVBases - Force appropriate alignment after virtual bases are /// laid out in MS-C++-ABI. @@ -133,7 +134,7 @@ private: typedef CXXRecordLayoutInfo::BaseOffsetsMapTy BaseOffsetsMapTy; ASTRecordLayout(const ASTContext &Ctx, CharUnits size, CharUnits alignment, - bool hasOwnVFPtr, bool hasVFPtr, + bool hasOwnVFPtr, bool hasExtendableVFPtr, CharUnits vbptroffset, CharUnits datasize, const uint64_t *fieldoffsets, unsigned fieldcount, @@ -240,10 +241,12 @@ public: return CXXInfo->HasOwnVFPtr; } - /// hasVFPtr - Does this class have a virtual function table pointer. - bool hasVFPtr() const { + /// hasVFPtr - Does this class have a virtual function table pointer + /// that can be extended by a derived class? This is synonymous with + /// this class having a VFPtr at offset zero. + bool hasExtendableVFPtr() const { assert(CXXInfo && "Record layout does not have C++ specific info!"); - return CXXInfo->HasVFPtr; + return CXXInfo->HasExtendableVFPtr; } /// hasOwnVBPtr - Does this class provide its own virtual-base diff --git a/lib/AST/RecordLayout.cpp b/lib/AST/RecordLayout.cpp index df5f79c961..71e44ecf92 100644 --- a/lib/AST/RecordLayout.cpp +++ b/lib/AST/RecordLayout.cpp @@ -43,7 +43,7 @@ ASTRecordLayout::ASTRecordLayout(const ASTContext &Ctx, CharUnits size, // Constructor for C++ records. ASTRecordLayout::ASTRecordLayout(const ASTContext &Ctx, CharUnits size, CharUnits alignment, - bool hasOwnVFPtr, bool hasVFPtr, + bool hasOwnVFPtr, bool hasExtendableVFPtr, CharUnits vbptroffset, CharUnits datasize, const uint64_t *fieldoffsets, @@ -74,7 +74,7 @@ ASTRecordLayout::ASTRecordLayout(const ASTContext &Ctx, CXXInfo->VBaseOffsets = VBaseOffsets; CXXInfo->HasOwnVFPtr = hasOwnVFPtr; CXXInfo->VBPtrOffset = vbptroffset; - CXXInfo->HasVFPtr = hasVFPtr; + CXXInfo->HasExtendableVFPtr = hasExtendableVFPtr; CXXInfo->BaseSharingVBPtr = BaseSharingVBPtr; CXXInfo->AlignAfterVBases = AlignAfterVBases; diff --git a/lib/AST/RecordLayoutBuilder.cpp b/lib/AST/RecordLayoutBuilder.cpp index d0426fa8db..524c3ba254 100644 --- a/lib/AST/RecordLayoutBuilder.cpp +++ b/lib/AST/RecordLayoutBuilder.cpp @@ -2118,8 +2118,10 @@ public: const CXXRecordDecl *PrimaryBase; /// \brief The class we share our vb-pointer with. const CXXRecordDecl *SharedVBPtrBase; - /// \brief True if the class has a (not necessarily its own) vftable pointer. - bool HasVFPtr : 1; + /// \brief True if the class has a vftable pointer that can be extended + /// by this class or classes derived from it. Such a vfptr will always occur + /// at offset 0. + bool HasExtendableVFPtr : 1; /// \brief True if the class has a (not necessarily its own) vbtable pointer. bool HasVBPtr : 1; /// \brief Offset to the virtual base table pointer (if one exists). @@ -2226,7 +2228,7 @@ MicrosoftRecordLayoutBuilder::initializeCXXLayout(const CXXRecordDecl *RD) { // Initialize information about the bases. HasVBPtr = false; - HasVFPtr = false; + HasExtendableVFPtr = false; SharedVBPtrBase = 0; PrimaryBase = 0; VirtualAlignment = CharUnits::One(); @@ -2251,9 +2253,9 @@ MicrosoftRecordLayoutBuilder::initializeCXXLayout(const CXXRecordDecl *RD) { continue; } // We located a primary base class! - if (!PrimaryBase && Layout.hasVFPtr()) { + if (!PrimaryBase && Layout.hasExtendableVFPtr()) { PrimaryBase = BaseDecl; - HasVFPtr = true; + HasExtendableVFPtr = true; } // We located a base to share a VBPtr with! if (!SharedVBPtrBase && Layout.hasVBPtr()) { @@ -2279,12 +2281,12 @@ void MicrosoftRecordLayoutBuilder::layoutVFPtr(const CXXRecordDecl *RD) { // Look at all of our methods to determine if we need a VFPtr. We need a // vfptr if we define a new virtual function. - if (!HasVFPtr && RD->isDynamicClass()) + if (!HasExtendableVFPtr && RD->isDynamicClass()) for (CXXRecordDecl::method_iterator i = RD->method_begin(), e = RD->method_end(); - !HasVFPtr && i != e; ++i) - HasVFPtr = i->isVirtual() && i->size_overridden_methods() == 0; - if (!HasVFPtr) + !HasExtendableVFPtr && i != e; ++i) + HasExtendableVFPtr = i->isVirtual() && i->size_overridden_methods() == 0; + if (!HasExtendableVFPtr) return; // MSVC 32 (but not 64) potentially over-aligns the vf-table pointer by giving @@ -2672,7 +2674,8 @@ ASTContext::BuildMicrosoftASTRecordLayout(const RecordDecl *D) const { Builder.cxxLayout(RD); return new (*this) ASTRecordLayout( *this, Builder.Size, Builder.Alignment, - Builder.HasVFPtr && !Builder.PrimaryBase, Builder.HasVFPtr, + Builder.HasExtendableVFPtr && !Builder.PrimaryBase, + Builder.HasExtendableVFPtr, Builder.VBPtrOffset, Builder.DataSize, Builder.FieldOffsets.data(), Builder.FieldOffsets.size(), Builder.DataSize, Builder.NonVirtualAlignment, CharUnits::Zero(), Builder.PrimaryBase, -- 2.40.0