From: Ted Kremenek Date: Thu, 13 Mar 2008 16:55:07 +0000 (+0000) Subject: The LiveVariables analysis no longer requires a FunctionDecl&; this allows it X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7cb15939e08ea31f0fadcd24c974dbc9e4b61c01;p=clang The LiveVariables analysis no longer requires a FunctionDecl&; this allows it to be run on other declarations of blocks of code (e.g., Objective-C methods.) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@48339 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Analysis/DeadStores.cpp b/Analysis/DeadStores.cpp index 0c05484432..0848336e58 100644 --- a/Analysis/DeadStores.cpp +++ b/Analysis/DeadStores.cpp @@ -76,13 +76,12 @@ public: namespace clang { -void CheckDeadStores(CFG& cfg, FunctionDecl& FD, ASTContext &Ctx, - Diagnostic &Diags) { +void CheckDeadStores(CFG& cfg, ASTContext &Ctx, Diagnostic &Diags) { - LiveVariables L(cfg, FD); + LiveVariables L(cfg); L.runOnCFG(cfg); DeadStoreObs A(Ctx, Diags); - L.runOnAllBlocks(cfg,&A); + L.runOnAllBlocks(cfg, &A); } } // end namespace clang diff --git a/Analysis/LiveVariables.cpp b/Analysis/LiveVariables.cpp index 52f7f4d19b..e59a488591 100644 --- a/Analysis/LiveVariables.cpp +++ b/Analysis/LiveVariables.cpp @@ -43,14 +43,9 @@ public: } // end anonymous namespace -LiveVariables::LiveVariables(CFG& cfg, FunctionDecl& FD) { +LiveVariables::LiveVariables(CFG& cfg) { + // Register all referenced VarDecls. 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); } @@ -201,11 +196,13 @@ void LiveVariables::runOnAllBlocks(const CFG& cfg, // bool LiveVariables::isLive(const CFGBlock* B, const VarDecl* D) const { - return getBlockData(B)(D,getAnalysisData()); + DeclBitVector_Types::Idx i = getAnalysisData().getIdx(D); + return i.isValid() ? getBlockData(B).getBit(i) : false; } bool LiveVariables::isLive(const ValTy& Live, const VarDecl* D) const { - return Live(D,getAnalysisData()); + DeclBitVector_Types::Idx i = getAnalysisData().getIdx(D); + return i.isValid() ? Live.getBit(i) : false; } bool LiveVariables::isLive(const Stmt* Loc, const Stmt* StmtVal) const { diff --git a/Driver/ASTConsumers.cpp b/Driver/ASTConsumers.cpp index 1e40495815..8e99878f66 100644 --- a/Driver/ASTConsumers.cpp +++ b/Driver/ASTConsumers.cpp @@ -528,7 +528,7 @@ namespace { } virtual void VisitCFG(CFG& C, FunctionDecl& FD) { - LiveVariables L(C, FD); + LiveVariables L(C); L.runOnCFG(C); L.dumpBlockLiveness(*SM); } @@ -553,7 +553,7 @@ namespace { } virtual void VisitCFG(CFG& C, FunctionDecl& FD) { - CheckDeadStores(C, FD, *Ctx, Diags); + CheckDeadStores(C, *Ctx, Diags); } virtual bool printFuncDeclStart() { return false; } diff --git a/include/clang/Analysis/Analyses/LiveVariables.h b/include/clang/Analysis/Analyses/LiveVariables.h index c048cbbc4e..f172df62e8 100644 --- a/include/clang/Analysis/Analyses/LiveVariables.h +++ b/include/clang/Analysis/Analyses/LiveVariables.h @@ -64,7 +64,7 @@ class LiveVariables : public DataflowValuessecond; + return I == DMap.end() ? Idx() : Idx(I->second); } unsigned getNumDecls() const { return NDecls; } @@ -84,13 +98,21 @@ struct DeclBitVector_Types { void copyValues(const ValTy& RHS) { DeclBV = RHS.DeclBV; } + llvm::BitVector::reference getBit(unsigned i) { + return DeclBV[i]; + } + + const bool getBit(unsigned i) const { + return DeclBV[i]; + } + llvm::BitVector::reference operator()(const ScopedDecl* SD, const AnalysisDataTy& AD) { - return DeclBV[AD.getIdx(SD)]; + return getBit(AD.getIdx(SD)); } - const llvm::BitVector::reference - operator()(const ScopedDecl* SD, const AnalysisDataTy& AD) const { - return const_cast(*this)(SD,AD); + + bool operator()(const ScopedDecl* SD, const AnalysisDataTy& AD) const { + return getBit(AD.getIdx(SD)); } llvm::BitVector::reference getDeclBit(unsigned i) { return DeclBV[i]; }