From ccc263b44c62ce3a02f797a3ddb3d6017cf0e5e4 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Wed, 23 Jun 2010 22:08:00 +0000 Subject: [PATCH] Add 'VisitEndAnalysis' callback to Checker class. This callback is called by GRExprEngine when the worklist algorithm has terminated. This allows some checkers to do a post-analysis phase after all paths have been analyzed. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@106689 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Checker/PathSensitive/Checker.h | 3 ++ .../Checker/PathSensitive/GRExprEngine.h | 7 +++-- .../clang/Checker/PathSensitive/GRSubEngine.h | 28 +++++++++++-------- lib/Checker/GRCoreEngine.cpp | 1 + lib/Checker/GRExprEngine.cpp | 7 +++++ 5 files changed, 32 insertions(+), 14 deletions(-) diff --git a/include/clang/Checker/PathSensitive/Checker.h b/include/clang/Checker/PathSensitive/Checker.h index dcb4ca62b8..034c305359 100644 --- a/include/clang/Checker/PathSensitive/Checker.h +++ b/include/clang/Checker/PathSensitive/Checker.h @@ -279,6 +279,9 @@ public: bool Assumption) { return state; } + + virtual void VisitEndAnalysis(ExplodedGraph &G, BugReporter &B, + bool hasWorkRemaining) {} }; } // end clang namespace diff --git a/include/clang/Checker/PathSensitive/GRExprEngine.h b/include/clang/Checker/PathSensitive/GRExprEngine.h index ac407f6933..cb5c0a70fc 100644 --- a/include/clang/Checker/PathSensitive/GRExprEngine.h +++ b/include/clang/Checker/PathSensitive/GRExprEngine.h @@ -178,12 +178,15 @@ public: /// nodes when the control reaches the end of a function. void ProcessEndPath(GREndPathNodeBuilder& builder); - // Generate the entry node of the callee. + /// Generate the entry node of the callee. void ProcessCallEnter(GRCallEnterNodeBuilder &builder); - // Generate the first post callsite node. + /// Generate the first post callsite node. void ProcessCallExit(GRCallExitNodeBuilder &builder); + /// Called by GRCoreEngine when the analysis worklist has terminated. + void ProcessEndWorklist(bool hasWorkRemaining); + /// EvalAssume - Callback function invoked by the ConstraintManager when /// making assumptions about state values. const GRState *ProcessAssume(const GRState *state, SVal cond, bool assumption); diff --git a/include/clang/Checker/PathSensitive/GRSubEngine.h b/include/clang/Checker/PathSensitive/GRSubEngine.h index d2e7457ea9..90a41d7c09 100644 --- a/include/clang/Checker/PathSensitive/GRSubEngine.h +++ b/include/clang/Checker/PathSensitive/GRSubEngine.h @@ -41,27 +41,27 @@ public: virtual GRStateManager& getStateManager() = 0; - /// ProcessStmt - Called by GRCoreEngine. Used to generate new successor - /// nodes by processing the 'effects' of a block-level statement. + /// Called by GRCoreEngine. Used to generate new successor + /// nodes by processing the 'effects' of a block-level statement. virtual void ProcessStmt(CFGElement E, GRStmtNodeBuilder& builder) = 0; - /// ProcessBlockEntrance - Called by GRCoreEngine when start processing - /// a CFGBlock. This method returns true if the analysis should continue - /// exploring the given path, and false otherwise. + /// Called by GRCoreEngine when start processing + /// a CFGBlock. This method returns true if the analysis should continue + /// exploring the given path, and false otherwise. virtual bool ProcessBlockEntrance(CFGBlock* B, const ExplodedNode *Pred, GRBlockCounter BC) = 0; - /// ProcessBranch - Called by GRCoreEngine. Used to generate successor + /// Called by GRCoreEngine. Used to generate successor /// nodes by processing the 'effects' of a branch condition. virtual void ProcessBranch(Stmt* Condition, Stmt* Term, GRBranchNodeBuilder& builder) = 0; - /// ProcessIndirectGoto - Called by GRCoreEngine. Used to generate successor - /// nodes by processing the 'effects' of a computed goto jump. + /// Called by GRCoreEngine. Used to generate successor + /// nodes by processing the 'effects' of a computed goto jump. virtual void ProcessIndirectGoto(GRIndirectGotoNodeBuilder& builder) = 0; - /// ProcessSwitch - Called by GRCoreEngine. Used to generate successor - /// nodes by processing the 'effects' of a switch statement. + /// Called by GRCoreEngine. Used to generate successor + /// nodes by processing the 'effects' of a switch statement. virtual void ProcessSwitch(GRSwitchNodeBuilder& builder) = 0; /// ProcessEndPath - Called by GRCoreEngine. Used to generate end-of-path @@ -74,10 +74,14 @@ public: // Generate the first post callsite node. virtual void ProcessCallExit(GRCallExitNodeBuilder &builder) = 0; - /// EvalAssume - Called by ConstraintManager. Used to call checker-specific - /// logic for handling assumptions on symbolic values. + /// Called by ConstraintManager. Used to call checker-specific + /// logic for handling assumptions on symbolic values. virtual const GRState* ProcessAssume(const GRState *state, SVal cond, bool assumption) = 0; + + /// Called by GRCoreEngine when the analysis worklist is either empty or the + // maximum number of analysis steps have been reached. + virtual void ProcessEndWorklist(bool hasWorkRemaining) = 0; }; } diff --git a/lib/Checker/GRCoreEngine.cpp b/lib/Checker/GRCoreEngine.cpp index 23a87d303b..36f330303c 100644 --- a/lib/Checker/GRCoreEngine.cpp +++ b/lib/Checker/GRCoreEngine.cpp @@ -221,6 +221,7 @@ bool GRCoreEngine::ExecuteWorkList(const LocationContext *L, unsigned Steps) { } } + SubEngine.ProcessEndWorklist(WList->hasWork()); return WList->hasWork(); } diff --git a/lib/Checker/GRExprEngine.cpp b/lib/Checker/GRExprEngine.cpp index d84301f0b9..b7b3502ccc 100644 --- a/lib/Checker/GRExprEngine.cpp +++ b/lib/Checker/GRExprEngine.cpp @@ -466,6 +466,13 @@ const GRState *GRExprEngine::ProcessAssume(const GRState *state, SVal cond, return TF->EvalAssume(state, cond, assumption); } +void GRExprEngine::ProcessEndWorklist(bool hasWorkRemaining) { + for (CheckersOrdered::iterator I = Checkers.begin(), E = Checkers.end(); + I != E; ++I) { + I->second->VisitEndAnalysis(G, BR, hasWorkRemaining); + } +} + void GRExprEngine::ProcessStmt(CFGElement CE, GRStmtNodeBuilder& builder) { CurrentStmt = CE.getStmt(); PrettyStackTraceLoc CrashInfo(getContext().getSourceManager(), -- 2.40.0