]> git.ipfire.org Git - thirdparty/gcc.git/commit
c: Fix up -Wunused-but-set-* warnings for _Atomics [PR99588]
authorJakub Jelinek <jakub@redhat.com>
Fri, 19 Mar 2021 21:54:31 +0000 (22:54 +0100)
committerJakub Jelinek <jakub@redhat.com>
Thu, 22 Apr 2021 14:50:23 +0000 (16:50 +0200)
commit3aa249a941d83bf734173991da6bf53ae79a3d47
tree4b809d3e2ef2295b53a237a1849638d2ff4777db
parentbd2a59b7b3f049d81566163056ae1206d4fa3e6d
c: Fix up -Wunused-but-set-* warnings for _Atomics [PR99588]

As the following testcases show, compared to -D_Atomic= case we have many
-Wunused-but-set-* warning false positives.
When an _Atomic variable/parameter is read, we call mark_exp_read on it in
convert_lvalue_to_rvalue, but build_atomic_assign does not.
For consistency with the non-_Atomic case where we mark_exp_read the lhs
for lhs op= ... but not for lhs = ..., this patch does that too.
But furthermore we need to pattern match the trees emitted by _Atomic store,
so that _Atomic store itself is not marked as being a variable read, but
when the result of the store is used, we mark it.

2021-03-19  Jakub Jelinek  <jakub@redhat.com>

PR c/99588
* c-typeck.c (mark_exp_read): Recognize what build_atomic_assign
with modifycode NOP_EXPR produces and mark the _Atomic var as read
if found.
(build_atomic_assign): For modifycode of NOP_EXPR, use COMPOUND_EXPRs
rather than STATEMENT_LIST.  Otherwise call mark_exp_read on lhs.
Set TREE_SIDE_EFFECTS on the TARGET_EXPR.

* gcc.dg/Wunused-var-5.c: New test.
* gcc.dg/Wunused-var-6.c: New test.

(cherry picked from commit b1fc1f1c4b2e9005c40ed476b067577da2d2ce84)
gcc/c/c-typeck.c
gcc/testsuite/gcc.dg/Wunused-var-5.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/Wunused-var-6.c [new file with mode: 0644]