Re: [C PATCH] Avoid incorrect warning for volatile in compound expressions [PR 98260]
On Sun, 13 Dec 2020, Uecker, Martin wrote: > Here is a patch that fixes an incorrect warning for volatile > that appeared with the lvalue change. > > > -- Martin > > C: Avoid incorrect warning for volatile in compound expressions [PR98260] OK. -- Joseph S. Myers jos...@codesourcery.com
Re: [C PATCH] Avoid incorrect warning for volatile in compound expressions [PR 98260]
On 12/13/20 9:12 AM, Uecker, Martin wrote: Here is a patch that fixes an incorrect warning for volatile that appeared with the lvalue change. It's helpful to mention the bug id in the first line of the regression tests committed with the fix. (No need to repost the patch just with that change.) Martin -- Martin C: Avoid incorrect warning for volatile in compound expressions [PR98260] 2020-12-12 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 87ee8f47806..1388a60c495 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 000..b32f7ef6c03 --- /dev/null +++ b/gcc/testsuite/gcc.dg/unused-9.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-Wunused" } */ + + +void g(void) +{ + int i = 0; + volatile int x; + (x, i++);/* { dg-bogus "set but not used" } */ +} + +
[C PATCH] Avoid incorrect warning for volatile in compound expressions [PR 98260]
Here is a patch that fixes an incorrect warning for volatile that appeared with the lvalue change. -- Martin C: Avoid incorrect warning for volatile in compound expressions [PR98260] 2020-12-12 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 87ee8f47806..1388a60c495 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 000..b32f7ef6c03 --- /dev/null +++ b/gcc/testsuite/gcc.dg/unused-9.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-Wunused" } */ + + +void g(void) +{ + int i = 0; + volatile int x; + (x, i++);/* { dg-bogus "set but not used" } */ +} + +