The following testcase was emitting false positive warning that
the rhs of #pragma omp atomic write was stored but not read,
when the atomic actually does read it. The following patch
fixes that by calling default_function_array_read_conversion
on it, so that it is marked as read as well as converted from
lvalue to rvalue.
Furthermore, the code had
if (code == NOP_EXPR) ... else ... if (code == NOP_EXPR) ...
with none of ... parts changing code, so I've merged the two ifs.
2025-02-25 Jakub Jelinek <jakub@redhat.com>
PR c/119000
* c-parser.cc (c_parser_omp_atomic): For omp write call
default_function_array_read_conversion on the rhs expression.
Merge the two adjacent if (code == NOP_EXPR) blocks.
* c-c++-common/gomp/pr119000.c: New test.
(cherry picked from commit
cdffc76393488a73671b70481cf8a4b7c289029d)
goto saw_error;
if (code == NOP_EXPR)
{
- lhs = c_parser_expression (parser).value;
- lhs = c_fully_fold (lhs, false, NULL);
- if (lhs == error_mark_node)
+ eloc = c_parser_peek_token (parser)->location;
+ expr = c_parser_expression (parser);
+ expr = default_function_array_read_conversion (eloc, expr);
+ /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
+ opcode. */
+ code = OMP_ATOMIC;
+ lhs = v;
+ v = NULL_TREE;
+ rhs = c_fully_fold (expr.value, false, NULL);
+ if (rhs == error_mark_node)
goto saw_error;
}
else
if (non_lvalue_p)
lhs = non_lvalue (lhs);
}
- if (code == NOP_EXPR)
- {
- /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
- opcode. */
- code = OMP_ATOMIC;
- rhs = lhs;
- lhs = v;
- v = NULL_TREE;
- }
goto done;
case OMP_ATOMIC_CAPTURE_NEW:
if (c_parser_next_token_is (parser, CPP_OPEN_BRACE))
--- /dev/null
+/* PR c/119000 */
+/* { dg-do compile } */
+/* { dg-options "-fopenmp -Wunused-but-set-variable" } */
+
+int
+foo (void)
+{
+ int a = 1, b, c = 1, v; /* { dg-warning "variable 'b' set but not used" } */
+ #pragma omp atomic write
+ v = a;
+ #pragma omp atomic read
+ b = v;
+ #pragma omp atomic update
+ v += c;
+ return v;
+}