[PATCH] D39220: [Analyzer] Store BodyFarm in std::unique_ptr

George Karpenkov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 23 18:31:25 PDT 2017


george.karpenkov created this revision.
Herald added subscribers: szepet, kristof.beyls, xazax.hun, aemerson.

While by using `.get()` method we don't get the full protection offered by `std::unique_ptr`, given that two bugs were already encountered (http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/9065 and omitted nullptr assignment), using `std::unique_ptr` seems strictly better than raw pointer for all practical purposes.


https://reviews.llvm.org/D39220

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


Index: lib/Analysis/AnalysisDeclContext.cpp
===================================================================
--- lib/Analysis/AnalysisDeclContext.cpp
+++ lib/Analysis/AnalysisDeclContext.cpp
@@ -306,8 +306,8 @@
 
 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,10 +603,7 @@
   }
 }
 
-AnalysisDeclContextManager::~AnalysisDeclContextManager() {
-  if (BdyFrm)
-    delete BdyFrm;
-}
+AnalysisDeclContextManager::~AnalysisDeclContextManager() {}
 
 LocationContext::~LocationContext() {}
 
Index: include/clang/Analysis/AnalysisDeclContext.h
===================================================================
--- include/clang/Analysis/AnalysisDeclContext.h
+++ include/clang/Analysis/AnalysisDeclContext.h
@@ -421,7 +421,7 @@
 
   /// 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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39220.119989.patch
Type: text/x-patch
Size: 1243 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171024/8c6c7744/attachment.bin>


More information about the cfe-commits mailing list