aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/UninitializedValuesV2.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2011-01-18 04:53:25 +0000
committerTed Kremenek <kremenek@apple.com>2011-01-18 04:53:25 +0000
commitc104e53639de4424b83955acfadc977773b5883d (patch)
treed8f8af9af06230eba1ff1f990e321ddf5c9a2915 /lib/Analysis/UninitializedValuesV2.cpp
parent8691e0ba6c1f4b72d1b65224304773647950c644 (diff)
Teach UninitializedValuesV2 about "int x = x" and
also properly handle confluence of loops. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123733 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/UninitializedValuesV2.cpp')
-rw-r--r--lib/Analysis/UninitializedValuesV2.cpp22
1 files changed, 14 insertions, 8 deletions
diff --git a/lib/Analysis/UninitializedValuesV2.cpp b/lib/Analysis/UninitializedValuesV2.cpp
index 209b18c045..3c833cb67b 100644
--- a/lib/Analysis/UninitializedValuesV2.cpp
+++ b/lib/Analysis/UninitializedValuesV2.cpp
@@ -22,6 +22,11 @@
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.
//====------------------------------------------------------------------------//
@@ -49,7 +54,7 @@ void DeclToBit::computeMap(const DeclContext &dc) {
E(dc.decls_end());
for ( ; I != E; ++I) {
const VarDecl *vd = *I;
- if (vd->isLocalVarDecl() && !vd->hasGlobalStorage())
+ if (isTrackedVar(vd))
map[vd] = count++;
}
}
@@ -126,7 +131,7 @@ void CFGBlockValues::mergeIntoScratch(llvm::BitVector const &source,
if (isFirst)
scratch = source;
else
- scratch &= source;
+ scratch |= source;
}
bool CFGBlockValues::updateBitVectorWithScratch(const CFGBlock *block) {
@@ -166,6 +171,8 @@ public:
}
void DataflowWorklist::enqueue(const CFGBlock *block) {
+ if (!block)
+ return;
unsigned idx = block->getBlockID();
if (enqueuedBlocks[idx])
return;
@@ -193,8 +200,8 @@ const CFGBlock *DataflowWorklist::dequeue() {
// 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 {
@@ -235,12 +242,11 @@ void TransferFunctions::VisitDeclStmt(DeclStmt *ds) {
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;
}
- }
}
}
}
@@ -248,7 +254,7 @@ void TransferFunctions::VisitDeclStmt(DeclStmt *ds) {
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);