/// only be used for querying the dataflow values within a block with
/// and Observer object.
void runOnBlock(const CFGBlock* B) {
+ if (D.getBlockDataMap().find(B) == D.getBlockDataMap().end())
+ return;
+
TransferFuncsTy TF (D.getAnalysisData());
ProcessBlock(B,TF,AnalysisDirTag());
}
I != E; ++I)
WorkList.enqueue(*I);
}
-
- // For blocks that have no associated dataflow value, instantiate a
- // default value.
- BlockDataMapTy& M = D.getBlockDataMap();
-
- for (CFG::const_iterator I=cfg.begin(), E=cfg.end(); I!=E; ++I)
- if (M.find(&*I) == M.end())
- M[&*I].resetValues(D.getAnalysisData());
}
/// SolveDataflowEquations (BACKWARD ANALYSIS) - Perform the actual
/// ProcessBlock (FORWARD ANALYSIS) - Process the transfer functions
/// for a given block based on a forward analysis.
- bool ProcessBlock(const CFGBlock* B, TransferFuncsTy& TF,
+ bool ProcessBlock(const CFGBlock* B, TransferFuncsTy& TF,
dataflow::forward_analysis_tag) {
ValTy& V = TF.getVal();
V.resetValues(D.getAnalysisData());
MergeOperatorTy Merge;
+ BlockDataMapTy& M = D.getBlockDataMap();
+ bool firstMerge = true;
+
for (CFGBlock::const_pred_iterator I=B->pred_begin(),
- E=B->pred_end(); I!=E; ++I)
- Merge(V,D.getBlockData(*I));
+ E=B->pred_end(); I!=E; ++I) {
+ typename BlockDataMapTy::iterator BI = M.find(*I);
+ if (BI != M.end()) {
+ if (firstMerge) {
+ firstMerge = false;
+ V.copyValues(BI->second);
+ }
+ else
+ Merge(V,BI->second);
+ }
+ }
// Process the statements in the block in the forward direction.
for (CFGBlock::const_iterator I=B->begin(), E=B->end(); I!=E; ++I)
V.resetValues(D.getAnalysisData());
MergeOperatorTy Merge;
+ BlockDataMapTy& M = D.getBlockDataMap();
+ bool firstMerge = true;
+
for (CFGBlock::const_succ_iterator I=B->succ_begin(),
- E=B->succ_end(); I!=E; ++I)
- Merge(V,D.getBlockData(*I));
+ E=B->succ_end(); I!=E; ++I) {
+ typename BlockDataMapTy::iterator BI = M.find(*I);
+ if (BI != M.end()) {
+ if (firstMerge) {
+ firstMerge = false;
+ V.copyValues(BI->second);
+ }
+ else
+ Merge(V,BI->second);
+ }
+ }
// Process the statements in the block in the forward direction.
for (CFGBlock::const_reverse_iterator I=B->begin(), E=B->end(); I!=E; ++I)
R.BlockStmt_Visit(*BI);
// Initialize the values of the last block.
- UninitializedValues::ValTy& V = getBlockDataMap()[&cfg.getEntry()];
- V.resetValues(getAnalysisData());
+// UninitializedValues::ValTy& V = getBlockDataMap()[&cfg.getEntry()];
+// V.resetValues(getAnalysisData());
}
//===----------------------------------------------------------------------===//
class TransferFuncs : public CFGStmtVisitor<TransferFuncs,bool> {
UninitializedValues::ValTy V;
UninitializedValues::AnalysisDataTy& AD;
+ bool InitWithAssigns;
public:
- TransferFuncs(UninitializedValues::AnalysisDataTy& ad) : AD(ad) {
+ TransferFuncs(UninitializedValues::AnalysisDataTy& ad,
+ bool init_with_assigns=true) :
+ AD(ad), InitWithAssigns(init_with_assigns) {
V.resetValues(AD);
}
else if (DeclRefExpr* DR = dyn_cast<DeclRefExpr>(S))
if (BlockVarDecl* VD = dyn_cast<BlockVarDecl>(DR->getDecl())) {
assert ( AD.VMap.find(VD) != AD.VMap.end() && "Unknown VarDecl.");
- return V.DeclBV[ AD.VMap[VD] ] = Visit(B->getRHS());
+
+ if(InitWithAssigns) {
+ // Pseudo-hack to prevent cascade of warnings. If the RHS uses
+ // an uninitialized value, then we are already going to flag a warning
+ // related to the "cause". Thus, propogating uninitialized doesn't
+ // make sense, since we are just adding extra messages that don't
+ // contribute to diagnosing the bug. In InitWithAssigns mode
+ // we unconditionally set the assigned variable to Initialized to
+ // prevent Uninitialized propogation.
+ return V.DeclBV[AD.VMap[VD]] = Initialized();
+ }
+ else
+ return V.DeclBV[ AD.VMap[VD] ] = Visit(B->getRHS());
}
-
+
break;
}
}
AD.EMap.end() && "Unknown Expr.");
assert ( AD.VMap.find(VD) != AD.VMap.end() && "Unknown VarDecl.");
- x = V.DeclBV[ AD.VMap[VD] ] = V.ExprBV[ AD.EMap[cast<Expr>(I)] ];
+ x = V.ExprBV[ AD.EMap[cast<Expr>(I)] ];
+ V.DeclBV[ AD.VMap[VD] ] = x;
}
return x;
assert (Dst.ExprBV.size() == Src.ExprBV.size()
&& "Bitvector sizes do not match.");
- Dst.ExprBV |= Src.ExprBV;
+ Dst.ExprBV &= Src.ExprBV;
}
};
} // end anonymous namespace