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
} // 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);
}
//
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 {
}
virtual void VisitCFG(CFG& C, FunctionDecl& FD) {
- LiveVariables L(C, FD);
+ LiveVariables L(C);
L.runOnCFG(C);
L.dumpBlockLiveness(*SM);
}
}
virtual void VisitCFG(CFG& C, FunctionDecl& FD) {
- CheckDeadStores(C, FD, *Ctx, Diags);
+ CheckDeadStores(C, *Ctx, Diags);
}
virtual bool printFuncDeclStart() { return false; }
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.
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);
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()),
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.
//===--------------------------------------------------------------------===//
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; }
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]; }