From: Marek Polacek <polacek@redhat.com>
To: Jakub Jelinek <jakub@redhat.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>,
Joseph Myers <joseph@codesourcery.com>
Subject: Re: [C PATCH] Prevent -Wunused-value warning with __atomic_fetch_* (PR c/69407)
Date: Fri, 04 Mar 2016 18:03:00 -0000 [thread overview]
Message-ID: <20160304180309.GN10006@redhat.com> (raw)
In-Reply-To: <20160304174126.GG3017@tucnak.redhat.com>
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
next prev parent reply other threads:[~2016-03-04 18:03 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-04 17:30 Marek Polacek
2016-03-04 17:41 ` Jakub Jelinek
2016-03-04 18:03 ` Marek Polacek [this message]
2016-03-04 18:20 ` Jakub Jelinek
2016-03-07 13:33 ` Marek Polacek
2016-03-14 11:48 ` Marek Polacek
2016-03-17 17:24 ` Jeff Law
2016-03-04 18:17 Uros Bizjak
2016-03-07 13:34 ` Marek Polacek
2016-03-18 15:46 ` Uros Bizjak
2016-03-18 16:02 ` Uros Bizjak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160304180309.GN10006@redhat.com \
--to=polacek@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
--cc=joseph@codesourcery.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).