From 0600918d1418c2eac2c96491637946206009c4de Mon Sep 17 00:00:00 2001 From: Tom Care Date: Thu, 5 Aug 2010 17:53:44 +0000 Subject: [PATCH] Fixed logic error in UnreachableCodeChecker's marking algorithm that would sometimes allow for multiple sequential statements to be flagged. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@110353 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Checker/UnreachableCodeChecker.cpp | 9 ++++++--- test/Analysis/unreachable-code-path.c | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/Checker/UnreachableCodeChecker.cpp b/lib/Checker/UnreachableCodeChecker.cpp index a84a3a5603..432967e00c 100644 --- a/lib/Checker/UnreachableCodeChecker.cpp +++ b/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/test/Analysis/unreachable-code-path.c b/test/Analysis/unreachable-code-path.c index 00987ddbb0..071532739c 100644 --- a/test/Analysis/unreachable-code-path.c +++ b/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; + } +} -- 2.40.0