* [PATCH] Fix bogus warning with -Wimplicit-fallthrough (PR c/79152)
@ 2017-01-20 16:18 Marek Polacek
2017-01-20 16:32 ` Jakub Jelinek
0 siblings, 1 reply; 2+ messages in thread
From: Marek Polacek @ 2017-01-20 16:18 UTC (permalink / raw)
To: GCC Patches; +Cc: Jakub Jelinek
We already have code to handle
case 0:
foo ();
label:
bar ();
where we don't want to warn, but the code didn't handle consecutive non-case
labels. Thus fixed.
Bootstrapped/regtested on x86_64-linux, ok for trunk?
2017-01-20 Marek Polacek <polacek@redhat.com>
PR c/79152
* gimplify.c (should_warn_for_implicit_fallthrough): Handle consecutive
non-case labels.
* c-c++-common/Wimplicit-fallthrough-35.c: New test.
diff --git gcc/gimplify.c gcc/gimplify.c
index 2777a23..d382eea 100644
--- gcc/gimplify.c
+++ gcc/gimplify.c
@@ -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;
}
diff --git gcc/testsuite/c-c++-common/Wimplicit-fallthrough-35.c gcc/testsuite/c-c++-common/Wimplicit-fallthrough-35.c
index e69de29..9a0aba6 100644
--- gcc/testsuite/c-c++-common/Wimplicit-fallthrough-35.c
+++ gcc/testsuite/c-c++-common/Wimplicit-fallthrough-35.c
@@ -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);
+ }
+}
Marek
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Fix bogus warning with -Wimplicit-fallthrough (PR c/79152)
2017-01-20 16:18 [PATCH] Fix bogus warning with -Wimplicit-fallthrough (PR c/79152) Marek Polacek
@ 2017-01-20 16:32 ` Jakub Jelinek
0 siblings, 0 replies; 2+ messages in thread
From: Jakub Jelinek @ 2017-01-20 16:32 UTC (permalink / raw)
To: Marek Polacek; +Cc: GCC Patches
On Fri, Jan 20, 2017 at 05:14:34PM +0100, Marek Polacek wrote:
> We already have code to handle
>
> case 0:
> foo ();
> label:
> bar ();
>
> where we don't want to warn, but the code didn't handle consecutive non-case
> labels. Thus fixed.
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
>
> 2017-01-20 Marek Polacek <polacek@redhat.com>
>
> PR c/79152
> * gimplify.c (should_warn_for_implicit_fallthrough): Handle consecutive
> non-case labels.
>
> * c-c++-common/Wimplicit-fallthrough-35.c: New test.
Ok, thanks.
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-01-20 16:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-20 16:18 [PATCH] Fix bogus warning with -Wimplicit-fallthrough (PR c/79152) Marek Polacek
2017-01-20 16:32 ` 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).