From ec13758ed41936bf803640f0dd8c259c034fe4b9 Mon Sep 17 00:00:00 2001 From: Martin Uecker Date: Wed, 16 Dec 2020 23:43:42 +0100 Subject: [PATCH] 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. --- gcc/c/c-parser.c | 10 ++++++++-- gcc/testsuite/gcc.dg/unused-9.c | 13 +++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/unused-9.c 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" } */ +} + + -- 2.30.2