diff options
author | Tom Care <tcare@apple.com> | 2010-08-05 17:53:44 +0000 |
---|---|---|
committer | Tom Care <tcare@apple.com> | 2010-08-05 17:53:44 +0000 |
commit | 16ba7c652e76acc0beea8a87bee912dc93413a6b (patch) | |
tree | cb3f97a2a4282197273d370ecc7163c4d8124ca0 /clang | |
parent | a9731a41796617623afb795564971d9b808ee331 (diff) | |
download | bcm5719-llvm-16ba7c652e76acc0beea8a87bee912dc93413a6b.tar.gz bcm5719-llvm-16ba7c652e76acc0beea8a87bee912dc93413a6b.zip |
Fixed logic error in UnreachableCodeChecker's marking algorithm that would sometimes allow for multiple sequential statements to be flagged.
llvm-svn: 110353
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/Checker/UnreachableCodeChecker.cpp | 9 | ||||
-rw-r--r-- | clang/test/Analysis/unreachable-code-path.c | 14 |
2 files changed, 20 insertions, 3 deletions
diff --git a/clang/lib/Checker/UnreachableCodeChecker.cpp b/clang/lib/Checker/UnreachableCodeChecker.cpp index a84a3a56039..432967e00c2 100644 --- a/clang/lib/Checker/UnreachableCodeChecker.cpp +++ b/clang/lib/Checker/UnreachableCodeChecker.cpp @@ -149,10 +149,13 @@ void UnreachableCodeChecker::FindUnreachableEntryPoints(const CFGBlock *CB) { for (CFGBlock::const_pred_iterator I = CB->pred_begin(); I != CB->pred_end(); ++I) { // Recurse over all unreachable blocks - if (!reachable.count((*I)->getBlockID()) - && !visited.count((*I)->getBlockID())) { - FindUnreachableEntryPoints(*I); + if (!reachable.count((*I)->getBlockID())) { + // At least one predeccessor was unreachable allPredecessorsReachable = false; + + // Only visit the block once + if (!visited.count((*I)->getBlockID())) + FindUnreachableEntryPoints(*I); } } diff --git a/clang/test/Analysis/unreachable-code-path.c b/clang/test/Analysis/unreachable-code-path.c index 00987ddbb09..071532739cb 100644 --- a/clang/test/Analysis/unreachable-code-path.c +++ b/clang/test/Analysis/unreachable-code-path.c @@ -88,3 +88,17 @@ void test8() { a = 5; } +// Check for bugs where multiple statements are reported +void test9(unsigned a) { + switch (a) { + if (a) // expected-warning{{never executed}} + foo(a + 5); // no-warning + else // no-warning + foo(a); // no-warning + case 1: + case 2: + break; + default: + break; + } +} |