[PATCH] Thread the info about vbptr sharing through ASTRecordLayout
Timur Iskhodzhanov
timurrrr at google.com
Thu Nov 7 06:43:59 PST 2013
Hi rnk,
This addresses the post-commit comments on r194082.
http://llvm-reviews.chandlerc.com/D2120
Files:
include/clang/AST/RecordLayout.h
lib/AST/RecordLayout.cpp
lib/AST/RecordLayoutBuilder.cpp
lib/AST/VTableBuilder.cpp
Index: include/clang/AST/RecordLayout.h
===================================================================
--- include/clang/AST/RecordLayout.h
+++ include/clang/AST/RecordLayout.h
@@ -110,6 +110,9 @@
/// PrimaryBase - The primary base info for this record.
llvm::PointerIntPair<const CXXRecordDecl *, 1, bool> PrimaryBase;
+
+ /// BaseSharingVBPtr - The base we share vbptr with.
+ const CXXRecordDecl *BaseSharingVBPtr;
/// FIXME: This should really use a SmallPtrMap, once we have one in LLVM :)
typedef llvm::DenseMap<const CXXRecordDecl *, CharUnits> BaseOffsetsMapTy;
@@ -143,6 +146,7 @@
CharUnits SizeOfLargestEmptySubobject,
const CXXRecordDecl *PrimaryBase,
bool IsPrimaryBaseVirtual,
+ const CXXRecordDecl *BaseSharingVBPtr,
bool ForceAlign,
const BaseOffsetsMapTy& BaseOffsets,
const VBaseOffsetsMapTy& VBaseOffsets);
@@ -277,6 +281,11 @@
return CXXInfo->VBPtrOffset;
}
+ const CXXRecordDecl *getBaseSharingVBPtr() const {
+ assert(CXXInfo && "Record layout does not have C++ specific info!");
+ return CXXInfo->BaseSharingVBPtr;
+ }
+
const VBaseOffsetsMapTy &getVBaseOffsetsMap() const {
assert(CXXInfo && "Record layout does not have C++ specific info!");
return CXXInfo->VBaseOffsets;
Index: lib/AST/RecordLayout.cpp
===================================================================
--- lib/AST/RecordLayout.cpp
+++ lib/AST/RecordLayout.cpp
@@ -54,6 +54,7 @@
CharUnits SizeOfLargestEmptySubobject,
const CXXRecordDecl *PrimaryBase,
bool IsPrimaryBaseVirtual,
+ const CXXRecordDecl *BaseSharingVBPtr,
bool AlignAfterVBases,
const BaseOffsetsMapTy& BaseOffsets,
const VBaseOffsetsMapTy& VBaseOffsets)
@@ -76,6 +77,7 @@
CXXInfo->VBPtrOffset = vbptroffset;
CXXInfo->HasVFPtr = hasVFPtr;
CXXInfo->HasOwnVBPtr = hasOwnVBPtr;
+ CXXInfo->BaseSharingVBPtr = BaseSharingVBPtr;
CXXInfo->AlignAfterVBases = AlignAfterVBases;
Index: lib/AST/RecordLayoutBuilder.cpp
===================================================================
--- lib/AST/RecordLayoutBuilder.cpp
+++ lib/AST/RecordLayoutBuilder.cpp
@@ -2677,7 +2677,8 @@
Builder.DataSize, Builder.FieldOffsets.data(),
Builder.FieldOffsets.size(), Builder.DataSize,
Builder.NonVirtualAlignment, CharUnits::Zero(), Builder.PrimaryBase,
- false, Builder.AlignAfterVBases, Builder.Bases, Builder.VBases);
+ false, Builder.SharedVBPtrBase, Builder.AlignAfterVBases,
+ Builder.Bases, Builder.VBases);
} else {
Builder.layout(D);
return new (*this) ASTRecordLayout(
@@ -2745,7 +2746,7 @@
EmptySubobjects.SizeOfLargestEmptySubobject,
Builder.PrimaryBase,
Builder.PrimaryBaseIsVirtual,
- true,
+ 0, true,
Builder.Bases, Builder.VBases);
} else {
RecordLayoutBuilder Builder(*this, /*EmptySubobjects=*/0);
Index: lib/AST/VTableBuilder.cpp
===================================================================
--- lib/AST/VTableBuilder.cpp
+++ lib/AST/VTableBuilder.cpp
@@ -3363,30 +3363,17 @@
const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD);
BasesSetVectorTy VisitedBases;
- // First, see if the Derived class shared the vbptr
- // with the first non-virtual base.
- for (CXXRecordDecl::base_class_const_iterator I = RD->bases_begin(),
- E = RD->bases_end(); I != E; ++I) {
- if (I->isVirtual())
- continue;
-
- const CXXRecordDecl *CurBase = I->getType()->getAsCXXRecordDecl();
- CharUnits DerivedVBPtrOffset = Layout.getVBPtrOffset(),
- BaseOffset = Layout.getBaseClassOffset(CurBase);
- const ASTRecordLayout &BaseLayout = Context.getASTRecordLayout(CurBase);
- if (!BaseLayout.hasVBPtr() ||
- DerivedVBPtrOffset != BaseOffset + BaseLayout.getVBPtrOffset())
- continue;
-
+ // First, see if the Derived class shared the vbptr with a non-virtual base.
+ if (const CXXRecordDecl *VBPtrBase = Layout.getBaseSharingVBPtr()) {
// If the Derived class shares the vbptr with a non-virtual base,
// it inherits its vbase indices.
- computeVBTableRelatedInformation(CurBase);
- for (CXXRecordDecl::base_class_const_iterator J = CurBase->vbases_begin(),
- F = CurBase->vbases_end(); J != F; ++J) {
- const CXXRecordDecl *SubVBase = J->getType()->getAsCXXRecordDecl();
- assert(VBTableIndices.count(ClassPairTy(CurBase, SubVBase)));
+ computeVBTableRelatedInformation(VBPtrBase);
+ for (CXXRecordDecl::base_class_const_iterator I = VBPtrBase->vbases_begin(),
+ E = VBPtrBase->vbases_end(); I != E; ++I) {
+ const CXXRecordDecl *SubVBase = I->getType()->getAsCXXRecordDecl();
+ assert(VBTableIndices.count(ClassPairTy(VBPtrBase, SubVBase)));
VBTableIndices[ClassPairTy(RD, SubVBase)] =
- VBTableIndices[ClassPairTy(CurBase, SubVBase)];
+ VBTableIndices[ClassPairTy(VBPtrBase, SubVBase)];
VisitedBases.insert(SubVBase);
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2120.1.patch
Type: text/x-patch
Size: 5468 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131107/57b28c30/attachment.bin>
More information about the cfe-commits
mailing list