]> granicus.if.org Git - clang/commitdiff
unique_ptrify the result of CFG::buildCFG/CFGBuilder::buildCFG
authorDavid Blaikie <dblaikie@gmail.com>
Fri, 29 Aug 2014 18:53:26 +0000 (18:53 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Fri, 29 Aug 2014 18:53:26 +0000 (18:53 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@216755 91177308-0d34-0410-b5e6-96231b3b80d8

docs/InternalsManual.rst
include/clang/Analysis/CFG.h
lib/Analysis/AnalysisDeclContext.cpp
lib/Analysis/CFG.cpp

index 8e047dbdae7add5968f6f03eeb7d7d0449857842..50a1943ee28b91777c5e1ec72ad2a515ba3bdd9c 100644 (file)
@@ -1396,10 +1396,7 @@ body by single call to a static class method:
 .. code-block:: c++
 
   Stmt *FooBody = ...
-  CFG *FooCFG = CFG::buildCFG(FooBody);
-
-It is the responsibility of the caller of ``CFG::buildCFG`` to ``delete`` the
-returned ``CFG*`` when the CFG is no longer needed.
+  std::unique_ptr<CFG> FooCFG = CFG::buildCFG(FooBody);
 
 Along with providing an interface to iterate over its ``CFGBlocks``, the
 ``CFG`` class also provides methods that are useful for debugging and
index 5987fffb79c16b83750671e33876374637118b44..beea867228d65c18adc8e76d1facef748b078792 100644 (file)
@@ -811,10 +811,9 @@ public:
     ImplTy I;
   };
 
-  /// buildCFG - Builds a CFG from an AST.  The responsibility to free the
-  ///   constructed CFG belongs to the caller.
-  static CFG* buildCFG(const Decl *D, Stmt *AST, ASTContext *C,
-                       const BuildOptions &BO);
+  /// buildCFG - Builds a CFG from an AST.
+  static std::unique_ptr<CFG> buildCFG(const Decl *D, Stmt *AST, ASTContext *C,
+                                       const BuildOptions &BO);
 
   /// createBlock - Create a new block in the CFG.  The CFG owns the block;
   ///  the caller should not directly free it.
index 5733236f91b07f3ad32381b976a4c1e744b75d08..dd154f457a677effdd8f6e1858409f0d6d5362d2 100644 (file)
@@ -189,8 +189,7 @@ CFG *AnalysisDeclContext::getCFG() {
     return getUnoptimizedCFG();
 
   if (!builtCFG) {
-    cfg.reset(CFG::buildCFG(D, getBody(),
-                            &D->getASTContext(), cfgBuildOptions));
+    cfg = CFG::buildCFG(D, getBody(), &D->getASTContext(), cfgBuildOptions);
     // Even when the cfg is not successfully built, we don't
     // want to try building it again.
     builtCFG = true;
@@ -208,8 +207,8 @@ CFG *AnalysisDeclContext::getUnoptimizedCFG() {
   if (!builtCompleteCFG) {
     SaveAndRestore<bool> NotPrune(cfgBuildOptions.PruneTriviallyFalseEdges,
                                   false);
-    completeCFG.reset(CFG::buildCFG(D, getBody(), &D->getASTContext(),
-                                    cfgBuildOptions));
+    completeCFG =
+        CFG::buildCFG(D, getBody(), &D->getASTContext(), cfgBuildOptions);
     // Even when the cfg is not successfully built, we don't
     // want to try building it again.
     builtCompleteCFG = true;
index 4a0d4e8e467b9f6280793c5b9d92bc9c83d08de4..d9073aa63b167a945c3d93cb634a4598c325a56b 100644 (file)
@@ -349,7 +349,7 @@ public:
       cachedEntry(nullptr), lastLookup(nullptr) {}
 
   // buildCFG - Used by external clients to construct the CFG.
-  CFG* buildCFG(const Decl *D, Stmt *Statement);
+  std::unique_ptr<CFG> buildCFG(const Decl *D, Stmt *Statement);
 
   bool alwaysAdd(const Stmt *stmt);
   
@@ -971,7 +971,7 @@ static const VariableArrayType *FindVA(const Type *t) {
 ///  body (compound statement).  The ownership of the returned CFG is
 ///  transferred to the caller.  If CFG construction fails, this method returns
 ///  NULL.
-CFG* CFGBuilder::buildCFG(const Decl *D, Stmt *Statement) {
+std::unique_ptr<CFG> CFGBuilder::buildCFG(const Decl *D, Stmt *Statement) {
   assert(cfg.get());
   if (!Statement)
     return nullptr;
@@ -1043,7 +1043,7 @@ CFG* CFGBuilder::buildCFG(const Decl *D, Stmt *Statement) {
   // Create an empty entry block that has no predecessors.
   cfg->setEntry(createBlock());
 
-  return cfg.release();
+  return std::move(cfg);
 }
 
 /// createBlock - Used to lazily create blocks that are connected
@@ -3775,10 +3775,9 @@ CFGBlock *CFG::createBlock() {
   return &back();
 }
 
-/// buildCFG - Constructs a CFG from an AST.  Ownership of the returned
-///  CFG is returned to the caller.
-CFG* CFG::buildCFG(const Decl *D, Stmt *Statement, ASTContext *C,
-    const BuildOptions &BO) {
+/// buildCFG - Constructs a CFG from an AST.
+std::unique_ptr<CFG> CFG::buildCFG(const Decl *D, Stmt *Statement,
+                                   ASTContext *C, const BuildOptions &BO) {
   CFGBuilder Builder(C, BO);
   return Builder.buildCFG(D, Statement);
 }