[PATCH] Append CXXDefaultInitExpr's wrapped expression to the CFG when visiting a constructor initializer

Enrico Pertoso epertoso at google.com
Thu Jan 30 09:48:09 PST 2014


  OK, this just became simpler.

Hi rsmith, jordan_rose,

http://llvm-reviews.chandlerc.com/D2370

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D2370?vs=6085&id=6777#toc

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

Index: include/clang/Analysis/CFG.h
===================================================================
--- include/clang/Analysis/CFG.h
+++ include/clang/Analysis/CFG.h
@@ -667,6 +667,7 @@
     bool AddTemporaryDtors;
     bool AddStaticInitBranches;
     bool AddCXXNewAllocator;
+    bool AddCXXDefaultInitExprInCtors;
 
     bool alwaysAdd(const Stmt *stmt) const {
       return alwaysAddMask[stmt->getStmtClass()];
@@ -689,7 +690,8 @@
       ,AddImplicitDtors(false)
       ,AddTemporaryDtors(false)
       ,AddStaticInitBranches(false)
-      ,AddCXXNewAllocator(false) {}
+      ,AddCXXNewAllocator(false)
+      ,AddCXXDefaultInitExprInCtors(false) {}
   };
 
   /// \brief Provides a custom implementation of the iterator class to have the
Index: lib/Analysis/CFG.cpp
===================================================================
--- lib/Analysis/CFG.cpp
+++ lib/Analysis/CFG.cpp
@@ -770,6 +770,19 @@
       // generating destructors for the second time.
       return Visit(cast<ExprWithCleanups>(Init)->getSubExpr());
     }
+    CXXDefaultInitExpr *Default;
+    if (BuildOpts.AddCXXDefaultInitExprInCtors &&
+        (Default = dyn_cast<CXXDefaultInitExpr>(Init))) {
+      // In general, appending the expression wrapped by a CXXDefaultInitExpr
+      // may cause the same Expr to appear more than once in the CFG. Doing it
+      // here is safe because there's only one initializer per field.
+      autoCreateBlock();
+      appendStmt(Block, Default);
+      if (Stmt *Child = Default->getExpr())
+        if (CFGBlock *R = Visit(Child))
+          Block = R;
+      return Block;
+    }
     return Visit(Init);
   }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2370.4.patch
Type: text/x-patch
Size: 1646 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140130/f67a7753/attachment.bin>


More information about the cfe-commits mailing list