diff options
Diffstat (limited to 'clang/Analysis')
| -rw-r--r-- | clang/Analysis/DeadStores.cpp | 6 | ||||
| -rw-r--r-- | clang/Analysis/GRConstants.cpp | 19 | ||||
| -rw-r--r-- | clang/Analysis/LiveVariables.cpp | 10 |
3 files changed, 21 insertions, 14 deletions
diff --git a/clang/Analysis/DeadStores.cpp b/clang/Analysis/DeadStores.cpp index 926109e1b29..4475d495fbf 100644 --- a/clang/Analysis/DeadStores.cpp +++ b/clang/Analysis/DeadStores.cpp @@ -76,8 +76,10 @@ public: namespace clang { -void CheckDeadStores(CFG& cfg, ASTContext &Ctx, Diagnostic &Diags) { - LiveVariables L(cfg); +void CheckDeadStores(CFG& cfg, FunctionDecl& FD, ASTContext &Ctx, + Diagnostic &Diags) { + + LiveVariables L(cfg, FD); L.runOnCFG(cfg); DeadStoreObs A(Ctx, Diags); L.runOnAllBlocks(cfg,&A); diff --git a/clang/Analysis/GRConstants.cpp b/clang/Analysis/GRConstants.cpp index a0a58db79a2..103e6a0d74b 100644 --- a/clang/Analysis/GRConstants.cpp +++ b/clang/Analysis/GRConstants.cpp @@ -577,7 +577,7 @@ protected: /// Liveness - live-variables information the ValueDecl* and block-level /// Expr* in the CFG. Used to prune out dead state. - LiveVariables* Liveness; + LiveVariables Liveness; /// Builder - The current GRNodeBuilder which is used when building the nodes /// for a given statement. @@ -600,17 +600,14 @@ protected: ASTContext& getContext() const { return G.getContext(); } public: - GRConstants(GraphTy& g) : G(g), Liveness(NULL), Builder(NULL), - ValMgr(G.getContext()), StmtEntryNode(NULL), CurrentStmt(NULL) { + GRConstants(GraphTy& g) : G(g), Liveness(G.getCFG(), G.getFunctionDecl()), + Builder(NULL), ValMgr(G.getContext()), StmtEntryNode(NULL), + CurrentStmt(NULL) { // Compute liveness information. - CFG& c = G.getCFG(); - Liveness = new LiveVariables(c); - Liveness->runOnCFG(c); - Liveness->runOnAllBlocks(c, NULL, true); + Liveness.runOnCFG(G.getCFG()); + Liveness.runOnAllBlocks(G.getCFG(), NULL, true); } - - ~GRConstants() { delete Liveness; } /// getCFG - Returns the CFG associated with this analysis. CFG& getCFG() { return G.getCFG(); } @@ -843,14 +840,14 @@ GRConstants::StateTy GRConstants::RemoveDeadBindings(Stmt* Loc, StateTy M) { // Remove old bindings for subexpressions and "dead" block-level expressions. for (; I!=E && !I.getKey().isDecl(); ++I) { - if (I.getKey().isSubExpr() || !Liveness->isLive(Loc,cast<Stmt>(I.getKey()))) + if (I.getKey().isSubExpr() || !Liveness.isLive(Loc,cast<Stmt>(I.getKey()))) M = StateMgr.Remove(M, I.getKey()); } // Remove bindings for "dead" decls. for (; I!=E && I.getKey().isDecl(); ++I) if (VarDecl* V = dyn_cast<VarDecl>(cast<ValueDecl>(I.getKey()))) - if (!Liveness->isLive(Loc, V)) + if (!Liveness.isLive(Loc, V)) M = StateMgr.Remove(M, I.getKey()); return M; diff --git a/clang/Analysis/LiveVariables.cpp b/clang/Analysis/LiveVariables.cpp index b96f7fc4bb2..c14b463be16 100644 --- a/clang/Analysis/LiveVariables.cpp +++ b/clang/Analysis/LiveVariables.cpp @@ -42,7 +42,15 @@ public: }; } // end anonymous namespace -void LiveVariables::InitializeValues(const CFG& cfg) { + +LiveVariables::LiveVariables(CFG& cfg, FunctionDecl& FD) { + getAnalysisData().setCFG(&cfg); + + for (FunctionDecl::param_iterator I=FD.param_begin(), E=FD.param_end(); + I !=E; ++I) + getAnalysisData().Register(*I); + + // Now register all the other VarDecls; RegisterDecls R(getAnalysisData()); cfg.VisitBlockStmts(R); } |

