re PR c/79152 (-Wimplicit-fallthrough false positive triggered by goto statements)
authorMarek Polacek <polacek@redhat.com>
Fri, 20 Jan 2017 16:28:16 +0000 (16:28 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Fri, 20 Jan 2017 16:28:16 +0000 (16:28 +0000)
PR c/79152
* gimplify.c (should_warn_for_implicit_fallthrough): Handle consecutive
non-case labels.

* c-c++-common/Wimplicit-fallthrough-35.c: New test.

From-SVN: r244726

gcc/ChangeLog
gcc/gimplify.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/Wimplicit-fallthrough-35.c [new file with mode: 0644]

index 0b3d0c98bb0f4a3dd4e8162e4757a943e0ada153..67ccfa80dcc2b9ce26700978d5b0329f81fd70fe 100644 (file)
@@ -1,3 +1,9 @@
+2017-01-20  Marek Polacek  <polacek@redhat.com>
+
+       PR c/79152
+       * gimplify.c (should_warn_for_implicit_fallthrough): Handle consecutive
+       non-case labels.
+
 2017-01-20  Alexander Monakov  <amonakov@ispras.ru>
 
        * omp-expand.c (expand_omp_simd): Clear PROP_gimple_lomp_dev regardless
index 2777a23eb937f896d7dc87fba364fadb96fca6df..d382eea69f85b6f2664fca3448bc33eb5e62e378 100644 (file)
@@ -1985,7 +1985,7 @@ should_warn_for_implicit_fallthrough (gimple_stmt_iterator *gsi_p, tree label)
   if (FALLTHROUGH_LABEL_P (label))
     return false;
 
-  /* Don't warn for a non-case label followed by a statement:
+  /* Don't warn for non-case labels followed by a statement:
        case 0:
         foo ();
        label:
@@ -1993,7 +1993,12 @@ should_warn_for_implicit_fallthrough (gimple_stmt_iterator *gsi_p, tree label)
      as these are likely intentional.  */
   if (!case_label_p (&gimplify_ctxp->case_labels, label))
     {
-      gsi_next (&gsi);
+      tree l;
+      while (!gsi_end_p (gsi)
+            && gimple_code (gsi_stmt (gsi)) == GIMPLE_LABEL
+            && (l = gimple_label_label (as_a <glabel *> (gsi_stmt (gsi))))
+            && !case_label_p (&gimplify_ctxp->case_labels, l))
+       gsi_next (&gsi);
       if (gsi_end_p (gsi) || gimple_code (gsi_stmt (gsi)) != GIMPLE_LABEL)
        return false;
     }
index cc98016025e3f8df4755341627cc23de2a6153f4..69ba36cc7e8f14f4fc53ede842166344f6406e30 100644 (file)
@@ -1,3 +1,8 @@
+2017-01-20  Marek Polacek  <polacek@redhat.com>
+
+       PR c/79152
+       * c-c++-common/Wimplicit-fallthrough-35.c: New test.
+
 2017-01-20  Thomas Preud'homme  <thomas.preudhomme@arm.com>
 
        * lib/target-supports.exp (check_configured_with): New procedure.
diff --git a/gcc/testsuite/c-c++-common/Wimplicit-fallthrough-35.c b/gcc/testsuite/c-c++-common/Wimplicit-fallthrough-35.c
new file mode 100644 (file)
index 0000000..9a0aba6
--- /dev/null
@@ -0,0 +1,61 @@
+/* PR c/79152 */
+/* { dg-do compile } */
+/* { dg-options "-Wimplicit-fallthrough" } */
+
+extern void foo (int);
+
+void
+f (int i)
+{
+  switch (i)
+    {
+    case 0:
+      foo (0);
+l1:
+      foo (1);
+    }
+
+  switch (i)
+    {
+    case 0:
+      foo (0);
+l2:;
+    }
+
+  switch (i)
+    {
+    case 0:
+      foo (0);
+l3:
+l4:
+      foo (1);
+    }
+
+  switch (i)
+    {
+    case 0:
+      foo (0);
+l5:
+l6:;
+    }
+
+  switch (i)
+    {
+    case 0:
+      foo (0); /* { dg-warning "statement may fall through" } */
+l7:
+l8:
+    case 1:
+      foo (1);
+    }
+
+  switch (i)
+    {
+    case 0:
+      foo (0); /* { dg-warning "statement may fall through" } */
+l9:
+    case 1:
+l10:
+      foo (1);
+    }
+}