]> granicus.if.org Git - clang/commitdiff
Fixed logic error in UnreachableCodeChecker's marking algorithm that would sometimes...
authorTom Care <tcare@apple.com>
Thu, 5 Aug 2010 17:53:44 +0000 (17:53 +0000)
committerTom Care <tcare@apple.com>
Thu, 5 Aug 2010 17:53:44 +0000 (17:53 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@110353 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Checker/UnreachableCodeChecker.cpp
test/Analysis/unreachable-code-path.c

index a84a3a5603980549da0dd1f87d8de127573d0ddd..432967e00c2b9bf0a48ebf07e7a45ec9dca0e324 100644 (file)
@@ -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);
     }
   }
 
index 00987ddbb095e4d2fca4915e982bc6fa1e37eec9..071532739cbe749f205bcdd097c961d3347bd932 100644 (file)
@@ -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;
+  }
+}