From d6ff5d77873052b57ae04e4060d35f4f94f0b82f Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Sat, 29 May 2010 17:48:36 +0000 Subject: [PATCH] Change LayoutVirtualBase to also take a BaseSubobjectInfo. llvm-svn: 105104 --- clang/lib/AST/RecordLayoutBuilder.cpp | 28 ++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/clang/lib/AST/RecordLayoutBuilder.cpp b/clang/lib/AST/RecordLayoutBuilder.cpp index cc29832c60ce..7dbfa9608c4f 100644 --- a/clang/lib/AST/RecordLayoutBuilder.cpp +++ b/clang/lib/AST/RecordLayoutBuilder.cpp @@ -579,7 +579,7 @@ class RecordLayoutBuilder { const CXXRecordDecl *MostDerivedClass); /// LayoutVirtualBase - Lays out a single virtual base. - void LayoutVirtualBase(const CXXRecordDecl *Base); + void LayoutVirtualBase(const BaseSubobjectInfo *Base); /// LayoutBase - Will lay out a base and return the offset where it was /// placed, in bits. @@ -885,7 +885,7 @@ RecordLayoutBuilder::LayoutNonVirtualBases(const CXXRecordDecl *RD) { "vbase already visited!"); VisitedVirtualBases.insert(PrimaryBase); - LayoutVirtualBase(PrimaryBase); + LayoutVirtualBase(PrimaryBaseInfo); } else { BaseSubobjectInfo *PrimaryBaseInfo = NonVirtualBaseInfo.lookup(PrimaryBase); @@ -1005,40 +1005,42 @@ RecordLayoutBuilder::LayoutVirtualBases(const CXXRecordDecl *RD, assert(!I->getType()->isDependentType() && "Cannot layout class with dependent bases."); - const CXXRecordDecl *Base = + const CXXRecordDecl *BaseDecl = cast(I->getType()->getAs()->getDecl()); if (I->isVirtual()) { - if (PrimaryBase != Base || !PrimaryBaseIsVirtual) { - bool IndirectPrimaryBase = IndirectPrimaryBases.count(Base); + if (PrimaryBase != BaseDecl || !PrimaryBaseIsVirtual) { + bool IndirectPrimaryBase = IndirectPrimaryBases.count(BaseDecl); // Only lay out the virtual base if it's not an indirect primary base. if (!IndirectPrimaryBase) { // Only visit virtual bases once. - if (!VisitedVirtualBases.insert(Base)) + if (!VisitedVirtualBases.insert(BaseDecl)) continue; - LayoutVirtualBase(Base); + const BaseSubobjectInfo *BaseInfo = VirtualBaseInfo.lookup(BaseDecl); + assert(BaseInfo && "Did not find virtual base info!"); + LayoutVirtualBase(BaseInfo); } } } - if (!Base->getNumVBases()) { + if (!BaseDecl->getNumVBases()) { // This base isn't interesting since it doesn't have any virtual bases. continue; } - LayoutVirtualBases(Base, MostDerivedClass); + LayoutVirtualBases(BaseDecl, MostDerivedClass); } } -void RecordLayoutBuilder::LayoutVirtualBase(const CXXRecordDecl *Base) { +void RecordLayoutBuilder::LayoutVirtualBase(const BaseSubobjectInfo *Base) { // Layout the base. - uint64_t Offset = LayoutBase(Base, /*BaseIsVirtual=*/true); + uint64_t Offset = LayoutBase(Base->Class, /*BaseIsVirtual=*/true); // Add its base class offset. - if (!VBases.insert(std::make_pair(Base, Offset)).second) - assert(false && "Added same vbase offset more than once!"); + assert(!VBases.count(Base->Class) && "vbase offset already exists!"); + VBases.insert(std::make_pair(Base->Class, Offset)); } uint64_t RecordLayoutBuilder::LayoutBase(const CXXRecordDecl *Base,