From: Reid Kleckner Date: Wed, 20 Jul 2016 14:40:25 +0000 (+0000) Subject: [MS] Improve VPtrInfo field names and doc comments X-Git-Tag: llvmorg-4.0.0-rc1~14783 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8ad06d6546a3a28673a0a0dc4d1569801fd2c930;p=platform%2Fupstream%2Fllvm.git [MS] Improve VPtrInfo field names and doc comments 'ReusingBase' was a terrible name. It might actually refer to the most derived class, which is not a base. 'BaseWithVPtr' was also bad, since again, it could refer to the most derived class. It was actually the first base to introduce the vptr, so now it is 'IntroducingObject'. llvm-svn: 276120 --- diff --git a/clang/include/clang/AST/VTableBuilder.h b/clang/include/clang/AST/VTableBuilder.h index 132ffec..28ec4b8 100644 --- a/clang/include/clang/AST/VTableBuilder.h +++ b/clang/include/clang/AST/VTableBuilder.h @@ -398,21 +398,21 @@ struct VPtrInfo { typedef SmallVector BasePath; VPtrInfo(const CXXRecordDecl *RD) - : ReusingBase(RD), BaseWithVPtr(RD), NextBaseToMangle(RD) {} + : ObjectWithVPtr(RD), IntroducingObject(RD), NextBaseToMangle(RD) {} - /// The vtable will hold all of the virtual bases or virtual methods of - /// ReusingBase. This may or may not be the same class as VPtrSubobject.Base. - /// A derived class will reuse the vptr of the first non-virtual base - /// subobject that has one. - const CXXRecordDecl *ReusingBase; + /// This is the most derived class that has this vptr at offset zero. When + /// single inheritance is used, this is always the most derived class. If + /// multiple inheritance is used, it may be any direct or indirect base. + const CXXRecordDecl *ObjectWithVPtr; - /// BaseWithVPtr is at this offset from its containing complete object or + /// This is the class that introduced the vptr by declaring new virtual + /// methods or virtual bases. + const CXXRecordDecl *IntroducingObject; + + /// IntroducingObject is at this offset from its containing complete object or /// virtual base. CharUnits NonVirtualOffset; - /// The vptr is stored inside this subobject. - const CXXRecordDecl *BaseWithVPtr; - /// The bases from the inheritance path that got used to mangle the vbtable /// name. This is not really a full path like a CXXBasePath. It holds the /// subset of records that need to be mangled into the vbtable symbol name in @@ -431,7 +431,7 @@ struct VPtrInfo { /// This holds the base classes path from the complete type to the first base /// with the given vfptr offset, in the base-to-derived order. Only used for /// vftables. - BasePath PathToBaseWithVPtr; + BasePath PathToIntroducingObject; /// Static offset from the top of the most derived class to this vfptr, /// including any virtual base offset. Only used for vftables. diff --git a/clang/lib/AST/VTableBuilder.cpp b/clang/lib/AST/VTableBuilder.cpp index 640fbf4..5c5fefd 100644 --- a/clang/lib/AST/VTableBuilder.cpp +++ b/clang/lib/AST/VTableBuilder.cpp @@ -2931,8 +2931,8 @@ void VFTableBuilder::AddMethods(BaseSubobject Base, unsigned BaseDepth, // class. const CXXRecordDecl *NextBase = nullptr, *NextLastVBase = LastVBase; CharUnits NextBaseOffset; - if (BaseDepth < WhichVFPtr.PathToBaseWithVPtr.size()) { - NextBase = WhichVFPtr.PathToBaseWithVPtr[BaseDepth]; + if (BaseDepth < WhichVFPtr.PathToIntroducingObject.size()) { + NextBase = WhichVFPtr.PathToIntroducingObject[BaseDepth]; if (isDirectVBase(NextBase, RD)) { NextLastVBase = NextBase; NextBaseOffset = MostDerivedClassLayout.getVBaseClassOffset(NextBase); @@ -3124,7 +3124,7 @@ static void dumpMicrosoftThunkAdjustment(const ThunkInfo &TI, raw_ostream &Out, void VFTableBuilder::dumpLayout(raw_ostream &Out) { Out << "VFTable for "; - PrintBasePath(WhichVFPtr.PathToBaseWithVPtr, Out); + PrintBasePath(WhichVFPtr.PathToIntroducingObject, Out); Out << "'"; MostDerivedClass->printQualifiedName(Out); Out << "' (" << Components.size() @@ -3311,10 +3311,10 @@ void MicrosoftVTableContext::computeVTablePaths(bool ForVBTables, // Keep track of which vtable the derived class is going to extend with // new methods or bases. We append to either the vftable of our primary // base, or the first non-virtual base that has a vbtable. - if (P->ReusingBase == Base && + if (P->ObjectWithVPtr == Base && Base == (ForVBTables ? Layout.getBaseSharingVBPtr() : Layout.getPrimaryBase())) - P->ReusingBase = RD; + P->ObjectWithVPtr = RD; // Keep track of the full adjustment from the MDC to this vtable. The // adjustment is captured by an optional vbase and a non-virtual offset. @@ -3401,14 +3401,14 @@ typedef llvm::SetVector, } // This recursive function finds all paths from a subobject centered at -// (RD, Offset) to the subobject located at BaseWithVPtr. +// (RD, Offset) to the subobject located at IntroducingObject. static void findPathsToSubobject(ASTContext &Context, const ASTRecordLayout &MostDerivedLayout, const CXXRecordDecl *RD, CharUnits Offset, - BaseSubobject BaseWithVPtr, + BaseSubobject IntroducingObject, FullPathTy &FullPath, std::list &Paths) { - if (BaseSubobject(RD, Offset) == BaseWithVPtr) { + if (BaseSubobject(RD, Offset) == IntroducingObject) { Paths.push_back(FullPath); return; } @@ -3422,7 +3422,7 @@ static void findPathsToSubobject(ASTContext &Context, : Offset + Layout.getBaseClassOffset(Base); FullPath.insert(BaseSubobject(Base, NewOffset)); findPathsToSubobject(Context, MostDerivedLayout, Base, NewOffset, - BaseWithVPtr, FullPath, Paths); + IntroducingObject, FullPath, Paths); FullPath.pop_back(); } } @@ -3497,7 +3497,7 @@ static const FullPathTy *selectBestPath(ASTContext &Context, CharUnits BaseOffset = getOffsetOfFullPath(Context, TopLevelRD, SpecificPath); FinalOverriders Overriders(TopLevelRD, CharUnits::Zero(), TopLevelRD); - for (const CXXMethodDecl *MD : Info->BaseWithVPtr->methods()) { + for (const CXXMethodDecl *MD : Info->IntroducingObject->methods()) { if (!MD->isVirtual()) continue; FinalOverriders::OverriderInfo OI = @@ -3555,15 +3555,15 @@ static void computeFullPathsForVFTables(ASTContext &Context, for (VPtrInfo *Info : Paths) { findPathsToSubobject( Context, MostDerivedLayout, RD, CharUnits::Zero(), - BaseSubobject(Info->BaseWithVPtr, Info->FullOffsetInMDC), FullPath, + BaseSubobject(Info->IntroducingObject, Info->FullOffsetInMDC), FullPath, FullPaths); FullPath.clear(); removeRedundantPaths(FullPaths); - Info->PathToBaseWithVPtr.clear(); + Info->PathToIntroducingObject.clear(); if (const FullPathTy *BestPath = selectBestPath(Context, RD, Info, FullPaths)) for (const BaseSubobject &BSO : *BestPath) - Info->PathToBaseWithVPtr.push_back(BSO.getBase()); + Info->PathToIntroducingObject.push_back(BSO.getBase()); FullPaths.clear(); } } diff --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp b/clang/lib/CodeGen/MicrosoftCXXABI.cpp index 41cd53c..6b919d1 100644 --- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp +++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp @@ -98,7 +98,7 @@ public: const VBTableGlobals &VBGlobals = enumerateVBTables(RD); for (const VPtrInfo *VBT : *VBGlobals.VBTables) { const ASTRecordLayout &SubobjectLayout = - Context.getASTRecordLayout(VBT->BaseWithVPtr); + Context.getASTRecordLayout(VBT->IntroducingObject); CharUnits Offs = VBT->NonVirtualOffset; Offs += SubobjectLayout.getVBPtrOffset(); if (VBT->getVBaseWithVPtr()) @@ -1211,7 +1211,7 @@ void MicrosoftCXXABI::EmitVBPtrStores(CodeGenFunction &CGF, const VPtrInfo *VBT = (*VBGlobals.VBTables)[I]; llvm::GlobalVariable *GV = VBGlobals.Globals[I]; const ASTRecordLayout &SubobjectLayout = - Context.getASTRecordLayout(VBT->BaseWithVPtr); + Context.getASTRecordLayout(VBT->IntroducingObject); CharUnits Offs = VBT->NonVirtualOffset; Offs += SubobjectLayout.getVBPtrOffset(); if (VBT->getVBaseWithVPtr()) @@ -1220,7 +1220,7 @@ void MicrosoftCXXABI::EmitVBPtrStores(CodeGenFunction &CGF, llvm::Value *GVPtr = CGF.Builder.CreateConstInBoundsGEP2_32(GV->getValueType(), GV, 0, 0); VBPtr = CGF.Builder.CreateElementBitCast(VBPtr, GVPtr->getType(), - "vbptr." + VBT->ReusingBase->getName()); + "vbptr." + VBT->ObjectWithVPtr->getName()); CGF.Builder.CreateStore(GVPtr, VBPtr); } } @@ -1514,20 +1514,20 @@ void MicrosoftCXXABI::emitVTableTypeMetadata(VPtrInfo *Info, getContext().getTargetInfo().getPointerWidth(0)) : CharUnits::Zero(); - if (Info->PathToBaseWithVPtr.empty()) { + if (Info->PathToIntroducingObject.empty()) { CGM.AddVTableTypeMetadata(VTable, AddressPoint, RD); return; } // Add a bitset entry for the least derived base belonging to this vftable. CGM.AddVTableTypeMetadata(VTable, AddressPoint, - Info->PathToBaseWithVPtr.back()); + Info->PathToIntroducingObject.back()); // Add a bitset entry for each derived class that is laid out at the same // offset as the least derived base. - for (unsigned I = Info->PathToBaseWithVPtr.size() - 1; I != 0; --I) { - const CXXRecordDecl *DerivedRD = Info->PathToBaseWithVPtr[I - 1]; - const CXXRecordDecl *BaseRD = Info->PathToBaseWithVPtr[I]; + for (unsigned I = Info->PathToIntroducingObject.size() - 1; I != 0; --I) { + const CXXRecordDecl *DerivedRD = Info->PathToIntroducingObject[I - 1]; + const CXXRecordDecl *BaseRD = Info->PathToIntroducingObject[I]; const ASTRecordLayout &Layout = getContext().getASTRecordLayout(DerivedRD); @@ -1972,7 +1972,7 @@ MicrosoftCXXABI::getAddrOfVBTable(const VPtrInfo &VBT, const CXXRecordDecl *RD, StringRef Name = OutName.str(); llvm::ArrayType *VBTableType = - llvm::ArrayType::get(CGM.IntTy, 1 + VBT.ReusingBase->getNumVBases()); + llvm::ArrayType::get(CGM.IntTy, 1 + VBT.ObjectWithVPtr->getNumVBases()); assert(!CGM.getModule().getNamedGlobal(Name) && "vbtable with this name already exists: mangling bug?"); @@ -1994,24 +1994,24 @@ MicrosoftCXXABI::getAddrOfVBTable(const VPtrInfo &VBT, const CXXRecordDecl *RD, void MicrosoftCXXABI::emitVBTableDefinition(const VPtrInfo &VBT, const CXXRecordDecl *RD, llvm::GlobalVariable *GV) const { - const CXXRecordDecl *ReusingBase = VBT.ReusingBase; + const CXXRecordDecl *ObjectWithVPtr = VBT.ObjectWithVPtr; - assert(RD->getNumVBases() && ReusingBase->getNumVBases() && + assert(RD->getNumVBases() && ObjectWithVPtr->getNumVBases() && "should only emit vbtables for classes with vbtables"); const ASTRecordLayout &BaseLayout = - getContext().getASTRecordLayout(VBT.BaseWithVPtr); + getContext().getASTRecordLayout(VBT.IntroducingObject); const ASTRecordLayout &DerivedLayout = getContext().getASTRecordLayout(RD); - SmallVector Offsets(1 + ReusingBase->getNumVBases(), + SmallVector Offsets(1 + ObjectWithVPtr->getNumVBases(), nullptr); - // The offset from ReusingBase's vbptr to itself always leads. + // The offset from ObjectWithVPtr's vbptr to itself always leads. CharUnits VBPtrOffset = BaseLayout.getVBPtrOffset(); Offsets[0] = llvm::ConstantInt::get(CGM.IntTy, -VBPtrOffset.getQuantity()); MicrosoftVTableContext &Context = CGM.getMicrosoftVTableContext(); - for (const auto &I : ReusingBase->vbases()) { + for (const auto &I : ObjectWithVPtr->vbases()) { const CXXRecordDecl *VBase = I.getType()->getAsCXXRecordDecl(); CharUnits Offset = DerivedLayout.getVBaseClassOffset(VBase); assert(!Offset.isNegative()); @@ -2023,7 +2023,7 @@ void MicrosoftCXXABI::emitVBTableDefinition(const VPtrInfo &VBT, DerivedLayout.getVBaseClassOffset(VBT.getVBaseWithVPtr()); Offset -= CompleteVBPtrOffset; - unsigned VBIndex = Context.getVBTableIndex(ReusingBase, VBase); + unsigned VBIndex = Context.getVBTableIndex(ObjectWithVPtr, VBase); assert(Offsets[VBIndex] == nullptr && "The same vbindex seen twice?"); Offsets[VBIndex] = llvm::ConstantInt::get(CGM.IntTy, Offset.getQuantity()); }