Message ID | 20160304180309.GN10006@redhat.com |
---|---|
State | New |
Headers | show |
On Fri, Mar 04, 2016 at 07:03:09PM +0100, Marek Polacek wrote: > Ok, version with dg-bogus: > > Bootstrapped/regtested on x86_64-linux, ok for trunk? > > 2016-03-04 Marek Polacek <polacek@redhat.com> > > PR c/69407 > * c-common.c (resolve_overloaded_builtin): Set TREE_USED for the fetch > operations. > > * gcc.dg/atomic-op-6.c: New test. > diff --git gcc/c-family/c-common.c gcc/c-family/c-common.c > index 965cf49..25afa9c 100644 > --- gcc/c-family/c-common.c > +++ gcc/c-family/c-common.c > @@ -11443,6 +11443,10 @@ resolve_overloaded_builtin (location_t loc, tree function, > && orig_code != BUILT_IN_ATOMIC_STORE_N) > result = sync_resolve_return (first_param, result, orig_format); > > + if (fetch_op) > + /* Prevent -Wunused-value warning. */ > + TREE_USED (result) = true; > + Can't sync_resolve_return return error_mark_node? If it could, perhaps it would be saver to move this a few lines above the sync_resolve_return call, where we've already checked that result is not error_mark_node. Otherwise LGTM. Jakub
On Fri, Mar 04, 2016 at 07:19:56PM +0100, Jakub Jelinek wrote: > > --- gcc/c-family/c-common.c > > +++ gcc/c-family/c-common.c > > @@ -11443,6 +11443,10 @@ resolve_overloaded_builtin (location_t loc, tree function, > > && orig_code != BUILT_IN_ATOMIC_STORE_N) > > result = sync_resolve_return (first_param, result, orig_format); > > > > + if (fetch_op) > > + /* Prevent -Wunused-value warning. */ > > + TREE_USED (result) = true; > > + > > Can't sync_resolve_return return error_mark_node? > If it could, perhaps it would be saver to move this a few lines above the > sync_resolve_return call, where we've already checked that result is not > error_mark_node. That seemed right but now I remember why I put setting TREE_USED here. Setting TREE_USED on the result of build_function_call_vec (a CALL_EXPR) wouldn't suppress the warning, it needs to be set on the result of sync_resolve_return (a CONVERT_EXPR). Setting TREE_USED on error_mark_node doesn't ICE so I didn't check for that as I think it should be harmless. So I'm keeping the patch as-is, please let me know you still want to see some adjustments. Marek
Ping. On Fri, Mar 04, 2016 at 07:03:09PM +0100, Marek Polacek wrote: > On Fri, Mar 04, 2016 at 06:41:26PM +0100, Jakub Jelinek wrote: > > I'm ok with it for gcc6. > > Cool. > > > But IMHO you should add dg-bogus directives here. > > Ok, version with dg-bogus: > > Bootstrapped/regtested on x86_64-linux, ok for trunk? > > 2016-03-04 Marek Polacek <polacek@redhat.com> > > PR c/69407 > * c-common.c (resolve_overloaded_builtin): Set TREE_USED for the fetch > operations. > > * gcc.dg/atomic-op-6.c: New test. > > diff --git gcc/c-family/c-common.c gcc/c-family/c-common.c > index 965cf49..25afa9c 100644 > --- gcc/c-family/c-common.c > +++ gcc/c-family/c-common.c > @@ -11443,6 +11443,10 @@ resolve_overloaded_builtin (location_t loc, tree function, > && orig_code != BUILT_IN_ATOMIC_STORE_N) > result = sync_resolve_return (first_param, result, orig_format); > > + if (fetch_op) > + /* Prevent -Wunused-value warning. */ > + TREE_USED (result) = true; > + > /* If new_return is set, assign function to that expr and cast the > result to void since the generic interface returned void. */ > if (new_return) > diff --git gcc/testsuite/gcc.dg/atomic-op-6.c gcc/testsuite/gcc.dg/atomic-op-6.c > index e69de29..f88c293 100644 > --- gcc/testsuite/gcc.dg/atomic-op-6.c > +++ gcc/testsuite/gcc.dg/atomic-op-6.c > @@ -0,0 +1,11 @@ > +/* Test we don't generate bogus warnings. */ > +/* PR c/69407 */ > +/* { dg-do compile } */ > +/* { dg-options "-Wall -Wextra" } */ > + > +void > +foo (int *p, int a) > +{ > + __atomic_fetch_add (&p, a, 0); /* { dg-bogus "value computed is not used" } */ > + __atomic_add_fetch (&p, a, 0); /* { dg-bogus "value computed is not used" } */ > +} Marek
On 03/14/2016 05:48 AM, Marek Polacek wrote: > Ping. > > On Fri, Mar 04, 2016 at 07:03:09PM +0100, Marek Polacek wrote: >> On Fri, Mar 04, 2016 at 06:41:26PM +0100, Jakub Jelinek wrote: >>> I'm ok with it for gcc6. >> >> Cool. >> >>> But IMHO you should add dg-bogus directives here. >> >> Ok, version with dg-bogus: >> >> Bootstrapped/regtested on x86_64-linux, ok for trunk? >> >> 2016-03-04 Marek Polacek <polacek@redhat.com> >> >> PR c/69407 >> * c-common.c (resolve_overloaded_builtin): Set TREE_USED for the fetch >> operations. >> >> * gcc.dg/atomic-op-6.c: New test. OK. jeff
diff --git gcc/c-family/c-common.c gcc/c-family/c-common.c index 965cf49..25afa9c 100644 --- gcc/c-family/c-common.c +++ gcc/c-family/c-common.c @@ -11443,6 +11443,10 @@ resolve_overloaded_builtin (location_t loc, tree function, && orig_code != BUILT_IN_ATOMIC_STORE_N) result = sync_resolve_return (first_param, result, orig_format); + if (fetch_op) + /* Prevent -Wunused-value warning. */ + TREE_USED (result) = true; + /* If new_return is set, assign function to that expr and cast the result to void since the generic interface returned void. */ if (new_return) diff --git gcc/testsuite/gcc.dg/atomic-op-6.c gcc/testsuite/gcc.dg/atomic-op-6.c index e69de29..f88c293 100644 --- gcc/testsuite/gcc.dg/atomic-op-6.c +++ gcc/testsuite/gcc.dg/atomic-op-6.c @@ -0,0 +1,11 @@ +/* Test we don't generate bogus warnings. */ +/* PR c/69407 */ +/* { dg-do compile } */ +/* { dg-options "-Wall -Wextra" } */ + +void +foo (int *p, int a) +{ + __atomic_fetch_add (&p, a, 0); /* { dg-bogus "value computed is not used" } */ + __atomic_add_fetch (&p, a, 0); /* { dg-bogus "value computed is not used" } */ +}