diff --git a/include/clang/AST/RecordLayout.h b/include/clang/AST/RecordLayout.h index 66792d715d..7490b1d66b 100644 --- a/include/clang/AST/RecordLayout.h +++ b/include/clang/AST/RecordLayout.h @@ -91,9 +91,10 @@ class ASTRecordLayout { const uint64_t *fieldoffsets, unsigned fieldcount, uint64_t nonvirtualsize, unsigned nonvirtualalign, const CXXRecordDecl *PB, bool PBVirtual, - const CXXRecordDecl **bases, const uint64_t *baseoffsets, - unsigned basecount, const CXXRecordDecl **vbases, - const uint64_t *vbaseoffsets,unsigned vbasecount) + const std::pair *bases, + unsigned numbases, + const std::pair *vbases, + unsigned numvbases) : Size(size), DataSize(datasize), FieldOffsets(0), Alignment(alignment), FieldCount(fieldcount), CXXInfo(new CXXRecordLayoutInfo) { if (FieldCount > 0) { @@ -106,10 +107,10 @@ class ASTRecordLayout { CXXInfo->PrimaryBaseWasVirtual = PBVirtual; CXXInfo->NonVirtualSize = nonvirtualsize; CXXInfo->NonVirtualAlign = nonvirtualalign; - for (unsigned i = 0; i != basecount; ++i) - CXXInfo->BaseOffsets[bases[i]] = baseoffsets[i]; - for (unsigned i = 0; i != vbasecount; ++i) - CXXInfo->VBaseOffsets[vbases[i]] = vbaseoffsets[i]; + for (unsigned i = 0; i != numbases; ++i) + CXXInfo->BaseOffsets[bases[i].first] = bases[i].second; + for (unsigned i = 0; i != numvbases; ++i) + CXXInfo->VBaseOffsets[vbases[i].first] = vbases[i].second; } ~ASTRecordLayout() { diff --git a/lib/AST/RecordLayoutBuilder.cpp b/lib/AST/RecordLayoutBuilder.cpp index 598bd261d7..e60b307d3b 100644 --- a/lib/AST/RecordLayoutBuilder.cpp +++ b/lib/AST/RecordLayoutBuilder.cpp @@ -198,8 +198,7 @@ void ASTRecordLayoutBuilder::LayoutVirtualBases(const CXXRecordDecl *RD, // Mark it so we don't lay it out twice. mark.insert(Base); assert (IndirectPrimary.count(Base) && "IndirectPrimary was wrong"); - VBases.push_back(Base); - VBaseOffsets.push_back(Offset); + VBases.push_back(std::make_pair(Base, Offset)); } else if (IndirectPrimary.count(Base)) { // Someone else will eventually lay this out. ; @@ -210,7 +209,7 @@ void ASTRecordLayoutBuilder::LayoutVirtualBases(const CXXRecordDecl *RD, // Mark it so we don't lay it out twice. mark.insert(Base); LayoutVirtualBase(Base); - BaseOffset = *(VBaseOffsets.end()-1); + BaseOffset = VBases.back().second; } } if (Base->getNumVBases()) { @@ -236,13 +235,10 @@ void ASTRecordLayoutBuilder::LayoutBaseNonVirtually(const CXXRecordDecl *RD, Size = (Size + (BaseAlign-1)) & ~(BaseAlign-1); // Add base class offsets. - if (IsVirtualBase) { - VBases.push_back(RD); - VBaseOffsets.push_back(Size); - } else { - Bases.push_back(RD); - BaseOffsets.push_back(Size); - } + if (IsVirtualBase) + VBases.push_back(std::make_pair(RD, Size)); + else + Bases.push_back(std::make_pair(RD, Size)); #if 0 // And now add offsets for all our primary virtual bases as well, so @@ -469,11 +465,6 @@ ASTRecordLayoutBuilder::ComputeLayout(ASTContext &Ctx, // FIXME: IsPODForThePurposeOfLayout should be stored in the record layout. bool IsPODForThePurposeOfLayout = cast(D)->isPOD(); - assert(Builder.Bases.size() == Builder.BaseOffsets.size() && - "Base offsets vector must be same size as bases vector!"); - assert(Builder.VBases.size() == Builder.VBaseOffsets.size() && - "Base offsets vector must be same size as bases vector!"); - // FIXME: This should be done in FinalizeLayout. uint64_t DataSize = IsPODForThePurposeOfLayout ? Builder.Size : Builder.NextOffset; @@ -488,10 +479,8 @@ ASTRecordLayoutBuilder::ComputeLayout(ASTContext &Ctx, Builder.PrimaryBase, Builder.PrimaryBaseWasVirtual, Builder.Bases.data(), - Builder.BaseOffsets.data(), Builder.Bases.size(), Builder.VBases.data(), - Builder.VBaseOffsets.data(), Builder.VBases.size()); } diff --git a/lib/AST/RecordLayoutBuilder.h b/lib/AST/RecordLayoutBuilder.h index efaa2eeb98..39adc29022 100644 --- a/lib/AST/RecordLayoutBuilder.h +++ b/lib/AST/RecordLayoutBuilder.h @@ -40,11 +40,11 @@ class ASTRecordLayoutBuilder { const CXXRecordDecl *PrimaryBase; bool PrimaryBaseWasVirtual; - llvm::SmallVector Bases; - llvm::SmallVector BaseOffsets; - - llvm::SmallVector VBases; - llvm::SmallVector VBaseOffsets; + typedef llvm::SmallVector, 4> BaseOffsetsTy; + + BaseOffsetsTy Bases; + BaseOffsetsTy VBases; ASTRecordLayoutBuilder(ASTContext &Ctx);