Hi rsmith, doug.gregor,

It's unlikely that a fallthrough is unintended in the following code:
switch (n) {
...
  label:
  case 1:
...
    goto label;
...
}

http://llvm-reviews.chandlerc.com/D329

Files:
  lib/Sema/AnalysisBasedWarnings.cpp
  test/SemaCXX/switch-implicit-fallthrough.cpp

Index: lib/Sema/AnalysisBasedWarnings.cpp
===================================================================
--- lib/Sema/AnalysisBasedWarnings.cpp
+++ lib/Sema/AnalysisBasedWarnings.cpp
@@ -722,6 +722,10 @@
         if (SW && SW->getSubStmt() == B.getLabel() && P->begin() == P->end())
           continue; // Previous case label has no statements, good.
 
+        const LabelStmt *L = dyn_cast_or_null<LabelStmt>(P->getLabel());
+        if (L && L->getSubStmt() == B.getLabel() && P->begin() == P->end())
+          continue; // Case label is preceded with a normal label, good.
+
         if (P->pred_begin() == P->pred_end()) {  // The block is unreachable.
           // This only catches trivially unreachable blocks.
           for (CFGBlock::const_iterator ElIt = P->begin(), ElEnd = P->end();
Index: test/SemaCXX/switch-implicit-fallthrough.cpp
===================================================================
--- test/SemaCXX/switch-implicit-fallthrough.cpp
+++ test/SemaCXX/switch-implicit-fallthrough.cpp
@@ -38,6 +38,18 @@
     case 68:
       break;
   }
+  switch (n / 15) {
+label_case_70:
+    case 70:
+      n += 333;
+      break;
+    case 71:
+      n += 334;
+      goto label_case_70;
+    case 72:
+      n += 335;
+      break;
+  }
   switch (n / 20) {
     case 7:
       n += 400;
Index: lib/Sema/AnalysisBasedWarnings.cpp
===================================================================
--- lib/Sema/AnalysisBasedWarnings.cpp
+++ lib/Sema/AnalysisBasedWarnings.cpp
@@ -722,6 +722,10 @@
         if (SW && SW->getSubStmt() == B.getLabel() && P->begin() == P->end())
           continue; // Previous case label has no statements, good.
 
+        const LabelStmt *L = dyn_cast_or_null<LabelStmt>(P->getLabel());
+        if (L && L->getSubStmt() == B.getLabel() && P->begin() == P->end())
+          continue; // Case label is preceded with a normal label, good.
+
         if (P->pred_begin() == P->pred_end()) {  // The block is unreachable.
           // This only catches trivially unreachable blocks.
           for (CFGBlock::const_iterator ElIt = P->begin(), ElEnd = P->end();
Index: test/SemaCXX/switch-implicit-fallthrough.cpp
===================================================================
--- test/SemaCXX/switch-implicit-fallthrough.cpp
+++ test/SemaCXX/switch-implicit-fallthrough.cpp
@@ -38,6 +38,18 @@
     case 68:
       break;
   }
+  switch (n / 15) {
+label_case_70:
+    case 70:
+      n += 333;
+      break;
+    case 71:
+      n += 334;
+      goto label_case_70;
+    case 72:
+      n += 335;
+      break;
+  }
   switch (n / 20) {
     case 7:
       n += 400;
_______________________________________________
cfe-commits mailing list
cfe-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to