Renamed GRConstants => GRSimpleVals.
Moved driver logic for --grsimple to GRSimpleVals.cpp.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@47137 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Analysis/GRExprEngine.cpp b/Analysis/GRExprEngine.cpp
index d9f1826..4418afd 100644
--- a/Analysis/GRExprEngine.cpp
+++ b/Analysis/GRExprEngine.cpp
@@ -14,7 +14,9 @@
//===----------------------------------------------------------------------===//
#include "clang/Analysis/PathSensitive/GRExprEngine.h"
-#include "GRSimpleVals.h"
+#include "clang/Analysis/PathSensitive/GRTransferFuncs.h"
+
+#include "llvm/Support/Streams.h"
using namespace clang;
using llvm::dyn_cast;
@@ -1004,7 +1006,7 @@
}
//===----------------------------------------------------------------------===//
-// Driver.
+// Visualization.
//===----------------------------------------------------------------------===//
#ifndef NDEBUG
@@ -1210,36 +1212,10 @@
} // end llvm namespace
#endif
-namespace clang {
-void RunGRConstants(CFG& cfg, FunctionDecl& FD, ASTContext& Ctx,
- Diagnostic& Diag) {
-
- GRCoreEngine<GRExprEngine> Engine(cfg, FD, Ctx);
- GRExprEngine* CheckerState = &Engine.getCheckerState();
- GRSimpleVals GRSV;
- CheckerState->setTransferFunctions(GRSV);
-
- // Execute the worklist algorithm.
- Engine.ExecuteWorkList();
-
- // Look for explicit-Null dereferences and warn about them.
-
-
- for (GRExprEngine::null_iterator I=CheckerState->null_begin(),
- E=CheckerState->null_end(); I!=E; ++I) {
-
- const PostStmt& L = cast<PostStmt>((*I)->getLocation());
- Expr* E = cast<Expr>(L.getStmt());
-
- Diag.Report(FullSourceLoc(E->getExprLoc(), Ctx.getSourceManager()),
- diag::chkr_null_deref_after_check);
- }
-
-
+void GRExprEngine::ViewGraph() {
#ifndef NDEBUG
- GraphPrintCheckerState = CheckerState;
- llvm::ViewGraph(*Engine.getGraph().roots_begin(),"GRExprEngine");
+ GraphPrintCheckerState = this;
+ llvm::ViewGraph(*G.roots_begin(), "GRExprEngine");
GraphPrintCheckerState = NULL;
-#endif
+#endif
}
-} // end clang namespace
diff --git a/Analysis/GRSimpleVals.cpp b/Analysis/GRSimpleVals.cpp
index 200c9a3..490ed7f 100644
--- a/Analysis/GRSimpleVals.cpp
+++ b/Analysis/GRSimpleVals.cpp
@@ -14,9 +14,39 @@
//===----------------------------------------------------------------------===//
#include "GRSimpleVals.h"
+#include "clang/Basic/Diagnostic.h"
using namespace clang;
+namespace clang {
+ void RunGRSimpleVals(CFG& cfg, FunctionDecl& FD, ASTContext& Ctx,
+ Diagnostic& Diag) {
+
+ GRCoreEngine<GRExprEngine> Engine(cfg, FD, Ctx);
+ GRExprEngine* CheckerState = &Engine.getCheckerState();
+ GRSimpleVals GRSV;
+ CheckerState->setTransferFunctions(GRSV);
+
+ // Execute the worklist algorithm.
+ Engine.ExecuteWorkList();
+
+ // Look for explicit-Null dereferences and warn about them.
+ for (GRExprEngine::null_iterator I=CheckerState->null_begin(),
+ E=CheckerState->null_end(); I!=E; ++I) {
+
+ const PostStmt& L = cast<PostStmt>((*I)->getLocation());
+ Expr* E = cast<Expr>(L.getStmt());
+
+ Diag.Report(FullSourceLoc(E->getExprLoc(), Ctx.getSourceManager()),
+ diag::chkr_null_deref_after_check);
+ }
+
+#ifndef NDEBUG
+ CheckerState->ViewGraph();
+#endif
+ }
+} // end clang namespace
+
//===----------------------------------------------------------------------===//
// Transfer function for Casts.
//===----------------------------------------------------------------------===//
diff --git a/Analysis/GRSimpleVals.h b/Analysis/GRSimpleVals.h
index 1ed6968..0f517fe 100644
--- a/Analysis/GRSimpleVals.h
+++ b/Analysis/GRSimpleVals.h
@@ -17,6 +17,7 @@
#define LLVM_CLANG_ANALYSIS_GRSIMPLEVALS
#include "clang/Analysis/PathSensitive/GRTransferFuncs.h"
+#include "clang/Analysis/PathSensitive/GRExprEngine.h"
namespace clang {
diff --git a/Driver/ASTConsumers.cpp b/Driver/ASTConsumers.cpp
index 6886194..08e2238 100644
--- a/Driver/ASTConsumers.cpp
+++ b/Driver/ASTConsumers.cpp
@@ -20,7 +20,7 @@
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/CFG.h"
#include "clang/Analysis/Analyses/LiveVariables.h"
-#include "clang/Analysis/Analyses/GRConstants.h"
+#include "clang/Analysis/Analyses/GRSimpleVals.h"
#include "clang/Analysis/LocalCheckers.h"
#include "llvm/Support/Streams.h"
using namespace clang;
@@ -574,26 +574,26 @@
}
//===----------------------------------------------------------------------===//
-// GRConstants - Perform intra-procedural, path-sensitive constant propagation.
+// GRSimpleVals - Perform intra-procedural, path-sensitive constant propagation.
namespace {
- class GRConstantsVisitor : public CFGVisitor {
+ class GRSimpleValsVisitor : public CFGVisitor {
Diagnostic &Diags;
ASTContext* Ctx;
public:
- GRConstantsVisitor(Diagnostic &diags) : Diags(diags) {}
+ GRSimpleValsVisitor(Diagnostic &diags) : Diags(diags) {}
virtual void Initialize(ASTContext &Context) { Ctx = &Context; }
virtual void VisitCFG(CFG& C, FunctionDecl&);
};
} // end anonymous namespace
-ASTConsumer* clang::CreateGRConstants(Diagnostic &Diags) {
- return new GRConstantsVisitor(Diags);
+ASTConsumer* clang::CreateGRSimpleVals(Diagnostic &Diags) {
+ return new GRSimpleValsVisitor(Diags);
}
-void GRConstantsVisitor::VisitCFG(CFG& C, FunctionDecl& FD) {
- RunGRConstants(C, FD, *Ctx, Diags);
+void GRSimpleValsVisitor::VisitCFG(CFG& C, FunctionDecl& FD) {
+ RunGRSimpleVals(C, FD, *Ctx, Diags);
}
//===----------------------------------------------------------------------===//
diff --git a/Driver/ASTConsumers.h b/Driver/ASTConsumers.h
index 28decda..8a14ff2 100644
--- a/Driver/ASTConsumers.h
+++ b/Driver/ASTConsumers.h
@@ -41,7 +41,7 @@
ASTConsumer *CreateUnitValsChecker(Diagnostic &Diags);
-ASTConsumer *CreateGRConstants(Diagnostic &Diags);
+ASTConsumer *CreateGRSimpleVals(Diagnostic &Diags);
ASTConsumer *CreateCodeRewriterTest(const std::string& InFile,
Diagnostic &Diags);
diff --git a/Driver/clang.cpp b/Driver/clang.cpp
index 2f47e51..c297303 100644
--- a/Driver/clang.cpp
+++ b/Driver/clang.cpp
@@ -68,7 +68,7 @@
ParseCFGDump, // Parse ASTS. Build CFGs. Print CFGs.
ParseCFGView, // Parse ASTS. Build CFGs. View CFGs.
AnalysisLiveVariables, // Print results of live-variable analysis.
- AnalysisGRConstants, // Perform graph-reachability constant prop.
+ AnalysisGRSimpleVals, // Perform graph-reachability constant prop.
WarnDeadStores, // Run DeadStores checker on parsed ASTs.
WarnDeadStoresCheck, // Check diagnostics for "DeadStores".
WarnUninitVals, // Run UnitializedVariables checker.
@@ -113,7 +113,7 @@
"Flag warnings of stores to dead variables."),
clEnumValN(WarnUninitVals, "warn-uninit-values",
"Flag warnings of uses of unitialized variables."),
- clEnumValN(AnalysisGRConstants, "grconstants",
+ clEnumValN(AnalysisGRSimpleVals, "grsimple",
"Perform path-sensitive constant propagation."),
clEnumValN(TestSerialization, "test-pickling",
"Run prototype serializtion code."),
@@ -971,8 +971,8 @@
case WarnUninitVals:
return CreateUnitValsChecker(Diag);
- case AnalysisGRConstants:
- return CreateGRConstants(Diag);
+ case AnalysisGRSimpleVals:
+ return CreateGRSimpleVals(Diag);
case TestSerialization:
return CreateSerializationTest(Diag, FileMgr, LangOpts);
diff --git a/include/clang/Analysis/Analyses/GRConstants.h b/include/clang/Analysis/Analyses/GRSimpleVals.h
similarity index 71%
rename from include/clang/Analysis/Analyses/GRConstants.h
rename to include/clang/Analysis/Analyses/GRSimpleVals.h
index afd0535..4da6d25 100644
--- a/include/clang/Analysis/Analyses/GRConstants.h
+++ b/include/clang/Analysis/Analyses/GRSimpleVals.h
@@ -1,4 +1,4 @@
-//===-- GRConstants.h- Simple, Path-Sens. Constant Prop. ---------*- C++ -*-==//
+//===-- GRSimpleVals.h- Simple, Path-Sens. Constant Prop. ---------*- C++ -*-==//
//
// The LLVM Compiler Infrastructure
//
@@ -9,7 +9,7 @@
//
// Constant Propagation via Graph Reachability
//
-// This files defines the interface to use the 'GRConstants' path-sensitive
+// This files defines the interface to use the 'GRSimpleVals' path-sensitive
// constant-propagation analysis.
//
//===----------------------------------------------------------------------===//
@@ -20,11 +20,11 @@
namespace clang {
class Diagnostic;
- /// RunGRConstants - This is a simple driver to run the GRConstants analysis
+ /// RunGRSimpleVals - This is a simple driver to run the GRSimpleVals analysis
/// on a provided CFG. This interface will eventually be replaced with
/// something more elaborate as the requirements on the interface become
/// clearer.
- void RunGRConstants(CFG& cfg, FunctionDecl& FD, ASTContext& Ctx,
+ void RunGRSimpleVals(CFG& cfg, FunctionDecl& FD, ASTContext& Ctx,
Diagnostic& Diag);
} // end clang namespace
diff --git a/include/clang/Analysis/PathSensitive/GRExprEngine.h b/include/clang/Analysis/PathSensitive/GRExprEngine.h
index fd0399a..1c88b30 100644
--- a/include/clang/Analysis/PathSensitive/GRExprEngine.h
+++ b/include/clang/Analysis/PathSensitive/GRExprEngine.h
@@ -17,7 +17,6 @@
#include "clang/Analysis/PathSensitive/GRCoreEngine.h"
#include "clang/Analysis/PathSensitive/GRTransferFuncs.h"
-#include "GRSimpleVals.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ASTContext.h"
@@ -33,7 +32,6 @@
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/Compiler.h"
-#include "llvm/Support/Streams.h"
#include <functional>
@@ -150,6 +148,10 @@
void setTransferFunctions(GRTransferFuncs* tf) { TF = tf; }
void setTransferFunctions(GRTransferFuncs& tf) { TF = &tf; }
+ /// ViewGraph - Visualize the ExplodedGraph created by executing the
+ /// simulation.
+ void ViewGraph();
+
/// getInitialState - Return the initial state used for the root vertex
/// in the ExplodedGraph.
StateTy getInitialState() {