public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Fix missing -Wimplicit-fallthrough warning
@ 2016-09-29 16:26 Marek Polacek
  2016-10-05 16:53 ` Marek Polacek
  0 siblings, 1 reply; 3+ messages in thread
From: Marek Polacek @ 2016-09-29 16:26 UTC (permalink / raw)
  To: GCC Patches

Here, a missing -Wimplicit-fallthrough warning was caused by a misplaced
FALLTHROUGH_LABEL_P check.  As it is now, for FALLTHROUGH_LABEL_P we'd
never gotten around to
 1933             /* So that next warn_implicit_fallthrough_r will start looking for
 1934                a new sequence starting with this label.  */
 1935             gsi_prev (gsi_p);

The fix is to move the check to should_warn_for_implicit_fallthrough.

Bootstrapped/regtested on x86_64-linux and ppc64-linux, ok for trunk?

2016-09-29  Marek Polacek  <polacek@redhat.com>

	* gimplify.c (should_warn_for_implicit_fallthrough): Check for
	FALLTHROUGH_LABEL_P here...
	(warn_implicit_fallthrough_r): ...not here.

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

diff --git gcc/gimplify.c gcc/gimplify.c
index 66bb8be..e077a7e 100644
--- gcc/gimplify.c
+++ gcc/gimplify.c
@@ -1817,6 +1817,10 @@ should_warn_for_implicit_fallthrough (gimple_stmt_iterator *gsi_p, tree label)
 {
   gimple_stmt_iterator gsi = *gsi_p;
 
+  /* Don't warn if the label is marked with a "falls through" comment.  */
+  if (FALLTHROUGH_LABEL_P (label))
+    return false;
+
   /* Don't warn for a non-case label followed by a statement:
        case 0:
 	 foo ();
@@ -1903,7 +1907,6 @@ warn_implicit_fallthrough_r (gimple_stmt_iterator *gsi_p, bool *handled_ops_p,
 	if (gimple_code (next) == GIMPLE_LABEL
 	    && gimple_has_location (next)
 	    && (label = gimple_label_label (as_a <glabel *> (next)))
-	    && !FALLTHROUGH_LABEL_P (label)
 	    && prev != NULL)
 	  {
 	    struct label_entry *l;
diff --git gcc/testsuite/c-c++-common/Wimplicit-fallthrough-22.c gcc/testsuite/c-c++-common/Wimplicit-fallthrough-22.c
index e69de29..7a81e47 100644
--- gcc/testsuite/c-c++-common/Wimplicit-fallthrough-22.c
+++ gcc/testsuite/c-c++-common/Wimplicit-fallthrough-22.c
@@ -0,0 +1,23 @@
+/* { dg-do compile } */
+/* { dg-options "-Wimplicit-fallthrough" } */
+
+void bar (int);
+
+void
+foo (int i)
+{
+  switch (i)
+    {
+    case 1:
+      bar (1);
+      /* FALLTHROUGH */
+    case 2:
+      bar (2); /* { dg-warning "statement may fall through" } */
+    case 3:
+      bar (3); /* { dg-warning "statement may fall through" } */
+    case 4:
+      bar (4);
+    default:
+      break;
+    }
+}

	Marek

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-10-07 12:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-29 16:26 Fix missing -Wimplicit-fallthrough warning Marek Polacek
2016-10-05 16:53 ` Marek Polacek
2016-10-07 12:30   ` Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).