Renamed GRConstants => GRSimpleVals.

Moved driver logic for --grsimple to GRSimpleVals.cpp.

llvm-svn: 47137
This commit is contained in:
Ted Kremenek 2008-02-14 22:36:46 +00:00
parent bd8957b6b2
commit d3122cb83c
8 changed files with 60 additions and 51 deletions

View File

@ -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 @@ GRExprEngine::AssumeSymInt(StateTy St, bool Assumption,
}
//===----------------------------------------------------------------------===//
// Driver.
// Visualization.
//===----------------------------------------------------------------------===//
#ifndef NDEBUG
@ -1210,36 +1212,10 @@ struct VISIBILITY_HIDDEN DOTGraphTraits<GRExprEngine::NodeTy*> :
} // 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

View File

@ -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.
//===----------------------------------------------------------------------===//

View File

@ -17,6 +17,7 @@
#define LLVM_CLANG_ANALYSIS_GRSIMPLEVALS
#include "clang/Analysis/PathSensitive/GRTransferFuncs.h"
#include "clang/Analysis/PathSensitive/GRExprEngine.h"
namespace clang {

View File

@ -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 @@ ASTConsumer *clang::CreateUnitValsChecker(Diagnostic &Diags) {
}
//===----------------------------------------------------------------------===//
// 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);
}
//===----------------------------------------------------------------------===//

View File

@ -41,7 +41,7 @@ ASTConsumer *CreateDeadStoreChecker(Diagnostic &Diags);
ASTConsumer *CreateUnitValsChecker(Diagnostic &Diags);
ASTConsumer *CreateGRConstants(Diagnostic &Diags);
ASTConsumer *CreateGRSimpleVals(Diagnostic &Diags);
ASTConsumer *CreateCodeRewriterTest(const std::string& InFile,
Diagnostic &Diags);

View File

@ -68,7 +68,7 @@ enum ProgActions {
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 @@ ProgAction(llvm::cl::desc("Choose output type:"), llvm::cl::ZeroOrMore,
"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 @@ static ASTConsumer* CreateASTConsumer(const std::string& InFile,
case WarnUninitVals:
return CreateUnitValsChecker(Diag);
case AnalysisGRConstants:
return CreateGRConstants(Diag);
case AnalysisGRSimpleVals:
return CreateGRSimpleVals(Diag);
case TestSerialization:
return CreateSerializationTest(Diag, FileMgr, LangOpts);

View File

@ -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

View File

@ -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 @@ public:
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() {