From: Martin Uecker Date: Wed, 16 Dec 2020 22:43:42 +0000 (+0100) Subject: C: Avoid incorrect warning for volatile in compound expressions [PR98260] X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ec13758ed41936bf803640f0dd8c259c034fe4b9;p=gcc.git C: Avoid incorrect warning for volatile in compound expressions [PR98260] 2020-12-16 Martin Uecker gcc/c/ PR c/98260 * c-parser.c (c_parser_expression): Look into nop expression when marking expressions as read. gcc/testsuite/ PR c/98260 * gcc.dg/unused-9.c: New test. --- diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index 69ecdb5e822..b9fdc90274e 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -10615,8 +10615,14 @@ c_parser_expression (c_parser *parser) c_parser_consume_token (parser); expr_loc = c_parser_peek_token (parser)->location; lhsval = expr.value; - while (TREE_CODE (lhsval) == COMPOUND_EXPR) - lhsval = TREE_OPERAND (lhsval, 1); + while (TREE_CODE (lhsval) == COMPOUND_EXPR + || TREE_CODE (lhsval) == NOP_EXPR) + { + if (TREE_CODE (lhsval) == COMPOUND_EXPR) + lhsval = TREE_OPERAND (lhsval, 1); + else + lhsval = TREE_OPERAND (lhsval, 0); + } if (DECL_P (lhsval) || handled_component_p (lhsval)) mark_exp_read (lhsval); next = c_parser_expr_no_commas (parser, NULL); diff --git a/gcc/testsuite/gcc.dg/unused-9.c b/gcc/testsuite/gcc.dg/unused-9.c new file mode 100644 index 00000000000..bdf36e1f50e --- /dev/null +++ b/gcc/testsuite/gcc.dg/unused-9.c @@ -0,0 +1,13 @@ +/* PR c/98260 */ +/* { dg-do compile } */ +/* { dg-options "-Wunused" } */ + + +void g(void) +{ + int i = 0; + volatile int x; + (x, i++); /* { dg-bogus "set but not used" } */ +} + +