diff options
-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; + } +} |