diff options
| author | Richard Smith <richard-llvm@metafoo.co.uk> | 2013-09-12 18:49:10 +0000 |
|---|---|---|
| committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2013-09-12 18:49:10 +0000 |
| commit | ba8071ec81eb5c39f8ebb869a18181a1ed25c782 (patch) | |
| tree | c186ec14ec3cd2de5ac5930e7d63b6c3a7ccf8c0 /clang/lib/Analysis | |
| parent | 16a4d8c15d873a5d19338a13004e6086bb7a3d45 (diff) | |
| download | bcm5719-llvm-ba8071ec81eb5c39f8ebb869a18181a1ed25c782.tar.gz bcm5719-llvm-ba8071ec81eb5c39f8ebb869a18181a1ed25c782.zip | |
PR16054: Slight strengthening for -Wsometimes-uninitialized: if we use a
variable uninitialized every time we reach its (reachable) declaration, or
every time we call the surrounding function, promote the warning from
-Wmaybe-uninitialized to -Wsometimes-uninitialized.
This is still slightly weaker than desired: we should, in general, warn
if a use is uninitialized the first time it is evaluated.
llvm-svn: 190623
Diffstat (limited to 'clang/lib/Analysis')
| -rw-r--r-- | clang/lib/Analysis/UninitializedValues.cpp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/clang/lib/Analysis/UninitializedValues.cpp b/clang/lib/Analysis/UninitializedValues.cpp index 6c6804fe9eb..332c02cf185 100644 --- a/clang/lib/Analysis/UninitializedValues.cpp +++ b/clang/lib/Analysis/UninitializedValues.cpp @@ -527,12 +527,28 @@ public: SuccsVisited[block->getBlockID()] = block->succ_size(); while (!Queue.empty()) { const CFGBlock *B = Queue.pop_back_val(); + + // If the use is always reached from the entry block, make a note of that. + if (B == &cfg.getEntry()) + Use.setUninitAfterCall(); + for (CFGBlock::const_pred_iterator I = B->pred_begin(), E = B->pred_end(); I != E; ++I) { const CFGBlock *Pred = *I; - if (vals.getValue(Pred, B, vd) == Initialized) + Value AtPredExit = vals.getValue(Pred, B, vd); + if (AtPredExit == Initialized) // This block initializes the variable. continue; + if (AtPredExit == MayUninitialized && + vals.getValue(B, 0, vd) == Uninitialized) { + // This block declares the variable (uninitialized), and is reachable + // from a block that initializes the variable. We can't guarantee to + // give an earlier location for the diagnostic (and it appears that + // this code is intended to be reachable) so give a diagnostic here + // and go no further down this path. + Use.setUninitAfterDecl(); + continue; + } unsigned &SV = SuccsVisited[Pred->getBlockID()]; if (!SV) { |

