[Analysis] Use unique_ptr in AnalyaisDeclContextManager's ContextMap.
authorJustin Lebar <jlebar@google.com>
Mon, 10 Oct 2016 16:26:44 +0000 (16:26 +0000)
committerJustin Lebar <jlebar@google.com>
Mon, 10 Oct 2016 16:26:44 +0000 (16:26 +0000)
Reviewers: timshen

Subscribers: cfe-commits

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

llvm-svn: 283774

clang/include/clang/Analysis/AnalysisContext.h
clang/lib/Analysis/AnalysisDeclContext.cpp

index 4324a03..f6a47d6 100644 (file)
@@ -406,7 +406,8 @@ private:
 };
 
 class AnalysisDeclContextManager {
-  typedef llvm::DenseMap<const Decl*, AnalysisDeclContext*> ContextMap;
+  typedef llvm::DenseMap<const Decl *, std::unique_ptr<AnalysisDeclContext>>
+      ContextMap;
 
   ContextMap Contexts;
   LocationContextManager LocContexts;
index 6bbe8f8..6b58916 100644 (file)
@@ -81,9 +81,7 @@ AnalysisDeclContextManager::AnalysisDeclContextManager(bool useUnoptimizedCFG,
   cfgBuildOptions.AddCXXNewAllocator = addCXXNewAllocator;
 }
 
-void AnalysisDeclContextManager::clear() {
-  llvm::DeleteContainerSeconds(Contexts);
-}
+void AnalysisDeclContextManager::clear() { Contexts.clear(); }
 
 static BodyFarm &getBodyFarm(ASTContext &C, CodeInjector *injector = nullptr) {
   static BodyFarm *BF = new BodyFarm(C, injector);
@@ -307,10 +305,10 @@ AnalysisDeclContext *AnalysisDeclContextManager::getContext(const Decl *D) {
     D = FD;
   }
 
-  AnalysisDeclContext *&AC = Contexts[D];
+  std::unique_ptr<AnalysisDeclContext> &AC = Contexts[D];
   if (!AC)
-    AC = new AnalysisDeclContext(this, D, cfgBuildOptions);
-  return AC;
+    AC = llvm::make_unique<AnalysisDeclContext>(this, D, cfgBuildOptions);
+  return AC.get();
 }
 
 const StackFrameContext *
@@ -606,9 +604,7 @@ AnalysisDeclContext::~AnalysisDeclContext() {
   }
 }
 
-AnalysisDeclContextManager::~AnalysisDeclContextManager() {
-  llvm::DeleteContainerSeconds(Contexts);
-}
+AnalysisDeclContextManager::~AnalysisDeclContextManager() {}
 
 LocationContext::~LocationContext() {}