From e01c98767dfd7153c3c84637c36659e3bbe16ff7 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Thu, 14 Feb 2008 22:36:46 +0000 Subject: [PATCH] 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 --- Analysis/GRExprEngine.cpp | 40 ++++--------------- Analysis/GRSimpleVals.cpp | 30 ++++++++++++++ Analysis/GRSimpleVals.h | 1 + Driver/ASTConsumers.cpp | 16 ++++---- Driver/ASTConsumers.h | 2 +- Driver/clang.cpp | 8 ++-- .../{GRConstants.h => GRSimpleVals.h} | 8 ++-- .../Analysis/PathSensitive/GRExprEngine.h | 6 ++- 8 files changed, 60 insertions(+), 51 deletions(-) rename include/clang/Analysis/Analyses/{GRConstants.h => GRSimpleVals.h} (72%) diff --git a/Analysis/GRExprEngine.cpp b/Analysis/GRExprEngine.cpp index d9f1826bd7..4418afddb6 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 @@ GRExprEngine::AssumeSymInt(StateTy St, bool Assumption, } //===----------------------------------------------------------------------===// -// Driver. +// Visualization. //===----------------------------------------------------------------------===// #ifndef NDEBUG @@ -1210,36 +1212,10 @@ struct VISIBILITY_HIDDEN DOTGraphTraits : } // end llvm namespace #endif -namespace clang { -void RunGRConstants(CFG& cfg, FunctionDecl& FD, ASTContext& Ctx, - Diagnostic& Diag) { - - GRCoreEngine 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((*I)->getLocation()); - Expr* E = cast(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 200c9a39c6..490ed7f31e 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 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((*I)->getLocation()); + Expr* E = cast(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 1ed69688b8..0f517fe5eb 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 688619438b..08e2238a66 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 @@ 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); } //===----------------------------------------------------------------------===// diff --git a/Driver/ASTConsumers.h b/Driver/ASTConsumers.h index 28decda9b3..8a14ff2b9e 100644 --- a/Driver/ASTConsumers.h +++ b/Driver/ASTConsumers.h @@ -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); diff --git a/Driver/clang.cpp b/Driver/clang.cpp index 2f47e5199c..c29730397f 100644 --- a/Driver/clang.cpp +++ b/Driver/clang.cpp @@ -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); diff --git a/include/clang/Analysis/Analyses/GRConstants.h b/include/clang/Analysis/Analyses/GRSimpleVals.h similarity index 72% rename from include/clang/Analysis/Analyses/GRConstants.h rename to include/clang/Analysis/Analyses/GRSimpleVals.h index afd0535a9a..4da6d258db 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 fd0399ae53..1c88b30b88 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 @@ -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() { -- 2.40.0