r283770 - Use unique_ptr for VPtrLocationsMap and VPtrInfoVector.
Justin Lebar via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 10 09:26:29 PDT 2016
Author: jlebar
Date: Mon Oct 10 11:26:29 2016
New Revision: 283770
URL: http://llvm.org/viewvc/llvm-project?rev=283770&view=rev
Log:
Use unique_ptr for VPtrLocationsMap and VPtrInfoVector.
Reviewers: timshen
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D25422
Modified:
cfe/trunk/include/clang/AST/VTableBuilder.h
cfe/trunk/lib/AST/VTableBuilder.cpp
cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
Modified: cfe/trunk/include/clang/AST/VTableBuilder.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/VTableBuilder.h?rev=283770&r1=283769&r2=283770&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/VTableBuilder.h (original)
+++ cfe/trunk/include/clang/AST/VTableBuilder.h Mon Oct 10 11:26:29 2016
@@ -417,14 +417,12 @@ struct VPtrInfo {
}
};
-typedef SmallVector<VPtrInfo *, 2> VPtrInfoVector;
+typedef SmallVector<std::unique_ptr<VPtrInfo>, 2> VPtrInfoVector;
/// All virtual base related information about a given record decl. Includes
/// information on all virtual base tables and the path components that are used
/// to mangle them.
struct VirtualBaseInfo {
- ~VirtualBaseInfo() { llvm::DeleteContainerPointers(VBPtrPaths); }
-
/// A map from virtual base to vbtable index for doing a conversion from the
/// the derived class to the a base.
llvm::DenseMap<const CXXRecordDecl *, unsigned> VBTableIndices;
@@ -477,8 +475,8 @@ private:
MethodVFTableLocationsTy;
MethodVFTableLocationsTy MethodVFTableLocations;
- typedef llvm::DenseMap<const CXXRecordDecl *, VPtrInfoVector *>
- VFPtrLocationsMapTy;
+ typedef llvm::DenseMap<const CXXRecordDecl *, VPtrInfoVector>
+ VFPtrLocationsMapTy;
VFPtrLocationsMapTy VFPtrLocations;
typedef std::pair<const CXXRecordDecl *, CharUnits> VFTableIdTy;
Modified: cfe/trunk/lib/AST/VTableBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/VTableBuilder.cpp?rev=283770&r1=283769&r2=283770&view=diff
==============================================================================
--- cfe/trunk/lib/AST/VTableBuilder.cpp (original)
+++ cfe/trunk/lib/AST/VTableBuilder.cpp Mon Oct 10 11:26:29 2016
@@ -2536,12 +2536,12 @@ private:
public:
VFTableBuilder(MicrosoftVTableContext &VTables,
- const CXXRecordDecl *MostDerivedClass, const VPtrInfo *Which)
+ const CXXRecordDecl *MostDerivedClass, const VPtrInfo &Which)
: VTables(VTables),
Context(MostDerivedClass->getASTContext()),
MostDerivedClass(MostDerivedClass),
MostDerivedClassLayout(Context.getASTRecordLayout(MostDerivedClass)),
- WhichVFPtr(*Which),
+ WhichVFPtr(Which),
Overriders(MostDerivedClass, CharUnits(), MostDerivedClass) {
// Provide the RTTI component if RTTIData is enabled. If the vftable would
// be available externally, we should not provide the RTTI componenent. It
@@ -3276,7 +3276,7 @@ void MicrosoftVTableContext::computeVTab
// Base case: this subobject has its own vptr.
if (ForVBTables ? Layout.hasOwnVBPtr() : Layout.hasOwnVFPtr())
- Paths.push_back(new VPtrInfo(RD));
+ Paths.push_back(llvm::make_unique<VPtrInfo>(RD));
// Recursive case: get all the vbtables from our bases and remove anything
// that shares a virtual base.
@@ -3292,14 +3292,14 @@ void MicrosoftVTableContext::computeVTab
const VPtrInfoVector &BasePaths =
ForVBTables ? enumerateVBTables(Base) : getVFPtrOffsets(Base);
- for (VPtrInfo *BaseInfo : BasePaths) {
+ for (const std::unique_ptr<VPtrInfo> &BaseInfo : BasePaths) {
// Don't include the path if it goes through a virtual base that we've
// already included.
if (setsIntersect(VBasesSeen, BaseInfo->ContainingVBases))
continue;
// Copy the path and adjust it as necessary.
- VPtrInfo *P = new VPtrInfo(*BaseInfo);
+ auto P = llvm::make_unique<VPtrInfo>(*BaseInfo);
// We mangle Base into the path if the path would've been ambiguous and it
// wasn't already extended with Base.
@@ -3326,7 +3326,7 @@ void MicrosoftVTableContext::computeVTab
if (const CXXRecordDecl *VB = P->getVBaseWithVPtr())
P->FullOffsetInMDC += Layout.getVBaseClassOffset(VB);
- Paths.push_back(P);
+ Paths.push_back(std::move(P));
}
if (B.isVirtual())
@@ -3345,10 +3345,10 @@ void MicrosoftVTableContext::computeVTab
Changed = rebucketPaths(Paths);
}
-static bool extendPath(VPtrInfo *P) {
- if (P->NextBaseToMangle) {
- P->MangledPath.push_back(P->NextBaseToMangle);
- P->NextBaseToMangle = nullptr;// Prevent the path from being extended twice.
+static bool extendPath(VPtrInfo &P) {
+ if (P.NextBaseToMangle) {
+ P.MangledPath.push_back(P.NextBaseToMangle);
+ P.NextBaseToMangle = nullptr;// Prevent the path from being extended twice.
return true;
}
return false;
@@ -3361,10 +3361,12 @@ static bool rebucketPaths(VPtrInfoVector
// sorted vector to implement a multiset to form the buckets. Note that the
// ordering is based on pointers, but it doesn't change our output order. The
// current algorithm is designed to match MSVC 2012's names.
- VPtrInfoVector PathsSorted(Paths);
+ llvm::SmallVector<std::reference_wrapper<VPtrInfo>, 2> PathsSorted(
+ llvm::make_pointee_iterator(Paths.begin()),
+ llvm::make_pointee_iterator(Paths.end()));
std::sort(PathsSorted.begin(), PathsSorted.end(),
- [](const VPtrInfo *LHS, const VPtrInfo *RHS) {
- return LHS->MangledPath < RHS->MangledPath;
+ [](const VPtrInfo &LHS, const VPtrInfo &RHS) {
+ return LHS.MangledPath < RHS.MangledPath;
});
bool Changed = false;
for (size_t I = 0, E = PathsSorted.size(); I != E;) {
@@ -3372,8 +3374,9 @@ static bool rebucketPaths(VPtrInfoVector
size_t BucketStart = I;
do {
++I;
- } while (I != E && PathsSorted[BucketStart]->MangledPath ==
- PathsSorted[I]->MangledPath);
+ } while (I != E &&
+ PathsSorted[BucketStart].get().MangledPath ==
+ PathsSorted[I].get().MangledPath);
// If this bucket has multiple paths, extend them all.
if (I - BucketStart > 1) {
@@ -3386,9 +3389,6 @@ static bool rebucketPaths(VPtrInfoVector
}
MicrosoftVTableContext::~MicrosoftVTableContext() {
- for (auto &P : VFPtrLocations)
- llvm::DeleteContainerPointers(*P.second);
- llvm::DeleteContainerSeconds(VFPtrLocations);
llvm::DeleteContainerSeconds(VFTableLayouts);
llvm::DeleteContainerSeconds(VBaseInfo);
}
@@ -3475,7 +3475,8 @@ static CharUnits getOffsetOfFullPath(AST
// two paths introduce overrides which the other path doesn't contain, issue a
// diagnostic.
static const FullPathTy *selectBestPath(ASTContext &Context,
- const CXXRecordDecl *RD, VPtrInfo *Info,
+ const CXXRecordDecl *RD,
+ const VPtrInfo &Info,
std::list<FullPathTy> &FullPaths) {
// Handle some easy cases first.
if (FullPaths.empty())
@@ -3495,7 +3496,7 @@ static const FullPathTy *selectBestPath(
CharUnits BaseOffset =
getOffsetOfFullPath(Context, TopLevelRD, SpecificPath);
FinalOverriders Overriders(TopLevelRD, CharUnits::Zero(), TopLevelRD);
- for (const CXXMethodDecl *MD : Info->IntroducingObject->methods()) {
+ for (const CXXMethodDecl *MD : Info.IntroducingObject->methods()) {
if (!MD->isVirtual())
continue;
FinalOverriders::OverriderInfo OI =
@@ -3550,7 +3551,7 @@ static void computeFullPathsForVFTables(
const ASTRecordLayout &MostDerivedLayout = Context.getASTRecordLayout(RD);
FullPathTy FullPath;
std::list<FullPathTy> FullPaths;
- for (VPtrInfo *Info : Paths) {
+ for (const std::unique_ptr<VPtrInfo>& Info : Paths) {
findPathsToSubobject(
Context, MostDerivedLayout, RD, CharUnits::Zero(),
BaseSubobject(Info->IntroducingObject, Info->FullOffsetInMDC), FullPath,
@@ -3559,7 +3560,7 @@ static void computeFullPathsForVFTables(
removeRedundantPaths(FullPaths);
Info->PathToIntroducingObject.clear();
if (const FullPathTy *BestPath =
- selectBestPath(Context, RD, Info, FullPaths))
+ selectBestPath(Context, RD, *Info, FullPaths))
for (const BaseSubobject &BSO : *BestPath)
Info->PathToIntroducingObject.push_back(BSO.getBase());
FullPaths.clear();
@@ -3576,14 +3577,16 @@ void MicrosoftVTableContext::computeVTab
const VTableLayout::AddressPointsMapTy EmptyAddressPointsMap;
- VPtrInfoVector *VFPtrs = new VPtrInfoVector();
- computeVTablePaths(/*ForVBTables=*/false, RD, *VFPtrs);
- computeFullPathsForVFTables(Context, RD, *VFPtrs);
- VFPtrLocations[RD] = VFPtrs;
+ {
+ VPtrInfoVector VFPtrs;
+ computeVTablePaths(/*ForVBTables=*/false, RD, VFPtrs);
+ computeFullPathsForVFTables(Context, RD, VFPtrs);
+ VFPtrLocations[RD] = std::move(VFPtrs);
+ }
MethodVFTableLocationsTy NewMethodLocations;
- for (const VPtrInfo *VFPtr : *VFPtrs) {
- VFTableBuilder Builder(*this, RD, VFPtr);
+ for (const std::unique_ptr<VPtrInfo> &VFPtr : VFPtrLocations[RD]) {
+ VFTableBuilder Builder(*this, RD, *VFPtr);
VFTableIdTy id(RD, VFPtr->FullOffsetInMDC);
assert(VFTableLayouts.count(id) == 0);
@@ -3723,7 +3726,7 @@ MicrosoftVTableContext::getVFPtrOffsets(
computeVTableRelatedInformation(RD);
assert(VFPtrLocations.count(RD) && "Couldn't find vfptr locations");
- return *VFPtrLocations[RD];
+ return VFPtrLocations[RD];
}
const VTableLayout &
Modified: cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp?rev=283770&r1=283769&r2=283770&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp Mon Oct 10 11:26:29 2016
@@ -96,7 +96,7 @@ public:
const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD);
const VBTableGlobals &VBGlobals = enumerateVBTables(RD);
- for (const VPtrInfo *VBT : *VBGlobals.VBTables) {
+ for (const std::unique_ptr<VPtrInfo> &VBT : *VBGlobals.VBTables) {
const ASTRecordLayout &SubobjectLayout =
Context.getASTRecordLayout(VBT->IntroducingObject);
CharUnits Offs = VBT->NonVirtualOffset;
@@ -122,7 +122,7 @@ public:
void emitBeginCatch(CodeGenFunction &CGF, const CXXCatchStmt *C) override;
llvm::GlobalVariable *getMSCompleteObjectLocator(const CXXRecordDecl *RD,
- const VPtrInfo *Info);
+ const VPtrInfo &Info);
llvm::Constant *getAddrOfRTTIDescriptor(QualType Ty) override;
CatchTypeInfo
@@ -254,7 +254,7 @@ public:
CXXDtorType Type, bool ForVirtualBase,
bool Delegating, Address This) override;
- void emitVTableTypeMetadata(VPtrInfo *Info, const CXXRecordDecl *RD,
+ void emitVTableTypeMetadata(const VPtrInfo &Info, const CXXRecordDecl *RD,
llvm::GlobalVariable *VTable);
void emitVTableDefinitions(CodeGenVTables &CGVT,
@@ -1214,7 +1214,7 @@ void MicrosoftCXXABI::EmitVBPtrStores(Co
const VBTableGlobals &VBGlobals = enumerateVBTables(RD);
for (unsigned I = 0, E = VBGlobals.VBTables->size(); I != E; ++I) {
- const VPtrInfo *VBT = (*VBGlobals.VBTables)[I];
+ const std::unique_ptr<VPtrInfo> &VBT = (*VBGlobals.VBTables)[I];
llvm::GlobalVariable *GV = VBGlobals.Globals[I];
const ASTRecordLayout &SubobjectLayout =
Context.getASTRecordLayout(VBT->IntroducingObject);
@@ -1509,7 +1509,7 @@ void MicrosoftCXXABI::EmitDestructorCall
getFromDtorType(Type));
}
-void MicrosoftCXXABI::emitVTableTypeMetadata(VPtrInfo *Info,
+void MicrosoftCXXABI::emitVTableTypeMetadata(const VPtrInfo &Info,
const CXXRecordDecl *RD,
llvm::GlobalVariable *VTable) {
if (!CGM.getCodeGenOpts().PrepareForLTO)
@@ -1524,20 +1524,20 @@ void MicrosoftCXXABI::emitVTableTypeMeta
getContext().getTargetInfo().getPointerWidth(0))
: CharUnits::Zero();
- if (Info->PathToIntroducingObject.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->PathToIntroducingObject.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->PathToIntroducingObject.size() - 1; I != 0; --I) {
- const CXXRecordDecl *DerivedRD = Info->PathToIntroducingObject[I - 1];
- const CXXRecordDecl *BaseRD = Info->PathToIntroducingObject[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);
@@ -1553,7 +1553,7 @@ void MicrosoftCXXABI::emitVTableTypeMeta
}
// Finally do the same for the most derived class.
- if (Info->FullOffsetInMDC.isZero())
+ if (Info.FullOffsetInMDC.isZero())
CGM.AddVTableTypeMetadata(VTable, AddressPoint, RD);
}
@@ -1562,7 +1562,7 @@ void MicrosoftCXXABI::emitVTableDefiniti
MicrosoftVTableContext &VFTContext = CGM.getMicrosoftVTableContext();
const VPtrInfoVector &VFPtrs = VFTContext.getVFPtrOffsets(RD);
- for (VPtrInfo *Info : VFPtrs) {
+ for (const std::unique_ptr<VPtrInfo>& Info : VFPtrs) {
llvm::GlobalVariable *VTable = getAddrOfVTable(RD, Info->FullOffsetInMDC);
if (VTable->hasInitializer())
continue;
@@ -1573,13 +1573,13 @@ void MicrosoftCXXABI::emitVTableDefiniti
llvm::Constant *RTTI = nullptr;
if (any_of(VTLayout.vtable_components(),
[](const VTableComponent &VTC) { return VTC.isRTTIKind(); }))
- RTTI = getMSCompleteObjectLocator(RD, Info);
+ RTTI = getMSCompleteObjectLocator(RD, *Info);
llvm::Constant *Init = CGVT.CreateVTableInitializer(VTLayout, RTTI);
VTable->setInitializer(Init);
- emitVTableTypeMetadata(Info, RD, VTable);
+ emitVTableTypeMetadata(*Info, RD, VTable);
}
}
@@ -1600,10 +1600,10 @@ llvm::Value *MicrosoftCXXABI::getVTableA
}
static void mangleVFTableName(MicrosoftMangleContext &MangleContext,
- const CXXRecordDecl *RD, const VPtrInfo *VFPtr,
+ const CXXRecordDecl *RD, const VPtrInfo &VFPtr,
SmallString<256> &Name) {
llvm::raw_svector_ostream Out(Name);
- MangleContext.mangleCXXVFTable(RD, VFPtr->MangledPath, Out);
+ MangleContext.mangleCXXVFTable(RD, VFPtr.MangledPath, Out);
}
llvm::Constant *
@@ -1650,25 +1650,25 @@ llvm::GlobalVariable *MicrosoftCXXABI::g
llvm::StringSet<> ObservedMangledNames;
for (size_t J = 0, F = VFPtrs.size(); J != F; ++J) {
SmallString<256> Name;
- mangleVFTableName(getMangleContext(), RD, VFPtrs[J], Name);
+ mangleVFTableName(getMangleContext(), RD, *VFPtrs[J], Name);
if (!ObservedMangledNames.insert(Name.str()).second)
llvm_unreachable("Already saw this mangling before?");
}
#endif
}
- VPtrInfo *const *VFPtrI =
- std::find_if(VFPtrs.begin(), VFPtrs.end(), [&](VPtrInfo *VPI) {
+ const std::unique_ptr<VPtrInfo> *VFPtrI = std::find_if(
+ VFPtrs.begin(), VFPtrs.end(), [&](const std::unique_ptr<VPtrInfo>& VPI) {
return VPI->FullOffsetInMDC == VPtrOffset;
});
if (VFPtrI == VFPtrs.end()) {
VFTablesMap[ID] = nullptr;
return nullptr;
}
- VPtrInfo *VFPtr = *VFPtrI;
+ const std::unique_ptr<VPtrInfo> &VFPtr = *VFPtrI;
SmallString<256> VFTableName;
- mangleVFTableName(getMangleContext(), RD, VFPtr, VFTableName);
+ mangleVFTableName(getMangleContext(), RD, *VFPtr, VFTableName);
// Classes marked __declspec(dllimport) need vftables generated on the
// import-side in order to support features like constexpr. No other
@@ -1964,7 +1964,7 @@ llvm::Function *MicrosoftCXXABI::EmitVir
void MicrosoftCXXABI::emitVirtualInheritanceTables(const CXXRecordDecl *RD) {
const VBTableGlobals &VBGlobals = enumerateVBTables(RD);
for (unsigned I = 0, E = VBGlobals.VBTables->size(); I != E; ++I) {
- const VPtrInfo *VBT = (*VBGlobals.VBTables)[I];
+ const std::unique_ptr<VPtrInfo>& VBT = (*VBGlobals.VBTables)[I];
llvm::GlobalVariable *GV = VBGlobals.Globals[I];
if (GV->isDeclaration())
emitVBTableDefinition(*VBT, RD, GV);
@@ -3426,7 +3426,7 @@ struct MSRTTIBuilder {
llvm::GlobalVariable *
getBaseClassArray(SmallVectorImpl<MSRTTIClass> &Classes);
llvm::GlobalVariable *getClassHierarchyDescriptor();
- llvm::GlobalVariable *getCompleteObjectLocator(const VPtrInfo *Info);
+ llvm::GlobalVariable *getCompleteObjectLocator(const VPtrInfo &Info);
CodeGenModule &CGM;
ASTContext &Context;
@@ -3608,11 +3608,11 @@ MSRTTIBuilder::getBaseClassDescriptor(co
}
llvm::GlobalVariable *
-MSRTTIBuilder::getCompleteObjectLocator(const VPtrInfo *Info) {
+MSRTTIBuilder::getCompleteObjectLocator(const VPtrInfo &Info) {
SmallString<256> MangledName;
{
llvm::raw_svector_ostream Out(MangledName);
- ABI.getMangleContext().mangleCXXRTTICompleteObjectLocator(RD, Info->MangledPath, Out);
+ ABI.getMangleContext().mangleCXXRTTICompleteObjectLocator(RD, Info.MangledPath, Out);
}
// Check to see if we've already computed this complete object locator.
@@ -3620,15 +3620,15 @@ MSRTTIBuilder::getCompleteObjectLocator(
return COL;
// Compute the fields of the complete object locator.
- int OffsetToTop = Info->FullOffsetInMDC.getQuantity();
+ int OffsetToTop = Info.FullOffsetInMDC.getQuantity();
int VFPtrOffset = 0;
// The offset includes the vtordisp if one exists.
- if (const CXXRecordDecl *VBase = Info->getVBaseWithVPtr())
+ if (const CXXRecordDecl *VBase = Info.getVBaseWithVPtr())
if (Context.getASTRecordLayout(RD)
.getVBaseOffsetsMap()
.find(VBase)
->second.hasVtorDisp())
- VFPtrOffset = Info->NonVirtualOffset.getQuantity() + 4;
+ VFPtrOffset = Info.NonVirtualOffset.getQuantity() + 4;
// Forward-declare the complete object locator.
llvm::StructType *Type = ABI.getCompleteObjectLocatorType();
@@ -3756,7 +3756,7 @@ llvm::Constant *MicrosoftCXXABI::getAddr
/// \brief Gets or a creates a Microsoft CompleteObjectLocator.
llvm::GlobalVariable *
MicrosoftCXXABI::getMSCompleteObjectLocator(const CXXRecordDecl *RD,
- const VPtrInfo *Info) {
+ const VPtrInfo &Info) {
return MSRTTIBuilder(*this, RD).getCompleteObjectLocator(Info);
}
More information about the cfe-commits
mailing list