This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C PATCH] Prevent -Wunused-value warning with __atomic_fetch_* (PR c/69407)
- From: Marek Polacek <polacek at redhat dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Cc: Joseph Myers <joseph at codesourcery dot com>
- Date: Fri, 4 Mar 2016 18:30:40 +0100
- Subject: [C PATCH] Prevent -Wunused-value warning with __atomic_fetch_* (PR c/69407)
- Authentication-results: sourceware.org; auth=none
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