[cfe-commits] r113898 - in /cfe/trunk: include/clang/Analysis/CFG.h lib/Analysis/AnalysisContext.cpp lib/Analysis/CFG.cpp
Ted Kremenek
kremenek at apple.com
Tue Sep 14 16:41:16 PDT 2010
Author: kremenek
Date: Tue Sep 14 18:41:16 2010
New Revision: 113898
URL: http://llvm.org/viewvc/llvm-project?rev=113898&view=rev
Log:
Add CFG::BuildOptions class to pass in CFG builder options under on parameter. Patch by Marcin Ĺwiderski!
Modified:
cfe/trunk/include/clang/Analysis/CFG.h
cfe/trunk/lib/Analysis/AnalysisContext.cpp
cfe/trunk/lib/Analysis/CFG.cpp
Modified: cfe/trunk/include/clang/Analysis/CFG.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/CFG.h?rev=113898&r1=113897&r2=113898&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/CFG.h (original)
+++ cfe/trunk/include/clang/Analysis/CFG.h Tue Sep 14 18:41:16 2010
@@ -311,11 +311,24 @@
// CFG Construction & Manipulation.
//===--------------------------------------------------------------------===//
+ class BuildOptions {
+ public:
+ bool PruneTriviallyFalseEdges:1;
+ bool AddEHEdges:1;
+ bool AddInitializers:1;
+ bool AddImplicitDtors:1;
+
+ BuildOptions()
+ : PruneTriviallyFalseEdges(true)
+ , AddEHEdges(false)
+ , AddInitializers(false)
+ , AddImplicitDtors(false) {}
+ };
+
/// 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,
- bool pruneTriviallyFalseEdges = true,
- bool AddEHEdges = false);
+ BuildOptions BO = BuildOptions());
/// createBlock - Create a new block in the CFG. The CFG owns the block;
/// the caller should not directly free it.
Modified: cfe/trunk/lib/Analysis/AnalysisContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/AnalysisContext.cpp?rev=113898&r1=113897&r2=113898&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/AnalysisContext.cpp (original)
+++ cfe/trunk/lib/Analysis/AnalysisContext.cpp Tue Sep 14 18:41:16 2010
@@ -59,7 +59,9 @@
return getUnoptimizedCFG();
if (!builtCFG) {
- cfg = CFG::buildCFG(D, getBody(), &D->getASTContext(), true, AddEHEdges);
+ CFG::BuildOptions B;
+ B.AddEHEdges = AddEHEdges;
+ cfg = CFG::buildCFG(D, getBody(), &D->getASTContext(), B);
// Even when the cfg is not successfully built, we don't
// want to try building it again.
builtCFG = true;
@@ -69,8 +71,10 @@
CFG *AnalysisContext::getUnoptimizedCFG() {
if (!builtCompleteCFG) {
- completeCFG = CFG::buildCFG(D, getBody(), &D->getASTContext(),
- false, AddEHEdges);
+ CFG::BuildOptions B;
+ B.PruneTriviallyFalseEdges = false;
+ B.AddEHEdges = AddEHEdges;
+ completeCFG = CFG::buildCFG(D, getBody(), &D->getASTContext(), B);
// Even when the cfg is not successfully built, we don't
// want to try building it again.
builtCompleteCFG = true;
Modified: cfe/trunk/lib/Analysis/CFG.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=113898&r1=113897&r2=113898&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CFG.cpp (original)
+++ cfe/trunk/lib/Analysis/CFG.cpp Tue Sep 14 18:41:16 2010
@@ -100,7 +100,7 @@
// buildCFG - Used by external clients to construct the CFG.
CFG* buildCFG(const Decl *D, Stmt *Statement, ASTContext *C,
- bool pruneTriviallyFalseEdges, bool AddEHEdges);
+ CFG::BuildOptions BO);
private:
// Visitors to walk an AST and construct the CFG.
@@ -187,7 +187,7 @@
/// TryEvaluateBool - Try and evaluate the Stmt and return 0 or 1
/// if we can evaluate to a known value, otherwise return -1.
TryResult TryEvaluateBool(Expr *S) {
- if (!PruneTriviallyFalseEdges)
+ if (!BuildOpts.PruneTriviallyFalseEdges)
return TryResult();
Expr::EvalResult Result;
@@ -199,12 +199,7 @@
}
bool badCFG;
-
- // True iff trivially false edges should be pruned from the CFG.
- bool PruneTriviallyFalseEdges;
-
- // True iff EH edges on CallExprs should be added to the CFG.
- bool AddEHEdges;
+ CFG::BuildOptions BuildOpts;
};
// FIXME: Add support for dependent-sized array types in C++?
@@ -227,11 +222,7 @@
/// transferred to the caller. If CFG construction fails, this method returns
/// NULL.
CFG* CFGBuilder::buildCFG(const Decl *D, Stmt* Statement, ASTContext* C,
- bool pruneTriviallyFalseEdges,
- bool addehedges) {
-
- AddEHEdges = addehedges;
- PruneTriviallyFalseEdges = pruneTriviallyFalseEdges;
+ CFG::BuildOptions BO) {
Context = C;
assert(cfg.get());
@@ -239,6 +230,9 @@
return NULL;
badCFG = false;
+ BuildOpts = BO;
+ if (!C->getLangOptions().CPlusPlus)
+ BuildOpts.AddImplicitDtors = false;
// Create an empty block that will serve as the exit block for the CFG. Since
// this is the first block added to the CFG, it will be implicitly registered
@@ -592,7 +586,7 @@
// Languages without exceptions are assumed to not throw.
if (Context->getLangOptions().Exceptions) {
- if (AddEHEdges)
+ if (BuildOpts.AddEHEdges)
AddEHEdge = true;
}
@@ -1810,11 +1804,9 @@
/// 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,
- bool PruneTriviallyFalse,
- bool AddEHEdges) {
+ BuildOptions BO) {
CFGBuilder Builder;
- return Builder.buildCFG(D, Statement, C, PruneTriviallyFalse,
- AddEHEdges);
+ return Builder.buildCFG(D, Statement, C, BO);
}
//===----------------------------------------------------------------------===//
More information about the cfe-commits
mailing list