[Analyzer] Store BodyFarm in std::unique_ptr
authorGeorge Karpenkov <ekarpenkov@apple.com>
Tue, 24 Oct 2017 23:53:19 +0000 (23:53 +0000)
committerGeorge Karpenkov <ekarpenkov@apple.com>
Tue, 24 Oct 2017 23:53:19 +0000 (23:53 +0000)
Differential Revision: https://reviews.llvm.org/D39220

llvm-svn: 316536

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

index 1486071..c976281 100644 (file)
@@ -421,7 +421,7 @@ class AnalysisDeclContextManager {
 
   /// Pointer to a factory for creating and caching implementations for common
   /// methods during the analysis.
-  BodyFarm *BdyFrm = nullptr;
+  std::unique_ptr<BodyFarm> BdyFrm;
 
   /// Flag to indicate whether or not bodies should be synthesized
   /// for well-known functions.
@@ -438,8 +438,6 @@ public:
                              bool addCXXNewAllocator = true,
                              CodeInjector *injector = nullptr);
 
-  ~AnalysisDeclContextManager();
-
   AnalysisDeclContext *getContext(const Decl *D);
 
   bool getUseUnoptimizedCFG() const {
index 4408a0e..17749db 100644 (file)
@@ -306,8 +306,8 @@ AnalysisDeclContext *AnalysisDeclContextManager::getContext(const Decl *D) {
 
 BodyFarm *AnalysisDeclContextManager::getBodyFarm() {
   if (!BdyFrm)
-    BdyFrm = new BodyFarm(ASTCtx, Injector.get());
-  return BdyFrm;
+    BdyFrm = llvm::make_unique<BodyFarm>(ASTCtx, Injector.get());
+  return BdyFrm.get();
 }
 
 const StackFrameContext *
@@ -603,11 +603,6 @@ AnalysisDeclContext::~AnalysisDeclContext() {
   }
 }
 
-AnalysisDeclContextManager::~AnalysisDeclContextManager() {
-  if (BdyFrm)
-    delete BdyFrm;
-}
-
 LocationContext::~LocationContext() {}
 
 LocationContextManager::~LocationContextManager() {