From c4e9e7b35a2d113c8aa3bcdaf858c5bac4d78b03 Mon Sep 17 00:00:00 2001
From: Justin Lebar <jlebar@google.com>
Date: Mon, 10 Oct 2016 16:26:36 +0000
Subject: [PATCH] Use unique_ptr for VTableBuilder::VBaseInfo map.

Reviewers: timshen

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D25424

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@283772 91177308-0d34-0410-b5e6-96231b3b80d8
---
 include/clang/AST/VTableBuilder.h |  5 +++--
 lib/AST/VTableBuilder.cpp         | 29 ++++++++++++++---------------
 2 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/include/clang/AST/VTableBuilder.h b/include/clang/AST/VTableBuilder.h
index 705326fc612..8f0feeda137 100644
--- a/include/clang/AST/VTableBuilder.h
+++ b/include/clang/AST/VTableBuilder.h
@@ -484,7 +484,8 @@ private:
       VFTableLayoutMapTy;
   VFTableLayoutMapTy VFTableLayouts;
 
-  llvm::DenseMap<const CXXRecordDecl *, VirtualBaseInfo *> VBaseInfo;
+  llvm::DenseMap<const CXXRecordDecl *, std::unique_ptr<VirtualBaseInfo>>
+      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/lib/AST/VTableBuilder.cpp b/lib/AST/VTableBuilder.cpp
index 9655445bad1..e4d51ee1ef8 100644
--- a/lib/AST/VTableBuilder.cpp
+++ b/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<BaseSubobject, std::vector<BaseSubobject>,
@@ -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<VirtualBaseInfo> &Entry = VBaseInfo[RD];
     if (Entry)
-      return Entry;
-    Entry = VBI = new VirtualBaseInfo();
+      return *Entry;
+    Entry = llvm::make_unique<VirtualBaseInfo>();
+    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 &
-- 
GitLab