From: Justin Lebar Date: Mon, 10 Oct 2016 16:26:36 +0000 (+0000) Subject: Use unique_ptr for VTableBuilder::VBaseInfo map. X-Git-Tag: llvmorg-4.0.0-rc1~7615 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=03b062019277fd3ac63a6e2e6ebcc1be3dd620b9;p=platform%2Fupstream%2Fllvm.git Use unique_ptr for VTableBuilder::VBaseInfo map. Reviewers: timshen Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D25424 llvm-svn: 283772 --- diff --git a/clang/include/clang/AST/VTableBuilder.h b/clang/include/clang/AST/VTableBuilder.h index 705326f..8f0feed 100644 --- a/clang/include/clang/AST/VTableBuilder.h +++ b/clang/include/clang/AST/VTableBuilder.h @@ -484,7 +484,8 @@ private: VFTableLayoutMapTy; VFTableLayoutMapTy VFTableLayouts; - llvm::DenseMap VBaseInfo; + llvm::DenseMap> + VBaseInfo; void enumerateVFPtrs(const CXXRecordDecl *ForClass, VPtrInfoVector &Result); @@ -494,7 +495,7 @@ private: const MethodVFTableLocationsTy &NewMethods, raw_ostream &); - const VirtualBaseInfo * + const VirtualBaseInfo & computeVBTableRelatedInformation(const CXXRecordDecl *RD); void computeVTablePaths(bool ForVBTables, const CXXRecordDecl *RD, diff --git a/clang/lib/AST/VTableBuilder.cpp b/clang/lib/AST/VTableBuilder.cpp index 9655445..e4d51ee 100644 --- a/clang/lib/AST/VTableBuilder.cpp +++ b/clang/lib/AST/VTableBuilder.cpp @@ -3388,9 +3388,7 @@ static bool rebucketPaths(VPtrInfoVector &Paths) { return Changed; } -MicrosoftVTableContext::~MicrosoftVTableContext() { - llvm::DeleteContainerSeconds(VBaseInfo); -} +MicrosoftVTableContext::~MicrosoftVTableContext() {} namespace { typedef llvm::SetVector, @@ -3670,17 +3668,18 @@ void MicrosoftVTableContext::dumpMethodLocations( Out.flush(); } -const VirtualBaseInfo *MicrosoftVTableContext::computeVBTableRelatedInformation( +const VirtualBaseInfo &MicrosoftVTableContext::computeVBTableRelatedInformation( const CXXRecordDecl *RD) { VirtualBaseInfo *VBI; { // Get or create a VBI for RD. Don't hold a reference to the DenseMap cell, // as it may be modified and rehashed under us. - VirtualBaseInfo *&Entry = VBaseInfo[RD]; + std::unique_ptr &Entry = VBaseInfo[RD]; if (Entry) - return Entry; - Entry = VBI = new VirtualBaseInfo(); + return *Entry; + Entry = llvm::make_unique(); + VBI = Entry.get(); } computeVTablePaths(/*ForVBTables=*/true, RD, VBI->VBPtrPaths); @@ -3690,10 +3689,10 @@ const VirtualBaseInfo *MicrosoftVTableContext::computeVBTableRelatedInformation( if (const CXXRecordDecl *VBPtrBase = Layout.getBaseSharingVBPtr()) { // If the Derived class shares the vbptr with a non-virtual base, the shared // virtual bases come first so that the layout is the same. - const VirtualBaseInfo *BaseInfo = + const VirtualBaseInfo &BaseInfo = computeVBTableRelatedInformation(VBPtrBase); - VBI->VBTableIndices.insert(BaseInfo->VBTableIndices.begin(), - BaseInfo->VBTableIndices.end()); + VBI->VBTableIndices.insert(BaseInfo.VBTableIndices.begin(), + BaseInfo.VBTableIndices.end()); } // New vbases are added to the end of the vbtable. @@ -3705,19 +3704,19 @@ const VirtualBaseInfo *MicrosoftVTableContext::computeVBTableRelatedInformation( VBI->VBTableIndices[CurVBase] = VBTableIndex++; } - return VBI; + return *VBI; } unsigned MicrosoftVTableContext::getVBTableIndex(const CXXRecordDecl *Derived, const CXXRecordDecl *VBase) { - const VirtualBaseInfo *VBInfo = computeVBTableRelatedInformation(Derived); - assert(VBInfo->VBTableIndices.count(VBase)); - return VBInfo->VBTableIndices.find(VBase)->second; + const VirtualBaseInfo &VBInfo = computeVBTableRelatedInformation(Derived); + assert(VBInfo.VBTableIndices.count(VBase)); + return VBInfo.VBTableIndices.find(VBase)->second; } const VPtrInfoVector & MicrosoftVTableContext::enumerateVBTables(const CXXRecordDecl *RD) { - return computeVBTableRelatedInformation(RD)->VBPtrPaths; + return computeVBTableRelatedInformation(RD).VBPtrPaths; } const VPtrInfoVector &