From: Enrico Pertoso Date: Wed, 3 Jun 2015 10:12:40 +0000 (+0000) Subject: Append CXXDefaultInitExpr's wrapped expression to the CFG when visiting a constructor... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=500d43f72aeea3974472ced6bd8d02c66f294dd8;p=clang Append CXXDefaultInitExpr's wrapped expression to the CFG when visiting a constructor initializer Summary: This patch is part of http://llvm-reviews.chandlerc.com/D2181. In-class initializers are appended to the CFG when CFGBuilder::addInitializer is called. Reviewers: jordan_rose, rsmith Reviewed By: jordan_rose Subscribers: cfe-commits, klimek Differential Revision: http://reviews.llvm.org/D2370 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@238913 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Analysis/CFG.h b/include/clang/Analysis/CFG.h index e7f6383626..5430c3bc6f 100644 --- a/include/clang/Analysis/CFG.h +++ b/include/clang/Analysis/CFG.h @@ -738,6 +738,7 @@ public: bool AddTemporaryDtors; bool AddStaticInitBranches; bool AddCXXNewAllocator; + bool AddCXXDefaultInitExprInCtors; bool alwaysAdd(const Stmt *stmt) const { return alwaysAddMask[stmt->getStmtClass()]; @@ -758,7 +759,7 @@ public: PruneTriviallyFalseEdges(true), AddEHEdges(false), AddInitializers(false), AddImplicitDtors(false), AddTemporaryDtors(false), AddStaticInitBranches(false), - AddCXXNewAllocator(false) {} + AddCXXNewAllocator(false), AddCXXDefaultInitExprInCtors(false) {} }; /// \brief Provides a custom implementation of the iterator class to have the diff --git a/lib/Analysis/CFG.cpp b/lib/Analysis/CFG.cpp index 6f624ee406..b2fdd27879 100644 --- a/lib/Analysis/CFG.cpp +++ b/lib/Analysis/CFG.cpp @@ -1095,6 +1095,19 @@ CFGBlock *CFGBuilder::addInitializer(CXXCtorInitializer *I) { // generating destructors for the second time. return Visit(cast(Init)->getSubExpr()); } + if (BuildOpts.AddCXXDefaultInitExprInCtors) { + if (CXXDefaultInitExpr *Default = dyn_cast(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); } diff --git a/lib/Sema/AnalysisBasedWarnings.cpp b/lib/Sema/AnalysisBasedWarnings.cpp index 98ffae9223..97f4a8def8 100644 --- a/lib/Sema/AnalysisBasedWarnings.cpp +++ b/lib/Sema/AnalysisBasedWarnings.cpp @@ -1886,6 +1886,7 @@ AnalysisBasedWarnings::IssueWarnings(sema::AnalysisBasedWarnings::Policy P, AC.getCFGBuildOptions().AddImplicitDtors = true; AC.getCFGBuildOptions().AddTemporaryDtors = true; AC.getCFGBuildOptions().AddCXXNewAllocator = false; + AC.getCFGBuildOptions().AddCXXDefaultInitExprInCtors = true; // Force that certain expressions appear as CFGElements in the CFG. This // is used to speed up various analyses.