* PATCH to fix bogus -Wimplicit-fallthrough warning (PR c++/77803)
@ 2016-09-30 21:39 Marek Polacek
2016-10-01 5:18 ` Markus Trippelsdorf
0 siblings, 1 reply; 7+ messages in thread
From: Marek Polacek @ 2016-09-30 21:39 UTC (permalink / raw)
To: GCC Patches
This PR reports a bogus -Wimplicit-fallthrough warning on the attached test.
The problem is that last_stmt_in_scope should for GIMPLE_TRY, if the last
statement of the eval part can't fallthrough, return this statement and don't
warn. And the same should be true for FALLTHROUGH (). This patch fixes it.
Bootstrapped/regtested on x86_64-linux, ok for trunk?
2016-09-30 Marek Polacek <polacek@redhat.com>
PR c++/77803
* gimplify.c (last_stmt_in_scope): Add check for FALLTHROUGH ().
* g++.dg/warn/Wimplicit-fallthrough-1.C: New test.
diff --git gcc/gimplify.c gcc/gimplify.c
index 66bb8be..97d63db 100644
--- gcc/gimplify.c
+++ gcc/gimplify.c
@@ -1687,6 +1687,7 @@ last_stmt_in_scope (gimple *stmt)
stmt = gimple_seq_last_stmt (gimple_try_eval (try_stmt));
gimple *last_eval = last_stmt_in_scope (stmt);
if (gimple_stmt_may_fallthru (last_eval)
+ && !gimple_call_internal_p (last_eval, IFN_FALLTHROUGH)
&& gimple_try_kind (try_stmt) == GIMPLE_TRY_FINALLY)
{
stmt = gimple_seq_last_stmt (gimple_try_cleanup (try_stmt));
diff --git gcc/testsuite/g++.dg/warn/Wimplicit-fallthrough-1.C gcc/testsuite/g++.dg/warn/Wimplicit-fallthrough-1.C
index e69de29..8f80b01 100644
--- gcc/testsuite/g++.dg/warn/Wimplicit-fallthrough-1.C
+++ gcc/testsuite/g++.dg/warn/Wimplicit-fallthrough-1.C
@@ -0,0 +1,16 @@
+// PR c++/77803
+// { dg-do compile { target c++11 } }
+// { dg-options "-Wimplicit-fallthrough" }
+
+struct A {};
+int a;
+void fn1() {
+ switch (0) {
+ case 0: {
+ A b;
+ [[fallthrough]];
+ }
+ default:
+ a = 0;
+ }
+}
Marek
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: PATCH to fix bogus -Wimplicit-fallthrough warning (PR c++/77803)
2016-09-30 21:39 PATCH to fix bogus -Wimplicit-fallthrough warning (PR c++/77803) Marek Polacek
@ 2016-10-01 5:18 ` Markus Trippelsdorf
2016-10-01 14:42 ` Marek Polacek
0 siblings, 1 reply; 7+ messages in thread
From: Markus Trippelsdorf @ 2016-10-01 5:18 UTC (permalink / raw)
To: Marek Polacek; +Cc: GCC Patches
On 2016.09.30 at 23:31 +0200, Marek Polacek wrote:
> This PR reports a bogus -Wimplicit-fallthrough warning on the attached test.
> The problem is that last_stmt_in_scope should for GIMPLE_TRY, if the last
> statement of the eval part can't fallthrough, return this statement and don't
> warn. And the same should be true for FALLTHROUGH (). This patch fixes it.
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
Try to compile the testcase without the fallthrough attribute...
> diff --git gcc/testsuite/g++.dg/warn/Wimplicit-fallthrough-1.C gcc/testsuite/g++.dg/warn/Wimplicit-fallthrough-1.C
> index e69de29..8f80b01 100644
> --- gcc/testsuite/g++.dg/warn/Wimplicit-fallthrough-1.C
> +++ gcc/testsuite/g++.dg/warn/Wimplicit-fallthrough-1.C
> @@ -0,0 +1,16 @@
> +// PR c++/77803
> +// { dg-do compile { target c++11 } }
> +// { dg-options "-Wimplicit-fallthrough" }
> +
> +struct A {};
> +int a;
> +void fn1() {
> + switch (0) {
> + case 0: {
> + A b;
> + [[fallthrough]];
> + }
> + default:
> + a = 0;
> + }
> +}
>
> Marek
>
--
Markus
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: PATCH to fix bogus -Wimplicit-fallthrough warning (PR c++/77803)
2016-10-01 5:18 ` Markus Trippelsdorf
@ 2016-10-01 14:42 ` Marek Polacek
2016-10-02 18:42 ` Jason Merrill
2016-10-07 8:45 ` Marek Polacek
0 siblings, 2 replies; 7+ messages in thread
From: Marek Polacek @ 2016-10-01 14:42 UTC (permalink / raw)
To: Markus Trippelsdorf; +Cc: GCC Patches
On Sat, Oct 01, 2016 at 07:17:50AM +0200, Markus Trippelsdorf wrote:
> On 2016.09.30 at 23:31 +0200, Marek Polacek wrote:
> > This PR reports a bogus -Wimplicit-fallthrough warning on the attached test.
> > The problem is that last_stmt_in_scope should for GIMPLE_TRY, if the last
> > statement of the eval part can't fallthrough, return this statement and don't
> > warn. And the same should be true for FALLTHROUGH (). This patch fixes it.
> >
> > Bootstrapped/regtested on x86_64-linux, ok for trunk?
>
> Try to compile the testcase without the fallthrough attribute...
Nuts. Forgot that gimple_call_internal_p doesn't handle NULL.
Bootstrapped/regtested on x86_64-linux and ppc64-linux, ok for trunk?
2016-10-01 Marek Polacek <polacek@redhat.com>
PR c++/77803
* gimplify.c (last_stmt_in_scope): Add check for FALLTHROUGH ().
* g++.dg/warn/Wimplicit-fallthrough-1.C: New test.
diff --git gcc/gimplify.c gcc/gimplify.c
index 66bb8be..a60d947 100644
--- gcc/gimplify.c
+++ gcc/gimplify.c
@@ -1687,6 +1687,8 @@ last_stmt_in_scope (gimple *stmt)
stmt = gimple_seq_last_stmt (gimple_try_eval (try_stmt));
gimple *last_eval = last_stmt_in_scope (stmt);
if (gimple_stmt_may_fallthru (last_eval)
+ && (last_eval == NULL
+ || !gimple_call_internal_p (last_eval, IFN_FALLTHROUGH))
&& gimple_try_kind (try_stmt) == GIMPLE_TRY_FINALLY)
{
stmt = gimple_seq_last_stmt (gimple_try_cleanup (try_stmt));
diff --git gcc/testsuite/g++.dg/warn/Wimplicit-fallthrough-1.C gcc/testsuite/g++.dg/warn/Wimplicit-fallthrough-1.C
index e69de29..053ed68 100644
--- gcc/testsuite/g++.dg/warn/Wimplicit-fallthrough-1.C
+++ gcc/testsuite/g++.dg/warn/Wimplicit-fallthrough-1.C
@@ -0,0 +1,33 @@
+// PR c++/77803
+// { dg-do compile { target c++11 } }
+// { dg-options "-Wimplicit-fallthrough" }
+
+struct A {};
+int a;
+
+void
+fn1 ()
+{
+ switch (0) {
+ case 0:
+ {
+ A b;
+ [[fallthrough]];
+ }
+ default:
+ a = 0;
+ }
+}
+
+void
+fn2 ()
+{
+ switch (0) {
+ case 0:
+ {
+ A b; // { dg-warning "statement may fall through" }
+ }
+ default:
+ a = 0;
+ }
+}
Marek
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: PATCH to fix bogus -Wimplicit-fallthrough warning (PR c++/77803)
2016-10-01 14:42 ` Marek Polacek
@ 2016-10-02 18:42 ` Jason Merrill
2016-10-02 21:57 ` Jakub Jelinek
2016-10-07 8:45 ` Marek Polacek
1 sibling, 1 reply; 7+ messages in thread
From: Jason Merrill @ 2016-10-02 18:42 UTC (permalink / raw)
To: Marek Polacek; +Cc: Markus Trippelsdorf, GCC Patches
On Sat, Oct 1, 2016 at 10:17 AM, Marek Polacek <polacek@redhat.com> wrote:
> + && (last_eval == NULL
> + || !gimple_call_internal_p (last_eval, IFN_FALLTHROUGH))
Isn't this still assuming that non-null last_eval must be a gcall, so
we'll get a checking ICE if it's something else?
Jason
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: PATCH to fix bogus -Wimplicit-fallthrough warning (PR c++/77803)
2016-10-02 18:42 ` Jason Merrill
@ 2016-10-02 21:57 ` Jakub Jelinek
0 siblings, 0 replies; 7+ messages in thread
From: Jakub Jelinek @ 2016-10-02 21:57 UTC (permalink / raw)
To: Jason Merrill; +Cc: Marek Polacek, Markus Trippelsdorf, GCC Patches
On Sun, Oct 02, 2016 at 02:42:23PM -0400, Jason Merrill wrote:
> On Sat, Oct 1, 2016 at 10:17 AM, Marek Polacek <polacek@redhat.com> wrote:
> > + && (last_eval == NULL
> > + || !gimple_call_internal_p (last_eval, IFN_FALLTHROUGH))
>
> Isn't this still assuming that non-null last_eval must be a gcall, so
> we'll get a checking ICE if it's something else?
This is the 2 operand gimple_call_internal_p, which is
return (is_gimple_call (gs)
&& gimple_call_internal_p (gs)
&& gimple_call_internal_fn (gs) == fn);
and thus should be fine for non-NULL last_eval.
Jakub
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: PATCH to fix bogus -Wimplicit-fallthrough warning (PR c++/77803)
2016-10-01 14:42 ` Marek Polacek
2016-10-02 18:42 ` Jason Merrill
@ 2016-10-07 8:45 ` Marek Polacek
2016-10-07 9:39 ` Jakub Jelinek
1 sibling, 1 reply; 7+ messages in thread
From: Marek Polacek @ 2016-10-07 8:45 UTC (permalink / raw)
To: GCC Patches
Ping.
On Sat, Oct 01, 2016 at 04:17:22PM +0200, Marek Polacek wrote:
> On Sat, Oct 01, 2016 at 07:17:50AM +0200, Markus Trippelsdorf wrote:
> > On 2016.09.30 at 23:31 +0200, Marek Polacek wrote:
> > > This PR reports a bogus -Wimplicit-fallthrough warning on the attached test.
> > > The problem is that last_stmt_in_scope should for GIMPLE_TRY, if the last
> > > statement of the eval part can't fallthrough, return this statement and don't
> > > warn. And the same should be true for FALLTHROUGH (). This patch fixes it.
> > >
> > > Bootstrapped/regtested on x86_64-linux, ok for trunk?
> >
> > Try to compile the testcase without the fallthrough attribute...
>
> Nuts. Forgot that gimple_call_internal_p doesn't handle NULL.
>
> Bootstrapped/regtested on x86_64-linux and ppc64-linux, ok for trunk?
>
> 2016-10-01 Marek Polacek <polacek@redhat.com>
>
> PR c++/77803
> * gimplify.c (last_stmt_in_scope): Add check for FALLTHROUGH ().
>
> * g++.dg/warn/Wimplicit-fallthrough-1.C: New test.
>
> diff --git gcc/gimplify.c gcc/gimplify.c
> index 66bb8be..a60d947 100644
> --- gcc/gimplify.c
> +++ gcc/gimplify.c
> @@ -1687,6 +1687,8 @@ last_stmt_in_scope (gimple *stmt)
> stmt = gimple_seq_last_stmt (gimple_try_eval (try_stmt));
> gimple *last_eval = last_stmt_in_scope (stmt);
> if (gimple_stmt_may_fallthru (last_eval)
> + && (last_eval == NULL
> + || !gimple_call_internal_p (last_eval, IFN_FALLTHROUGH))
> && gimple_try_kind (try_stmt) == GIMPLE_TRY_FINALLY)
> {
> stmt = gimple_seq_last_stmt (gimple_try_cleanup (try_stmt));
> diff --git gcc/testsuite/g++.dg/warn/Wimplicit-fallthrough-1.C gcc/testsuite/g++.dg/warn/Wimplicit-fallthrough-1.C
> index e69de29..053ed68 100644
> --- gcc/testsuite/g++.dg/warn/Wimplicit-fallthrough-1.C
> +++ gcc/testsuite/g++.dg/warn/Wimplicit-fallthrough-1.C
> @@ -0,0 +1,33 @@
> +// PR c++/77803
> +// { dg-do compile { target c++11 } }
> +// { dg-options "-Wimplicit-fallthrough" }
> +
> +struct A {};
> +int a;
> +
> +void
> +fn1 ()
> +{
> + switch (0) {
> + case 0:
> + {
> + A b;
> + [[fallthrough]];
> + }
> + default:
> + a = 0;
> + }
> +}
> +
> +void
> +fn2 ()
> +{
> + switch (0) {
> + case 0:
> + {
> + A b; // { dg-warning "statement may fall through" }
> + }
> + default:
> + a = 0;
> + }
> +}
>
> Marek
Marek
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: PATCH to fix bogus -Wimplicit-fallthrough warning (PR c++/77803)
2016-10-07 8:45 ` Marek Polacek
@ 2016-10-07 9:39 ` Jakub Jelinek
0 siblings, 0 replies; 7+ messages in thread
From: Jakub Jelinek @ 2016-10-07 9:39 UTC (permalink / raw)
To: Marek Polacek; +Cc: GCC Patches
On Fri, Oct 07, 2016 at 10:45:18AM +0200, Marek Polacek wrote:
> Ping.
>
> On Sat, Oct 01, 2016 at 04:17:22PM +0200, Marek Polacek wrote:
> > On Sat, Oct 01, 2016 at 07:17:50AM +0200, Markus Trippelsdorf wrote:
> > > On 2016.09.30 at 23:31 +0200, Marek Polacek wrote:
> > > > This PR reports a bogus -Wimplicit-fallthrough warning on the attached test.
> > > > The problem is that last_stmt_in_scope should for GIMPLE_TRY, if the last
> > > > statement of the eval part can't fallthrough, return this statement and don't
> > > > warn. And the same should be true for FALLTHROUGH (). This patch fixes it.
> > > >
> > > > Bootstrapped/regtested on x86_64-linux, ok for trunk?
> > >
> > > Try to compile the testcase without the fallthrough attribute...
> >
> > Nuts. Forgot that gimple_call_internal_p doesn't handle NULL.
> >
> > Bootstrapped/regtested on x86_64-linux and ppc64-linux, ok for trunk?
> >
> > 2016-10-01 Marek Polacek <polacek@redhat.com>
> >
> > PR c++/77803
> > * gimplify.c (last_stmt_in_scope): Add check for FALLTHROUGH ().
> >
> > * g++.dg/warn/Wimplicit-fallthrough-1.C: New test.
Ok, thanks.
Jakub
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2016-10-07 9:39 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-30 21:39 PATCH to fix bogus -Wimplicit-fallthrough warning (PR c++/77803) Marek Polacek
2016-10-01 5:18 ` Markus Trippelsdorf
2016-10-01 14:42 ` Marek Polacek
2016-10-02 18:42 ` Jason Merrill
2016-10-02 21:57 ` Jakub Jelinek
2016-10-07 8:45 ` Marek Polacek
2016-10-07 9:39 ` 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).