using namespace clang;
+static bool isTrackedVar(const VarDecl *vd) {
+ return vd->isLocalVarDecl() && !vd->hasGlobalStorage() &&
+ vd->getType()->isScalarType();
+}
+
//------------------------------------------------------------------------====//
// DeclToBit: a mapping from Decls we track to bitvector indices.
//====------------------------------------------------------------------------//
E(dc.decls_end());
for ( ; I != E; ++I) {
const VarDecl *vd = *I;
- if (vd->isLocalVarDecl() && !vd->hasGlobalStorage())
+ if (isTrackedVar(vd))
map[vd] = count++;
}
}
if (isFirst)
scratch = source;
else
- scratch &= source;
+ scratch |= source;
}
bool CFGBlockValues::updateBitVectorWithScratch(const CFGBlock *block) {
}
void DataflowWorklist::enqueue(const CFGBlock *block) {
+ if (!block)
+ return;
unsigned idx = block->getBlockID();
if (enqueuedBlocks[idx])
return;
// Transfer function for uninitialized values analysis.
//====------------------------------------------------------------------------//
-static const bool Initialized = true;
-static const bool Uninitialized = false;
+static const bool Initialized = false;
+static const bool Uninitialized = true;
namespace {
class FindVarResult {
for (DeclStmt::decl_iterator DI = ds->decl_begin(), DE = ds->decl_end();
DI != DE; ++DI) {
if (VarDecl *vd = dyn_cast<VarDecl>(*DI)) {
- if (vd->isLocalVarDecl() && !vd->hasGlobalStorage()) {
+ if (isTrackedVar(vd))
if (Stmt *init = vd->getInit()) {
- vals[vd] = Initialized;
Visit(init);
+ vals[vd] = Initialized;
}
- }
}
}
}
static FindVarResult findBlockVarDecl(Expr* ex) {
if (DeclRefExpr* dr = dyn_cast<DeclRefExpr>(ex->IgnoreParenCasts()))
if (VarDecl *vd = dyn_cast<VarDecl>(dr->getDecl()))
- if (vd->isLocalVarDecl() && !vd->hasGlobalStorage())
+ if (isTrackedVar(vd))
return FindVarResult(vd, dr);
return FindVarResult(0, 0);
return i; // no-warning
}
+// Simply don't crash on this test case.
+void test14() {
+ const char *p = 0;
+ for (;;) {}
+}
+
+void test15() {
+ int x = x; // expected-warning{{use of uninitialized variable 'x'}}
+}
+// Don't warn in the following example; shows dataflow confluence.
+char *test16_aux();
+void test16() {
+ char *p = test16_aux();
+ for (unsigned i = 0 ; i < 100 ; i++)
+ p[i] = 'a'; // no-warning
+}