blob: 29c17c3765de8ef9a2b0d0f9c0240b410df19164 [file] [log] [blame]
Ted Kremenek6f342132011-03-15 03:17:07 +00001//==- UninitializedValues.cpp - Find Uninitialized Values -------*- C++ --*-==//
Ted Kremenek610068c2011-01-15 02:58:47 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements uninitialized values analysis for source-level CFGs.
11//
12//===----------------------------------------------------------------------===//
13
Richard Smith558e8872012-07-13 23:33:44 +000014#include "clang/AST/ASTContext.h"
Benjamin Kramer2fa67ef2012-12-01 15:09:41 +000015#include "clang/AST/Attr.h"
Ted Kremenek610068c2011-01-15 02:58:47 +000016#include "clang/AST/Decl.h"
Jordan Rosed049b402013-05-15 23:22:55 +000017#include "clang/AST/StmtVisitor.h"
Ted Kremenekc1602582012-11-17 02:00:00 +000018#include "clang/Analysis/Analyses/PostOrderCFGView.h"
Ted Kremenek6f342132011-03-15 03:17:07 +000019#include "clang/Analysis/Analyses/UninitializedValues.h"
Benjamin Kramer2fa67ef2012-12-01 15:09:41 +000020#include "clang/Analysis/AnalysisContext.h"
21#include "clang/Analysis/CFG.h"
Ted Kremenek25c1d572012-09-13 00:21:35 +000022#include "clang/Analysis/DomainSpecific/ObjCNoReturn.h"
Benjamin Kramer2fa67ef2012-12-01 15:09:41 +000023#include "llvm/ADT/DenseMap.h"
24#include "llvm/ADT/Optional.h"
25#include "llvm/ADT/PackedVector.h"
26#include "llvm/ADT/SmallBitVector.h"
27#include "llvm/ADT/SmallVector.h"
Argyrios Kyrtzidisb2c60b02012-03-01 19:45:56 +000028#include "llvm/Support/SaveAndRestore.h"
Benjamin Kramer2fa67ef2012-12-01 15:09:41 +000029#include <utility>
Ted Kremenek610068c2011-01-15 02:58:47 +000030
31using namespace clang;
32
Richard Smith558e8872012-07-13 23:33:44 +000033#define DEBUG_LOGGING 0
34
Ted Kremenek40900ee2011-01-27 02:29:34 +000035static bool isTrackedVar(const VarDecl *vd, const DeclContext *dc) {
Ted Kremenek1cbc3152011-03-17 03:06:11 +000036 if (vd->isLocalVarDecl() && !vd->hasGlobalStorage() &&
Ted Kremeneka21612f2011-04-07 20:02:56 +000037 !vd->isExceptionVariable() &&
Ted Kremenek1cbc3152011-03-17 03:06:11 +000038 vd->getDeclContext() == dc) {
39 QualType ty = vd->getType();
40 return ty->isScalarType() || ty->isVectorType();
41 }
42 return false;
Ted Kremenekc104e532011-01-18 04:53:25 +000043}
44
Ted Kremenek610068c2011-01-15 02:58:47 +000045//------------------------------------------------------------------------====//
Ted Kremenek136f8f22011-03-15 04:57:27 +000046// DeclToIndex: a mapping from Decls we track to value indices.
Ted Kremenek610068c2011-01-15 02:58:47 +000047//====------------------------------------------------------------------------//
48
49namespace {
Ted Kremenek136f8f22011-03-15 04:57:27 +000050class DeclToIndex {
Ted Kremenek610068c2011-01-15 02:58:47 +000051 llvm::DenseMap<const VarDecl *, unsigned> map;
52public:
Ted Kremenek136f8f22011-03-15 04:57:27 +000053 DeclToIndex() {}
Ted Kremenek610068c2011-01-15 02:58:47 +000054
55 /// Compute the actual mapping from declarations to bits.
56 void computeMap(const DeclContext &dc);
57
58 /// Return the number of declarations in the map.
59 unsigned size() const { return map.size(); }
60
61 /// Returns the bit vector index for a given declaration.
David Blaikiedc84cd52013-02-20 22:23:23 +000062 Optional<unsigned> getValueIndex(const VarDecl *d) const;
Ted Kremenek610068c2011-01-15 02:58:47 +000063};
64}
65
Ted Kremenek136f8f22011-03-15 04:57:27 +000066void DeclToIndex::computeMap(const DeclContext &dc) {
Ted Kremenek610068c2011-01-15 02:58:47 +000067 unsigned count = 0;
68 DeclContext::specific_decl_iterator<VarDecl> I(dc.decls_begin()),
69 E(dc.decls_end());
70 for ( ; I != E; ++I) {
David Blaikie581deb32012-06-06 20:45:41 +000071 const VarDecl *vd = *I;
Ted Kremenek40900ee2011-01-27 02:29:34 +000072 if (isTrackedVar(vd, &dc))
Ted Kremenek610068c2011-01-15 02:58:47 +000073 map[vd] = count++;
74 }
75}
76
David Blaikiedc84cd52013-02-20 22:23:23 +000077Optional<unsigned> DeclToIndex::getValueIndex(const VarDecl *d) const {
Ted Kremenekb831c672011-03-29 01:40:00 +000078 llvm::DenseMap<const VarDecl *, unsigned>::const_iterator I = map.find(d);
Ted Kremenek610068c2011-01-15 02:58:47 +000079 if (I == map.end())
David Blaikie66874fb2013-02-21 01:47:18 +000080 return None;
Ted Kremenek610068c2011-01-15 02:58:47 +000081 return I->second;
82}
83
84//------------------------------------------------------------------------====//
85// CFGBlockValues: dataflow values for CFG blocks.
86//====------------------------------------------------------------------------//
87
Ted Kremenekf7bafc72011-03-15 04:57:38 +000088// These values are defined in such a way that a merge can be done using
89// a bitwise OR.
90enum Value { Unknown = 0x0, /* 00 */
91 Initialized = 0x1, /* 01 */
92 Uninitialized = 0x2, /* 10 */
93 MayUninitialized = 0x3 /* 11 */ };
94
95static bool isUninitialized(const Value v) {
96 return v >= Uninitialized;
97}
98static bool isAlwaysUninit(const Value v) {
99 return v == Uninitialized;
100}
Ted Kremenekafb10c42011-03-15 04:57:29 +0000101
Benjamin Kramerda57f3e2011-03-26 12:38:21 +0000102namespace {
Ted Kremenek496398d2011-03-15 04:57:32 +0000103
Benjamin Kramerda3d76b2012-09-28 16:44:29 +0000104typedef llvm::PackedVector<Value, 2, llvm::SmallBitVector> ValueVector;
Ted Kremenek13bd4232011-01-20 17:37:17 +0000105
Ted Kremenek610068c2011-01-15 02:58:47 +0000106class CFGBlockValues {
107 const CFG &cfg;
Benjamin Kramerda3d76b2012-09-28 16:44:29 +0000108 SmallVector<ValueVector, 8> vals;
Ted Kremenek136f8f22011-03-15 04:57:27 +0000109 ValueVector scratch;
Ted Kremenek4ddb3872011-03-15 05:30:12 +0000110 DeclToIndex declToIndex;
Ted Kremenek610068c2011-01-15 02:58:47 +0000111public:
112 CFGBlockValues(const CFG &cfg);
Ted Kremenekeee18c32012-07-19 04:59:05 +0000113
Ted Kremenekd40066b2011-04-04 23:29:12 +0000114 unsigned getNumEntries() const { return declToIndex.size(); }
115
Ted Kremenek610068c2011-01-15 02:58:47 +0000116 void computeSetOfDeclarations(const DeclContext &dc);
Ted Kremenekeee18c32012-07-19 04:59:05 +0000117 ValueVector &getValueVector(const CFGBlock *block) {
Benjamin Kramerda3d76b2012-09-28 16:44:29 +0000118 return vals[block->getBlockID()];
Ted Kremenekeee18c32012-07-19 04:59:05 +0000119 }
Ted Kremenek13bd4232011-01-20 17:37:17 +0000120
Richard Smitha9e8b9e2012-07-02 23:23:04 +0000121 void setAllScratchValues(Value V);
Ted Kremenek136f8f22011-03-15 04:57:27 +0000122 void mergeIntoScratch(ValueVector const &source, bool isFirst);
123 bool updateValueVectorWithScratch(const CFGBlock *block);
Ted Kremenek610068c2011-01-15 02:58:47 +0000124
125 bool hasNoDeclarations() const {
Ted Kremenek4ddb3872011-03-15 05:30:12 +0000126 return declToIndex.size() == 0;
Ted Kremenek610068c2011-01-15 02:58:47 +0000127 }
Ted Kremeneke0e29332011-08-20 01:15:28 +0000128
Ted Kremenek610068c2011-01-15 02:58:47 +0000129 void resetScratch();
Ted Kremenek13bd4232011-01-20 17:37:17 +0000130
Ted Kremenek136f8f22011-03-15 04:57:27 +0000131 ValueVector::reference operator[](const VarDecl *vd);
Richard Smith2815e1a2012-05-25 02:17:09 +0000132
133 Value getValue(const CFGBlock *block, const CFGBlock *dstBlock,
134 const VarDecl *vd) {
David Blaikiedc84cd52013-02-20 22:23:23 +0000135 const Optional<unsigned> &idx = declToIndex.getValueIndex(vd);
Richard Smith2815e1a2012-05-25 02:17:09 +0000136 assert(idx.hasValue());
Ted Kremenekeee18c32012-07-19 04:59:05 +0000137 return getValueVector(block)[idx.getValue()];
Richard Smith2815e1a2012-05-25 02:17:09 +0000138 }
Ted Kremenek610068c2011-01-15 02:58:47 +0000139};
Benjamin Kramerda57f3e2011-03-26 12:38:21 +0000140} // end anonymous namespace
Ted Kremenek610068c2011-01-15 02:58:47 +0000141
Ted Kremenekeee18c32012-07-19 04:59:05 +0000142CFGBlockValues::CFGBlockValues(const CFG &c) : cfg(c), vals(0) {}
Ted Kremenek610068c2011-01-15 02:58:47 +0000143
Ted Kremenek610068c2011-01-15 02:58:47 +0000144void CFGBlockValues::computeSetOfDeclarations(const DeclContext &dc) {
Ted Kremenek4ddb3872011-03-15 05:30:12 +0000145 declToIndex.computeMap(dc);
Ted Kremenekeee18c32012-07-19 04:59:05 +0000146 unsigned decls = declToIndex.size();
147 scratch.resize(decls);
148 unsigned n = cfg.getNumBlockIDs();
149 if (!n)
150 return;
151 vals.resize(n);
152 for (unsigned i = 0; i < n; ++i)
Benjamin Kramerda3d76b2012-09-28 16:44:29 +0000153 vals[i].resize(decls);
Ted Kremenek13bd4232011-01-20 17:37:17 +0000154}
155
Richard Smith558e8872012-07-13 23:33:44 +0000156#if DEBUG_LOGGING
Ted Kremenek136f8f22011-03-15 04:57:27 +0000157static void printVector(const CFGBlock *block, ValueVector &bv,
Ted Kremenek9fcbcee2011-02-01 17:43:18 +0000158 unsigned num) {
Ted Kremenek9fcbcee2011-02-01 17:43:18 +0000159 llvm::errs() << block->getBlockID() << " :";
160 for (unsigned i = 0; i < bv.size(); ++i) {
161 llvm::errs() << ' ' << bv[i];
162 }
163 llvm::errs() << " : " << num << '\n';
164}
165#endif
Ted Kremenek610068c2011-01-15 02:58:47 +0000166
Richard Smitha9e8b9e2012-07-02 23:23:04 +0000167void CFGBlockValues::setAllScratchValues(Value V) {
168 for (unsigned I = 0, E = scratch.size(); I != E; ++I)
169 scratch[I] = V;
170}
171
Ted Kremenekc5f740e2011-10-07 00:42:48 +0000172void CFGBlockValues::mergeIntoScratch(ValueVector const &source,
173 bool isFirst) {
174 if (isFirst)
175 scratch = source;
176 else
177 scratch |= source;
178}
179
Ted Kremenek136f8f22011-03-15 04:57:27 +0000180bool CFGBlockValues::updateValueVectorWithScratch(const CFGBlock *block) {
Ted Kremenekeee18c32012-07-19 04:59:05 +0000181 ValueVector &dst = getValueVector(block);
Ted Kremenek610068c2011-01-15 02:58:47 +0000182 bool changed = (dst != scratch);
183 if (changed)
184 dst = scratch;
Richard Smith558e8872012-07-13 23:33:44 +0000185#if DEBUG_LOGGING
Ted Kremenek9fcbcee2011-02-01 17:43:18 +0000186 printVector(block, scratch, 0);
187#endif
Ted Kremenek13bd4232011-01-20 17:37:17 +0000188 return changed;
189}
190
Ted Kremenek610068c2011-01-15 02:58:47 +0000191void CFGBlockValues::resetScratch() {
192 scratch.reset();
193}
194
Ted Kremenek136f8f22011-03-15 04:57:27 +0000195ValueVector::reference CFGBlockValues::operator[](const VarDecl *vd) {
David Blaikiedc84cd52013-02-20 22:23:23 +0000196 const Optional<unsigned> &idx = declToIndex.getValueIndex(vd);
Ted Kremenek610068c2011-01-15 02:58:47 +0000197 assert(idx.hasValue());
198 return scratch[idx.getValue()];
199}
200
201//------------------------------------------------------------------------====//
202// Worklist: worklist for dataflow analysis.
203//====------------------------------------------------------------------------//
204
205namespace {
206class DataflowWorklist {
Ted Kremenekc1602582012-11-17 02:00:00 +0000207 PostOrderCFGView::iterator PO_I, PO_E;
Chris Lattner5f9e2722011-07-23 10:55:15 +0000208 SmallVector<const CFGBlock *, 20> worklist;
Ted Kremenek496398d2011-03-15 04:57:32 +0000209 llvm::BitVector enqueuedBlocks;
Ted Kremenek610068c2011-01-15 02:58:47 +0000210public:
Ted Kremenekc1602582012-11-17 02:00:00 +0000211 DataflowWorklist(const CFG &cfg, PostOrderCFGView &view)
212 : PO_I(view.begin()), PO_E(view.end()),
213 enqueuedBlocks(cfg.getNumBlockIDs(), true) {
214 // Treat the first block as already analyzed.
215 if (PO_I != PO_E) {
216 assert(*PO_I == &cfg.getEntry());
217 enqueuedBlocks[(*PO_I)->getBlockID()] = false;
218 ++PO_I;
219 }
220 }
Ted Kremenek610068c2011-01-15 02:58:47 +0000221
Ted Kremenek610068c2011-01-15 02:58:47 +0000222 void enqueueSuccessors(const CFGBlock *block);
223 const CFGBlock *dequeue();
Ted Kremenek610068c2011-01-15 02:58:47 +0000224};
225}
226
Ted Kremenek610068c2011-01-15 02:58:47 +0000227void DataflowWorklist::enqueueSuccessors(const clang::CFGBlock *block) {
228 for (CFGBlock::const_succ_iterator I = block->succ_begin(),
229 E = block->succ_end(); I != E; ++I) {
Chandler Carruth80520502011-07-08 11:19:06 +0000230 const CFGBlock *Successor = *I;
231 if (!Successor || enqueuedBlocks[Successor->getBlockID()])
232 continue;
233 worklist.push_back(Successor);
234 enqueuedBlocks[Successor->getBlockID()] = true;
Ted Kremenek610068c2011-01-15 02:58:47 +0000235 }
236}
237
238const CFGBlock *DataflowWorklist::dequeue() {
Ted Kremenekc1602582012-11-17 02:00:00 +0000239 const CFGBlock *B = 0;
240
241 // First dequeue from the worklist. This can represent
242 // updates along backedges that we want propagated as quickly as possible.
Robert Wilhelm344472e2013-08-23 16:11:15 +0000243 if (!worklist.empty())
244 B = worklist.pop_back_val();
245
Ted Kremenekc1602582012-11-17 02:00:00 +0000246 // Next dequeue from the initial reverse post order. This is the
247 // theoretical ideal in the presence of no back edges.
248 else if (PO_I != PO_E) {
249 B = *PO_I;
250 ++PO_I;
251 }
252 else {
Ted Kremenek610068c2011-01-15 02:58:47 +0000253 return 0;
Ted Kremenekc1602582012-11-17 02:00:00 +0000254 }
255
256 assert(enqueuedBlocks[B->getBlockID()] == true);
257 enqueuedBlocks[B->getBlockID()] = false;
258 return B;
Ted Kremenek610068c2011-01-15 02:58:47 +0000259}
260
261//------------------------------------------------------------------------====//
Richard Smith9532e0d2012-07-17 00:06:14 +0000262// Classification of DeclRefExprs as use or initialization.
Ted Kremenek610068c2011-01-15 02:58:47 +0000263//====------------------------------------------------------------------------//
264
Ted Kremenek610068c2011-01-15 02:58:47 +0000265namespace {
266class FindVarResult {
267 const VarDecl *vd;
268 const DeclRefExpr *dr;
269public:
Richard Smith9532e0d2012-07-17 00:06:14 +0000270 FindVarResult(const VarDecl *vd, const DeclRefExpr *dr) : vd(vd), dr(dr) {}
271
Ted Kremenek610068c2011-01-15 02:58:47 +0000272 const DeclRefExpr *getDeclRefExpr() const { return dr; }
273 const VarDecl *getDecl() const { return vd; }
274};
Richard Smith9532e0d2012-07-17 00:06:14 +0000275
276static const Expr *stripCasts(ASTContext &C, const Expr *Ex) {
277 while (Ex) {
278 Ex = Ex->IgnoreParenNoopCasts(C);
279 if (const CastExpr *CE = dyn_cast<CastExpr>(Ex)) {
280 if (CE->getCastKind() == CK_LValueBitCast) {
281 Ex = CE->getSubExpr();
282 continue;
283 }
284 }
285 break;
286 }
287 return Ex;
288}
289
290/// If E is an expression comprising a reference to a single variable, find that
291/// variable.
292static FindVarResult findVar(const Expr *E, const DeclContext *DC) {
293 if (const DeclRefExpr *DRE =
294 dyn_cast<DeclRefExpr>(stripCasts(DC->getParentASTContext(), E)))
295 if (const VarDecl *VD = dyn_cast<VarDecl>(DRE->getDecl()))
296 if (isTrackedVar(VD, DC))
297 return FindVarResult(VD, DRE);
298 return FindVarResult(0, 0);
299}
300
301/// \brief Classify each DeclRefExpr as an initialization or a use. Any
302/// DeclRefExpr which isn't explicitly classified will be assumed to have
303/// escaped the analysis and will be treated as an initialization.
304class ClassifyRefs : public StmtVisitor<ClassifyRefs> {
305public:
306 enum Class {
307 Init,
308 Use,
309 SelfInit,
310 Ignore
311 };
312
313private:
314 const DeclContext *DC;
315 llvm::DenseMap<const DeclRefExpr*, Class> Classification;
316
317 bool isTrackedVar(const VarDecl *VD) const {
318 return ::isTrackedVar(VD, DC);
319 }
320
321 void classify(const Expr *E, Class C);
322
323public:
324 ClassifyRefs(AnalysisDeclContext &AC) : DC(cast<DeclContext>(AC.getDecl())) {}
325
326 void VisitDeclStmt(DeclStmt *DS);
327 void VisitUnaryOperator(UnaryOperator *UO);
328 void VisitBinaryOperator(BinaryOperator *BO);
329 void VisitCallExpr(CallExpr *CE);
330 void VisitCastExpr(CastExpr *CE);
331
332 void operator()(Stmt *S) { Visit(S); }
333
334 Class get(const DeclRefExpr *DRE) const {
335 llvm::DenseMap<const DeclRefExpr*, Class>::const_iterator I
336 = Classification.find(DRE);
337 if (I != Classification.end())
338 return I->second;
339
340 const VarDecl *VD = dyn_cast<VarDecl>(DRE->getDecl());
341 if (!VD || !isTrackedVar(VD))
342 return Ignore;
343
344 return Init;
345 }
346};
347}
348
349static const DeclRefExpr *getSelfInitExpr(VarDecl *VD) {
350 if (Expr *Init = VD->getInit()) {
351 const DeclRefExpr *DRE
352 = dyn_cast<DeclRefExpr>(stripCasts(VD->getASTContext(), Init));
353 if (DRE && DRE->getDecl() == VD)
354 return DRE;
355 }
356 return 0;
357}
358
359void ClassifyRefs::classify(const Expr *E, Class C) {
Ted Kremenek77fd3c02013-01-19 00:25:06 +0000360 // The result of a ?: could also be an lvalue.
361 E = E->IgnoreParens();
362 if (const ConditionalOperator *CO = dyn_cast<ConditionalOperator>(E)) {
363 const Expr *TrueExpr = CO->getTrueExpr();
364 if (!isa<OpaqueValueExpr>(TrueExpr))
365 classify(TrueExpr, C);
366 classify(CO->getFalseExpr(), C);
367 return;
368 }
369
Richard Smith9532e0d2012-07-17 00:06:14 +0000370 FindVarResult Var = findVar(E, DC);
371 if (const DeclRefExpr *DRE = Var.getDeclRefExpr())
372 Classification[DRE] = std::max(Classification[DRE], C);
373}
374
375void ClassifyRefs::VisitDeclStmt(DeclStmt *DS) {
Stephen Hines651f13c2014-04-23 16:59:28 -0700376 for (auto *DI : DS->decls()) {
377 VarDecl *VD = dyn_cast<VarDecl>(DI);
Richard Smith9532e0d2012-07-17 00:06:14 +0000378 if (VD && isTrackedVar(VD))
379 if (const DeclRefExpr *DRE = getSelfInitExpr(VD))
380 Classification[DRE] = SelfInit;
381 }
382}
383
384void ClassifyRefs::VisitBinaryOperator(BinaryOperator *BO) {
385 // Ignore the evaluation of a DeclRefExpr on the LHS of an assignment. If this
386 // is not a compound-assignment, we will treat it as initializing the variable
387 // when TransferFunctions visits it. A compound-assignment does not affect
388 // whether a variable is uninitialized, and there's no point counting it as a
389 // use.
Richard Smith6cfa78f2012-07-17 01:27:33 +0000390 if (BO->isCompoundAssignmentOp())
391 classify(BO->getLHS(), Use);
392 else if (BO->getOpcode() == BO_Assign)
Richard Smith9532e0d2012-07-17 00:06:14 +0000393 classify(BO->getLHS(), Ignore);
394}
395
396void ClassifyRefs::VisitUnaryOperator(UnaryOperator *UO) {
397 // Increment and decrement are uses despite there being no lvalue-to-rvalue
398 // conversion.
399 if (UO->isIncrementDecrementOp())
400 classify(UO->getSubExpr(), Use);
401}
402
403void ClassifyRefs::VisitCallExpr(CallExpr *CE) {
404 // If a value is passed by const reference to a function, we should not assume
405 // that it is initialized by the call, and we conservatively do not assume
406 // that it is used.
407 for (CallExpr::arg_iterator I = CE->arg_begin(), E = CE->arg_end();
408 I != E; ++I)
409 if ((*I)->getType().isConstQualified() && (*I)->isGLValue())
410 classify(*I, Ignore);
411}
412
413void ClassifyRefs::VisitCastExpr(CastExpr *CE) {
414 if (CE->getCastKind() == CK_LValueToRValue)
415 classify(CE->getSubExpr(), Use);
416 else if (CStyleCastExpr *CSE = dyn_cast<CStyleCastExpr>(CE)) {
417 if (CSE->getType()->isVoidType()) {
418 // Squelch any detected load of an uninitialized value if
419 // we cast it to void.
420 // e.g. (void) x;
421 classify(CSE->getSubExpr(), Ignore);
422 }
423 }
424}
425
426//------------------------------------------------------------------------====//
427// Transfer function for uninitialized values analysis.
428//====------------------------------------------------------------------------//
429
430namespace {
Ted Kremenek0c8e5a02011-07-19 14:18:48 +0000431class TransferFunctions : public StmtVisitor<TransferFunctions> {
Ted Kremenek610068c2011-01-15 02:58:47 +0000432 CFGBlockValues &vals;
433 const CFG &cfg;
Richard Smith2815e1a2012-05-25 02:17:09 +0000434 const CFGBlock *block;
Ted Kremenek1d26f482011-10-24 01:32:45 +0000435 AnalysisDeclContext &ac;
Richard Smith9532e0d2012-07-17 00:06:14 +0000436 const ClassifyRefs &classification;
Ted Kremenek25c1d572012-09-13 00:21:35 +0000437 ObjCNoReturn objCNoRet;
Ted Kremenekeba76a42012-11-17 07:18:30 +0000438 UninitVariablesHandler &handler;
Richard Smith9532e0d2012-07-17 00:06:14 +0000439
Ted Kremenek610068c2011-01-15 02:58:47 +0000440public:
441 TransferFunctions(CFGBlockValues &vals, const CFG &cfg,
Richard Smith2815e1a2012-05-25 02:17:09 +0000442 const CFGBlock *block, AnalysisDeclContext &ac,
Richard Smith9532e0d2012-07-17 00:06:14 +0000443 const ClassifyRefs &classification,
Ted Kremenekeba76a42012-11-17 07:18:30 +0000444 UninitVariablesHandler &handler)
Richard Smith9532e0d2012-07-17 00:06:14 +0000445 : vals(vals), cfg(cfg), block(block), ac(ac),
Ted Kremenek25c1d572012-09-13 00:21:35 +0000446 classification(classification), objCNoRet(ac.getASTContext()),
447 handler(handler) {}
Richard Smith9532e0d2012-07-17 00:06:14 +0000448
Richard Smith81891882012-05-24 23:45:35 +0000449 void reportUse(const Expr *ex, const VarDecl *vd);
Ted Kremeneka8c17a52011-01-25 19:13:48 +0000450
Ted Kremenek25c1d572012-09-13 00:21:35 +0000451 void VisitBinaryOperator(BinaryOperator *bo);
Ted Kremeneka8c17a52011-01-25 19:13:48 +0000452 void VisitBlockExpr(BlockExpr *be);
Richard Smitha9e8b9e2012-07-02 23:23:04 +0000453 void VisitCallExpr(CallExpr *ce);
Ted Kremenekc21fed32011-01-18 21:18:58 +0000454 void VisitDeclRefExpr(DeclRefExpr *dr);
Ted Kremenek25c1d572012-09-13 00:21:35 +0000455 void VisitDeclStmt(DeclStmt *ds);
456 void VisitObjCForCollectionStmt(ObjCForCollectionStmt *FS);
457 void VisitObjCMessageExpr(ObjCMessageExpr *ME);
Richard Smith2815e1a2012-05-25 02:17:09 +0000458
Ted Kremenek40900ee2011-01-27 02:29:34 +0000459 bool isTrackedVar(const VarDecl *vd) {
460 return ::isTrackedVar(vd, cast<DeclContext>(ac.getDecl()));
461 }
Richard Smith2815e1a2012-05-25 02:17:09 +0000462
Richard Smith9532e0d2012-07-17 00:06:14 +0000463 FindVarResult findVar(const Expr *ex) {
464 return ::findVar(ex, cast<DeclContext>(ac.getDecl()));
465 }
466
Richard Smith2815e1a2012-05-25 02:17:09 +0000467 UninitUse getUninitUse(const Expr *ex, const VarDecl *vd, Value v) {
468 UninitUse Use(ex, isAlwaysUninit(v));
469
470 assert(isUninitialized(v));
471 if (Use.getKind() == UninitUse::Always)
472 return Use;
473
474 // If an edge which leads unconditionally to this use did not initialize
475 // the variable, we can say something stronger than 'may be uninitialized':
476 // we can say 'either it's used uninitialized or you have dead code'.
477 //
478 // We track the number of successors of a node which have been visited, and
479 // visit a node once we have visited all of its successors. Only edges where
480 // the variable might still be uninitialized are followed. Since a variable
481 // can't transfer from being initialized to being uninitialized, this will
482 // trace out the subgraph which inevitably leads to the use and does not
483 // initialize the variable. We do not want to skip past loops, since their
484 // non-termination might be correlated with the initialization condition.
485 //
486 // For example:
487 //
488 // void f(bool a, bool b) {
489 // block1: int n;
490 // if (a) {
491 // block2: if (b)
492 // block3: n = 1;
493 // block4: } else if (b) {
494 // block5: while (!a) {
495 // block6: do_work(&a);
496 // n = 2;
497 // }
498 // }
499 // block7: if (a)
500 // block8: g();
501 // block9: return n;
502 // }
503 //
504 // Starting from the maybe-uninitialized use in block 9:
505 // * Block 7 is not visited because we have only visited one of its two
506 // successors.
507 // * Block 8 is visited because we've visited its only successor.
508 // From block 8:
509 // * Block 7 is visited because we've now visited both of its successors.
510 // From block 7:
511 // * Blocks 1, 2, 4, 5, and 6 are not visited because we didn't visit all
512 // of their successors (we didn't visit 4, 3, 5, 6, and 5, respectively).
513 // * Block 3 is not visited because it initializes 'n'.
514 // Now the algorithm terminates, having visited blocks 7 and 8, and having
515 // found the frontier is blocks 2, 4, and 5.
516 //
517 // 'n' is definitely uninitialized for two edges into block 7 (from blocks 2
518 // and 4), so we report that any time either of those edges is taken (in
519 // each case when 'b == false'), 'n' is used uninitialized.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +0000520 SmallVector<const CFGBlock*, 32> Queue;
521 SmallVector<unsigned, 32> SuccsVisited(cfg.getNumBlockIDs(), 0);
Richard Smith2815e1a2012-05-25 02:17:09 +0000522 Queue.push_back(block);
523 // Specify that we've already visited all successors of the starting block.
524 // This has the dual purpose of ensuring we never add it to the queue, and
525 // of marking it as not being a candidate element of the frontier.
526 SuccsVisited[block->getBlockID()] = block->succ_size();
527 while (!Queue.empty()) {
Robert Wilhelm344472e2013-08-23 16:11:15 +0000528 const CFGBlock *B = Queue.pop_back_val();
Richard Smith8a1fdfc2013-09-12 18:49:10 +0000529
530 // If the use is always reached from the entry block, make a note of that.
531 if (B == &cfg.getEntry())
532 Use.setUninitAfterCall();
533
Richard Smith2815e1a2012-05-25 02:17:09 +0000534 for (CFGBlock::const_pred_iterator I = B->pred_begin(), E = B->pred_end();
535 I != E; ++I) {
536 const CFGBlock *Pred = *I;
Stephen Hines651f13c2014-04-23 16:59:28 -0700537 if (!Pred)
538 continue;
539
Richard Smith8a1fdfc2013-09-12 18:49:10 +0000540 Value AtPredExit = vals.getValue(Pred, B, vd);
541 if (AtPredExit == Initialized)
Richard Smith2815e1a2012-05-25 02:17:09 +0000542 // This block initializes the variable.
543 continue;
Richard Smith8a1fdfc2013-09-12 18:49:10 +0000544 if (AtPredExit == MayUninitialized &&
545 vals.getValue(B, 0, vd) == Uninitialized) {
546 // This block declares the variable (uninitialized), and is reachable
547 // from a block that initializes the variable. We can't guarantee to
548 // give an earlier location for the diagnostic (and it appears that
549 // this code is intended to be reachable) so give a diagnostic here
550 // and go no further down this path.
551 Use.setUninitAfterDecl();
552 continue;
553 }
Richard Smith2815e1a2012-05-25 02:17:09 +0000554
Richard Smith558e8872012-07-13 23:33:44 +0000555 unsigned &SV = SuccsVisited[Pred->getBlockID()];
556 if (!SV) {
557 // When visiting the first successor of a block, mark all NULL
558 // successors as having been visited.
559 for (CFGBlock::const_succ_iterator SI = Pred->succ_begin(),
560 SE = Pred->succ_end();
561 SI != SE; ++SI)
562 if (!*SI)
563 ++SV;
564 }
565
566 if (++SV == Pred->succ_size())
Richard Smith2815e1a2012-05-25 02:17:09 +0000567 // All paths from this block lead to the use and don't initialize the
568 // variable.
569 Queue.push_back(Pred);
570 }
571 }
572
573 // Scan the frontier, looking for blocks where the variable was
574 // uninitialized.
575 for (CFG::const_iterator BI = cfg.begin(), BE = cfg.end(); BI != BE; ++BI) {
576 const CFGBlock *Block = *BI;
577 unsigned BlockID = Block->getBlockID();
578 const Stmt *Term = Block->getTerminator();
579 if (SuccsVisited[BlockID] && SuccsVisited[BlockID] < Block->succ_size() &&
580 Term) {
581 // This block inevitably leads to the use. If we have an edge from here
582 // to a post-dominator block, and the variable is uninitialized on that
583 // edge, we have found a bug.
584 for (CFGBlock::const_succ_iterator I = Block->succ_begin(),
585 E = Block->succ_end(); I != E; ++I) {
586 const CFGBlock *Succ = *I;
587 if (Succ && SuccsVisited[Succ->getBlockID()] >= Succ->succ_size() &&
588 vals.getValue(Block, Succ, vd) == Uninitialized) {
589 // Switch cases are a special case: report the label to the caller
590 // as the 'terminator', not the switch statement itself. Suppress
591 // situations where no label matched: we can't be sure that's
592 // possible.
593 if (isa<SwitchStmt>(Term)) {
594 const Stmt *Label = Succ->getLabel();
595 if (!Label || !isa<SwitchCase>(Label))
596 // Might not be possible.
597 continue;
598 UninitUse::Branch Branch;
599 Branch.Terminator = Label;
600 Branch.Output = 0; // Ignored.
601 Use.addUninitBranch(Branch);
602 } else {
603 UninitUse::Branch Branch;
604 Branch.Terminator = Term;
605 Branch.Output = I - Block->succ_begin();
606 Use.addUninitBranch(Branch);
607 }
608 }
609 }
610 }
611 }
612
613 return Use;
614 }
Ted Kremenek610068c2011-01-15 02:58:47 +0000615};
616}
617
Richard Smith81891882012-05-24 23:45:35 +0000618void TransferFunctions::reportUse(const Expr *ex, const VarDecl *vd) {
Richard Smith81891882012-05-24 23:45:35 +0000619 Value v = vals[vd];
620 if (isUninitialized(v))
Ted Kremenekeba76a42012-11-17 07:18:30 +0000621 handler.handleUseOfUninitVariable(vd, getUninitUse(ex, vd, v));
Ted Kremenek610068c2011-01-15 02:58:47 +0000622}
623
Richard Smith9532e0d2012-07-17 00:06:14 +0000624void TransferFunctions::VisitObjCForCollectionStmt(ObjCForCollectionStmt *FS) {
Ted Kremenek1ea800c2011-01-27 02:01:31 +0000625 // This represents an initialization of the 'element' value.
Richard Smith9532e0d2012-07-17 00:06:14 +0000626 if (DeclStmt *DS = dyn_cast<DeclStmt>(FS->getElement())) {
627 const VarDecl *VD = cast<VarDecl>(DS->getSingleDecl());
628 if (isTrackedVar(VD))
629 vals[VD] = Initialized;
Ted Kremenek1ea800c2011-01-27 02:01:31 +0000630 }
Ted Kremenek1ea800c2011-01-27 02:01:31 +0000631}
632
Ted Kremeneka8c17a52011-01-25 19:13:48 +0000633void TransferFunctions::VisitBlockExpr(BlockExpr *be) {
Ted Kremenekbc8b44c2011-03-31 22:32:41 +0000634 const BlockDecl *bd = be->getBlockDecl();
Stephen Hines651f13c2014-04-23 16:59:28 -0700635 for (const auto &I : bd->captures()) {
636 const VarDecl *vd = I.getVariable();
Ted Kremenekbc8b44c2011-03-31 22:32:41 +0000637 if (!isTrackedVar(vd))
638 continue;
Stephen Hines651f13c2014-04-23 16:59:28 -0700639 if (I.isByRef()) {
Ted Kremenekbc8b44c2011-03-31 22:32:41 +0000640 vals[vd] = Initialized;
641 continue;
642 }
Richard Smith81891882012-05-24 23:45:35 +0000643 reportUse(be, vd);
Ted Kremeneka8c17a52011-01-25 19:13:48 +0000644 }
645}
646
Richard Smitha9e8b9e2012-07-02 23:23:04 +0000647void TransferFunctions::VisitCallExpr(CallExpr *ce) {
Ted Kremenek44ca53f2012-09-12 05:53:43 +0000648 if (Decl *Callee = ce->getCalleeDecl()) {
649 if (Callee->hasAttr<ReturnsTwiceAttr>()) {
650 // After a call to a function like setjmp or vfork, any variable which is
651 // initialized anywhere within this function may now be initialized. For
652 // now, just assume such a call initializes all variables. FIXME: Only
653 // mark variables as initialized if they have an initializer which is
654 // reachable from here.
655 vals.setAllScratchValues(Initialized);
656 }
657 else if (Callee->hasAttr<AnalyzerNoReturnAttr>()) {
658 // Functions labeled like "analyzer_noreturn" are often used to denote
659 // "panic" functions that in special debug situations can still return,
660 // but for the most part should not be treated as returning. This is a
661 // useful annotation borrowed from the static analyzer that is useful for
662 // suppressing branch-specific false positives when we call one of these
663 // functions but keep pretending the path continues (when in reality the
664 // user doesn't care).
665 vals.setAllScratchValues(Unknown);
666 }
667 }
Richard Smitha9e8b9e2012-07-02 23:23:04 +0000668}
669
Ted Kremenek0c8e5a02011-07-19 14:18:48 +0000670void TransferFunctions::VisitDeclRefExpr(DeclRefExpr *dr) {
Richard Smith9532e0d2012-07-17 00:06:14 +0000671 switch (classification.get(dr)) {
672 case ClassifyRefs::Ignore:
673 break;
674 case ClassifyRefs::Use:
675 reportUse(dr, cast<VarDecl>(dr->getDecl()));
676 break;
677 case ClassifyRefs::Init:
678 vals[cast<VarDecl>(dr->getDecl())] = Initialized;
679 break;
680 case ClassifyRefs::SelfInit:
Ted Kremenekeba76a42012-11-17 07:18:30 +0000681 handler.handleSelfInit(cast<VarDecl>(dr->getDecl()));
Richard Smith9532e0d2012-07-17 00:06:14 +0000682 break;
683 }
Ted Kremenek0c8e5a02011-07-19 14:18:48 +0000684}
685
Richard Smith9532e0d2012-07-17 00:06:14 +0000686void TransferFunctions::VisitBinaryOperator(BinaryOperator *BO) {
687 if (BO->getOpcode() == BO_Assign) {
688 FindVarResult Var = findVar(BO->getLHS());
689 if (const VarDecl *VD = Var.getDecl())
690 vals[VD] = Initialized;
691 }
692}
693
694void TransferFunctions::VisitDeclStmt(DeclStmt *DS) {
Stephen Hines651f13c2014-04-23 16:59:28 -0700695 for (auto *DI : DS->decls()) {
696 VarDecl *VD = dyn_cast<VarDecl>(DI);
Richard Smith9532e0d2012-07-17 00:06:14 +0000697 if (VD && isTrackedVar(VD)) {
698 if (getSelfInitExpr(VD)) {
699 // If the initializer consists solely of a reference to itself, we
700 // explicitly mark the variable as uninitialized. This allows code
701 // like the following:
702 //
703 // int x = x;
704 //
705 // to deliberately leave a variable uninitialized. Different analysis
706 // clients can detect this pattern and adjust their reporting
707 // appropriately, but we need to continue to analyze subsequent uses
708 // of the variable.
709 vals[VD] = Uninitialized;
710 } else if (VD->getInit()) {
711 // Treat the new variable as initialized.
712 vals[VD] = Initialized;
713 } else {
714 // No initializer: the variable is now uninitialized. This matters
715 // for cases like:
716 // while (...) {
717 // int n;
718 // use(n);
719 // n = 0;
720 // }
721 // FIXME: Mark the variable as uninitialized whenever its scope is
722 // left, since its scope could be re-entered by a jump over the
723 // declaration.
724 vals[VD] = Uninitialized;
Ted Kremenekc21fed32011-01-18 21:18:58 +0000725 }
Ted Kremenek610068c2011-01-15 02:58:47 +0000726 }
727 }
728}
729
Ted Kremenek25c1d572012-09-13 00:21:35 +0000730void TransferFunctions::VisitObjCMessageExpr(ObjCMessageExpr *ME) {
731 // If the Objective-C message expression is an implicit no-return that
732 // is not modeled in the CFG, set the tracked dataflow values to Unknown.
733 if (objCNoRet.isImplicitNoReturn(ME)) {
734 vals.setAllScratchValues(Unknown);
735 }
736}
737
Ted Kremenek610068c2011-01-15 02:58:47 +0000738//------------------------------------------------------------------------====//
739// High-level "driver" logic for uninitialized values analysis.
740//====------------------------------------------------------------------------//
741
Ted Kremenek13bd4232011-01-20 17:37:17 +0000742static bool runOnBlock(const CFGBlock *block, const CFG &cfg,
Ted Kremenek1d26f482011-10-24 01:32:45 +0000743 AnalysisDeclContext &ac, CFGBlockValues &vals,
Richard Smith9532e0d2012-07-17 00:06:14 +0000744 const ClassifyRefs &classification,
Ted Kremenekf8adeef2011-04-04 20:30:58 +0000745 llvm::BitVector &wasAnalyzed,
Ted Kremenekeba76a42012-11-17 07:18:30 +0000746 UninitVariablesHandler &handler) {
Ted Kremenekf8adeef2011-04-04 20:30:58 +0000747 wasAnalyzed[block->getBlockID()] = true;
Ted Kremenek610068c2011-01-15 02:58:47 +0000748 vals.resetScratch();
Ted Kremenekeee18c32012-07-19 04:59:05 +0000749 // Merge in values of predecessor blocks.
Ted Kremenek610068c2011-01-15 02:58:47 +0000750 bool isFirst = true;
751 for (CFGBlock::const_pred_iterator I = block->pred_begin(),
752 E = block->pred_end(); I != E; ++I) {
Ted Kremenek6f275422011-09-02 19:39:26 +0000753 const CFGBlock *pred = *I;
Stephen Hines651f13c2014-04-23 16:59:28 -0700754 if (!pred)
755 continue;
Ted Kremenek6f275422011-09-02 19:39:26 +0000756 if (wasAnalyzed[pred->getBlockID()]) {
Ted Kremenekeee18c32012-07-19 04:59:05 +0000757 vals.mergeIntoScratch(vals.getValueVector(pred), isFirst);
Ted Kremenek6f275422011-09-02 19:39:26 +0000758 isFirst = false;
759 }
Ted Kremenek610068c2011-01-15 02:58:47 +0000760 }
761 // Apply the transfer function.
Richard Smith9532e0d2012-07-17 00:06:14 +0000762 TransferFunctions tf(vals, cfg, block, ac, classification, handler);
Ted Kremenek610068c2011-01-15 02:58:47 +0000763 for (CFGBlock::const_iterator I = block->begin(), E = block->end();
764 I != E; ++I) {
David Blaikieb0780542013-02-23 00:29:34 +0000765 if (Optional<CFGStmt> cs = I->getAs<CFGStmt>())
766 tf.Visit(const_cast<Stmt*>(cs->getStmt()));
Ted Kremenek610068c2011-01-15 02:58:47 +0000767 }
Ted Kremenek136f8f22011-03-15 04:57:27 +0000768 return vals.updateValueVectorWithScratch(block);
Ted Kremenek610068c2011-01-15 02:58:47 +0000769}
770
Ted Kremenekeba76a42012-11-17 07:18:30 +0000771/// PruneBlocksHandler is a special UninitVariablesHandler that is used
772/// to detect when a CFGBlock has any *potential* use of an uninitialized
773/// variable. It is mainly used to prune out work during the final
774/// reporting pass.
775namespace {
776struct PruneBlocksHandler : public UninitVariablesHandler {
777 PruneBlocksHandler(unsigned numBlocks)
778 : hadUse(numBlocks, false), hadAnyUse(false),
779 currentBlock(0) {}
780
781 virtual ~PruneBlocksHandler() {}
782
783 /// Records if a CFGBlock had a potential use of an uninitialized variable.
784 llvm::BitVector hadUse;
785
786 /// Records if any CFGBlock had a potential use of an uninitialized variable.
787 bool hadAnyUse;
788
789 /// The current block to scribble use information.
790 unsigned currentBlock;
791
Stephen Hines651f13c2014-04-23 16:59:28 -0700792 void handleUseOfUninitVariable(const VarDecl *vd,
793 const UninitUse &use) override {
Ted Kremenekeba76a42012-11-17 07:18:30 +0000794 hadUse[currentBlock] = true;
795 hadAnyUse = true;
796 }
797
798 /// Called when the uninitialized variable analysis detects the
799 /// idiom 'int x = x'. All other uses of 'x' within the initializer
800 /// are handled by handleUseOfUninitVariable.
Stephen Hines651f13c2014-04-23 16:59:28 -0700801 void handleSelfInit(const VarDecl *vd) override {
Ted Kremenekeba76a42012-11-17 07:18:30 +0000802 hadUse[currentBlock] = true;
803 hadAnyUse = true;
804 }
805};
806}
807
Chandler Carruth5d989942011-07-06 16:21:37 +0000808void clang::runUninitializedVariablesAnalysis(
809 const DeclContext &dc,
810 const CFG &cfg,
Ted Kremenek1d26f482011-10-24 01:32:45 +0000811 AnalysisDeclContext &ac,
Chandler Carruth5d989942011-07-06 16:21:37 +0000812 UninitVariablesHandler &handler,
813 UninitVariablesAnalysisStats &stats) {
Ted Kremenek610068c2011-01-15 02:58:47 +0000814 CFGBlockValues vals(cfg);
815 vals.computeSetOfDeclarations(dc);
816 if (vals.hasNoDeclarations())
817 return;
Ted Kremenekd40066b2011-04-04 23:29:12 +0000818
Chandler Carruth5d989942011-07-06 16:21:37 +0000819 stats.NumVariablesAnalyzed = vals.getNumEntries();
820
Richard Smith9532e0d2012-07-17 00:06:14 +0000821 // Precompute which expressions are uses and which are initializations.
822 ClassifyRefs classification(ac);
823 cfg.VisitBlockStmts(classification);
824
Ted Kremenekd40066b2011-04-04 23:29:12 +0000825 // Mark all variables uninitialized at the entry.
826 const CFGBlock &entry = cfg.getEntry();
Ted Kremenekeee18c32012-07-19 04:59:05 +0000827 ValueVector &vec = vals.getValueVector(&entry);
828 const unsigned n = vals.getNumEntries();
829 for (unsigned j = 0; j < n ; ++j) {
830 vec[j] = Uninitialized;
Ted Kremenekd40066b2011-04-04 23:29:12 +0000831 }
832
833 // Proceed with the workist.
Ted Kremenekc1602582012-11-17 02:00:00 +0000834 DataflowWorklist worklist(cfg, *ac.getAnalysis<PostOrderCFGView>());
Ted Kremenek496398d2011-03-15 04:57:32 +0000835 llvm::BitVector previouslyVisited(cfg.getNumBlockIDs());
Ted Kremenek610068c2011-01-15 02:58:47 +0000836 worklist.enqueueSuccessors(&cfg.getEntry());
Ted Kremenekf8adeef2011-04-04 20:30:58 +0000837 llvm::BitVector wasAnalyzed(cfg.getNumBlockIDs(), false);
Ted Kremenek6f275422011-09-02 19:39:26 +0000838 wasAnalyzed[cfg.getEntry().getBlockID()] = true;
Ted Kremenekeba76a42012-11-17 07:18:30 +0000839 PruneBlocksHandler PBH(cfg.getNumBlockIDs());
Ted Kremenek610068c2011-01-15 02:58:47 +0000840
841 while (const CFGBlock *block = worklist.dequeue()) {
Ted Kremenekeba76a42012-11-17 07:18:30 +0000842 PBH.currentBlock = block->getBlockID();
843
Ted Kremenek610068c2011-01-15 02:58:47 +0000844 // Did the block change?
Richard Smith9532e0d2012-07-17 00:06:14 +0000845 bool changed = runOnBlock(block, cfg, ac, vals,
Ted Kremenekeba76a42012-11-17 07:18:30 +0000846 classification, wasAnalyzed, PBH);
Chandler Carruth5d989942011-07-06 16:21:37 +0000847 ++stats.NumBlockVisits;
Ted Kremenek610068c2011-01-15 02:58:47 +0000848 if (changed || !previouslyVisited[block->getBlockID()])
849 worklist.enqueueSuccessors(block);
850 previouslyVisited[block->getBlockID()] = true;
851 }
Ted Kremenekeba76a42012-11-17 07:18:30 +0000852
853 if (!PBH.hadAnyUse)
854 return;
855
Enea Zaffanella67d472c2013-01-11 11:37:08 +0000856 // Run through the blocks one more time, and report uninitialized variables.
Ted Kremenek610068c2011-01-15 02:58:47 +0000857 for (CFG::const_iterator BI = cfg.begin(), BE = cfg.end(); BI != BE; ++BI) {
Ted Kremenek6f275422011-09-02 19:39:26 +0000858 const CFGBlock *block = *BI;
Ted Kremenekeba76a42012-11-17 07:18:30 +0000859 if (PBH.hadUse[block->getBlockID()]) {
860 runOnBlock(block, cfg, ac, vals, classification, wasAnalyzed, handler);
Chandler Carruth5d989942011-07-06 16:21:37 +0000861 ++stats.NumBlockVisits;
862 }
Ted Kremenek610068c2011-01-15 02:58:47 +0000863 }
864}
865
866UninitVariablesHandler::~UninitVariablesHandler() {}