aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/UninitializedValues.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2011-04-04 20:30:58 +0000
committerTed Kremenek <kremenek@apple.com>2011-04-04 20:30:58 +0000
commitf8adeefa9e9882bff402e092024dd457f8574673 (patch)
tree3058605ba5d49ddc2ce05a2db7411faa5690001f /lib/Analysis/UninitializedValues.cpp
parent5360c921a91dc43b442f069ba86d7b9df66362fc (diff)
-Wuninitialized: don't warn about uninitialized variables in unreachable code.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@128840 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/UninitializedValues.cpp')
-rw-r--r--lib/Analysis/UninitializedValues.cpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/Analysis/UninitializedValues.cpp b/lib/Analysis/UninitializedValues.cpp
index 58191ec0b0..f775cc5b50 100644
--- a/lib/Analysis/UninitializedValues.cpp
+++ b/lib/Analysis/UninitializedValues.cpp
@@ -156,6 +156,8 @@ public:
return declToIndex.getValueIndex(vd).hasValue();
}
+ bool hasValues(const CFGBlock *block);
+
void resetScratch();
ValueVector &getScratch() { return scratch; }
@@ -231,6 +233,11 @@ ValueVector &CFGBlockValues::getValueVector(const CFGBlock *block,
return lazyCreate(vals[idx].first);
}
+bool CFGBlockValues::hasValues(const CFGBlock *block) {
+ unsigned idx = block->getBlockID();
+ return vals[idx].second != 0;
+}
+
BVPair &CFGBlockValues::getValueVectors(const clang::CFGBlock *block,
bool shouldLazyCreate) {
unsigned idx = block->getBlockID();
@@ -603,9 +610,12 @@ void TransferFunctions::VisitUnaryExprOrTypeTraitExpr(
static bool runOnBlock(const CFGBlock *block, const CFG &cfg,
AnalysisContext &ac, CFGBlockValues &vals,
+ llvm::BitVector &wasAnalyzed,
UninitVariablesHandler *handler = 0,
bool flagBlockUses = false) {
+ wasAnalyzed[block->getBlockID()] = true;
+
if (const BinaryOperator *b = getLogicalOperatorInChain(block)) {
CFGBlock::const_pred_iterator itr = block->pred_begin();
BVPair vA = vals.getValueVectors(*itr, false);
@@ -663,10 +673,11 @@ void clang::runUninitializedVariablesAnalysis(const DeclContext &dc,
llvm::BitVector previouslyVisited(cfg.getNumBlockIDs());
worklist.enqueueSuccessors(&cfg.getEntry());
+ llvm::BitVector wasAnalyzed(cfg.getNumBlockIDs(), false);
while (const CFGBlock *block = worklist.dequeue()) {
// Did the block change?
- bool changed = runOnBlock(block, cfg, ac, vals);
+ bool changed = runOnBlock(block, cfg, ac, vals, wasAnalyzed);
if (changed || !previouslyVisited[block->getBlockID()])
worklist.enqueueSuccessors(block);
previouslyVisited[block->getBlockID()] = true;
@@ -674,7 +685,9 @@ void clang::runUninitializedVariablesAnalysis(const DeclContext &dc,
// Run through the blocks one more time, and report uninitialized variabes.
for (CFG::const_iterator BI = cfg.begin(), BE = cfg.end(); BI != BE; ++BI) {
- runOnBlock(*BI, cfg, ac, vals, &handler, /* flagBlockUses */ true);
+ if (wasAnalyzed[(*BI)->getBlockID()])
+ runOnBlock(*BI, cfg, ac, vals, wasAnalyzed, &handler,
+ /* flagBlockUses */ true);
}
}