typedef SmallVector<const CXXRecordDecl *, 1> 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
/// 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.
// 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);
void VFTableBuilder::dumpLayout(raw_ostream &Out) {
Out << "VFTable for ";
- PrintBasePath(WhichVFPtr.PathToBaseWithVPtr, Out);
+ PrintBasePath(WhichVFPtr.PathToIntroducingObject, Out);
Out << "'";
MostDerivedClass->printQualifiedName(Out);
Out << "' (" << Components.size()
// 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.
}
// 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<FullPathTy> &Paths) {
- if (BaseSubobject(RD, Offset) == BaseWithVPtr) {
+ if (BaseSubobject(RD, Offset) == IntroducingObject) {
Paths.push_back(FullPath);
return;
}
: Offset + Layout.getBaseClassOffset(Base);
FullPath.insert(BaseSubobject(Base, NewOffset));
findPathsToSubobject(Context, MostDerivedLayout, Base, NewOffset,
- BaseWithVPtr, FullPath, Paths);
+ IntroducingObject, FullPath, Paths);
FullPath.pop_back();
}
}
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 =
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();
}
}
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())
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())
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);
}
}
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);
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?");
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<llvm::Constant *, 4> Offsets(1 + ReusingBase->getNumVBases(),
+ SmallVector<llvm::Constant *, 4> 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());
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());
}