[cfe-commits] r48339 - in /cfe/trunk: Analysis/DeadStores.cpp Analysis/LiveVariables.cpp Driver/ASTConsumers.cpp include/clang/Analysis/Analyses/LiveVariables.h include/clang/Analysis/LocalCheckers.h include/clang/Analysis/PathSensitive/GRExprEngine.h include/clang/Analysis/Support/ExprDeclBitVector.h
Ted Kremenek
kremenek at apple.com
Thu Mar 13 09:55:08 PDT 2008
Author: kremenek
Date: Thu Mar 13 11:55:07 2008
New Revision: 48339
URL: http://llvm.org/viewvc/llvm-project?rev=48339&view=rev
Log:
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.)
Modified:
cfe/trunk/Analysis/DeadStores.cpp
cfe/trunk/Analysis/LiveVariables.cpp
cfe/trunk/Driver/ASTConsumers.cpp
cfe/trunk/include/clang/Analysis/Analyses/LiveVariables.h
cfe/trunk/include/clang/Analysis/LocalCheckers.h
cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h
cfe/trunk/include/clang/Analysis/Support/ExprDeclBitVector.h
Modified: cfe/trunk/Analysis/DeadStores.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/DeadStores.cpp?rev=48339&r1=48338&r2=48339&view=diff
==============================================================================
--- cfe/trunk/Analysis/DeadStores.cpp (original)
+++ cfe/trunk/Analysis/DeadStores.cpp Thu Mar 13 11:55:07 2008
@@ -76,13 +76,12 @@
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
Modified: cfe/trunk/Analysis/LiveVariables.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/LiveVariables.cpp?rev=48339&r1=48338&r2=48339&view=diff
==============================================================================
--- cfe/trunk/Analysis/LiveVariables.cpp (original)
+++ cfe/trunk/Analysis/LiveVariables.cpp Thu Mar 13 11:55:07 2008
@@ -43,14 +43,9 @@
} // 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 @@
//
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 {
Modified: cfe/trunk/Driver/ASTConsumers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/ASTConsumers.cpp?rev=48339&r1=48338&r2=48339&view=diff
==============================================================================
--- cfe/trunk/Driver/ASTConsumers.cpp (original)
+++ cfe/trunk/Driver/ASTConsumers.cpp Thu Mar 13 11:55:07 2008
@@ -528,7 +528,7 @@
}
virtual void VisitCFG(CFG& C, FunctionDecl& FD) {
- LiveVariables L(C, FD);
+ LiveVariables L(C);
L.runOnCFG(C);
L.dumpBlockLiveness(*SM);
}
@@ -553,7 +553,7 @@
}
virtual void VisitCFG(CFG& C, FunctionDecl& FD) {
- CheckDeadStores(C, FD, *Ctx, Diags);
+ CheckDeadStores(C, *Ctx, Diags);
}
virtual bool printFuncDeclStart() { return false; }
Modified: cfe/trunk/include/clang/Analysis/Analyses/LiveVariables.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/Analyses/LiveVariables.h?rev=48339&r1=48338&r2=48339&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/Analyses/LiveVariables.h (original)
+++ cfe/trunk/include/clang/Analysis/Analyses/LiveVariables.h Thu Mar 13 11:55:07 2008
@@ -64,7 +64,7 @@
public:
typedef LiveVariables_ValueTypes::ObserverTy ObserverTy;
- LiveVariables(CFG& cfg, FunctionDecl& FD);
+ LiveVariables(CFG& cfg);
/// IsLive - Return true if a variable is live at beginning of a
/// specified block.
Modified: cfe/trunk/include/clang/Analysis/LocalCheckers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/LocalCheckers.h?rev=48339&r1=48338&r2=48339&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/LocalCheckers.h (original)
+++ cfe/trunk/include/clang/Analysis/LocalCheckers.h Thu Mar 13 11:55:07 2008
@@ -22,8 +22,7 @@
class Diagnostic;
class ASTContext;
-void CheckDeadStores(CFG& cfg, FunctionDecl& FD, ASTContext &Ctx,
- Diagnostic &Diags);
+void CheckDeadStores(CFG& cfg, ASTContext &Ctx, Diagnostic &Diags);
void CheckUninitializedValues(CFG& cfg, ASTContext& Ctx, Diagnostic& Diags,
bool FullUninitTaint=false);
Modified: cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h?rev=48339&r1=48338&r2=48339&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h Thu Mar 13 11:55:07 2008
@@ -126,7 +126,7 @@
public:
GRExprEngine(GraphTy& g) :
- G(g), Liveness(G.getCFG(), G.getFunctionDecl()),
+ G(g), Liveness(G.getCFG()),
Builder(NULL),
StateMgr(G.getContext(), G.getAllocator()),
BasicVals(StateMgr.getBasicValueFactory()),
Modified: cfe/trunk/include/clang/Analysis/Support/ExprDeclBitVector.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/Support/ExprDeclBitVector.h?rev=48339&r1=48338&r2=48339&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/Support/ExprDeclBitVector.h (original)
+++ cfe/trunk/include/clang/Analysis/Support/ExprDeclBitVector.h Thu Mar 13 11:55:07 2008
@@ -28,6 +28,21 @@
struct DeclBitVector_Types {
+ class Idx {
+ unsigned I;
+ public:
+ Idx(unsigned i) : I(i) {}
+ explicit Idx() : I(~0U) {}
+
+ bool isValid() const {
+ return I != ~0U;
+ }
+ operator unsigned() const {
+ assert (isValid());
+ return I;
+ }
+ };
+
//===--------------------------------------------------------------------===//
// AnalysisDataTy - Whole-function meta data.
//===--------------------------------------------------------------------===//
@@ -48,10 +63,9 @@
bool isTracked(const ScopedDecl* SD) { return DMap.find(SD) != DMap.end(); }
- unsigned getIdx(const ScopedDecl* SD) const {
+ Idx getIdx(const ScopedDecl* SD) const {
DMapTy::const_iterator I = DMap.find(SD);
- assert (I != DMap.end());
- return I->second;
+ return I == DMap.end() ? Idx() : Idx(I->second);
}
unsigned getNumDecls() const { return NDecls; }
@@ -84,13 +98,21 @@
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<ValTy&>(*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]; }
More information about the cfe-commits
mailing list