r238913 - Append CXXDefaultInitExpr's wrapped expression to the CFG when visiting a constructor initializer
Enrico Pertoso
epertoso at google.com
Wed Jun 3 03:12:40 PDT 2015
Author: epertoso
Date: Wed Jun 3 05:12:40 2015
New Revision: 238913
URL: http://llvm.org/viewvc/llvm-project?rev=238913&view=rev
Log:
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
Modified:
cfe/trunk/include/clang/Analysis/CFG.h
cfe/trunk/lib/Analysis/CFG.cpp
cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
Modified: cfe/trunk/include/clang/Analysis/CFG.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/CFG.h?rev=238913&r1=238912&r2=238913&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/CFG.h (original)
+++ cfe/trunk/include/clang/Analysis/CFG.h Wed Jun 3 05:12:40 2015
@@ -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
Modified: cfe/trunk/lib/Analysis/CFG.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=238913&r1=238912&r2=238913&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CFG.cpp (original)
+++ cfe/trunk/lib/Analysis/CFG.cpp Wed Jun 3 05:12:40 2015
@@ -1095,6 +1095,19 @@ CFGBlock *CFGBuilder::addInitializer(CXX
// generating destructors for the second time.
return Visit(cast<ExprWithCleanups>(Init)->getSubExpr());
}
+ if (BuildOpts.AddCXXDefaultInitExprInCtors) {
+ if (CXXDefaultInitExpr *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);
}
Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=238913&r1=238912&r2=238913&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original)
+++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Wed Jun 3 05:12:40 2015
@@ -1886,6 +1886,7 @@ AnalysisBasedWarnings::IssueWarnings(sem
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.
More information about the cfe-commits
mailing list