public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Marek Polacek <polacek@redhat.com>
To: GCC Patches <gcc-patches@gcc.gnu.org>
Cc: Joseph Myers <joseph@codesourcery.com>
Subject: [C PATCH] Prevent -Wunused-value warning with __atomic_fetch_* (PR c/69407)
Date: Fri, 04 Mar 2016 17:30:00 -0000	[thread overview]
Message-ID: <20160304173040.GM10006@redhat.com> (raw)

This is not a regression but I thought I'd post this anyway.  Martin reported
that we generate -Wunused-value warnings on the attached testcase, which
arguable doesn't make sense.  Setting TREE_USED suppresses the warning.  Since
we already compute 'fetch_op' I used that.  (This warning doesn't trigger e.g.
for __atomic_load/store/compare.)

Bootstrapped/regtested on x86_64-linux, ok for trunk or gcc7?

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..c8d93a4 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);
+  __atomic_add_fetch (&p, a, 0);
+}

	Marek

             reply	other threads:[~2016-03-04 17:30 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-04 17:30 Marek Polacek [this message]
2016-03-04 17:41 ` Jakub Jelinek
2016-03-04 18:03   ` Marek Polacek
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=20160304173040.GM10006@redhat.com \
    --to=polacek@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --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).