C: Avoid incorrect warning for volatile in compound expressions [PR98260]

2020-12-16  Martin Uecker  <muecker@gwdg.de>

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.
This commit is contained in:
Martin Uecker 2020-12-16 23:43:42 +01:00
parent 64a54505ec
commit ec13758ed4
2 changed files with 21 additions and 2 deletions

View file

@ -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);

View file

@ -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" } */
}