From 11d29d639f4b60f51a593932529be6895b613d4c Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Fri, 22 Dec 2017 19:01:58 +0100 Subject: [PATCH] re PR debug/83547 ((statement-frontiers) error: void value not ignored as it ought to be) PR debug/83547 * tree-iterator.c (alloc_stmt_list): Start with cleared TREE_SIDE_EFFECTS regardless whether a new STATEMENT_LIST is allocated or old one reused. c/ * c-typeck.c (c_finish_stmt_expr): Ignore !TREE_SIDE_EFFECTS as indicator of ({ }), instead skip all trailing DEBUG_BEGIN_STMTs first, and consider empty ones if there are no other stmts. For -Wunused-value walk all statements before the one only followed by DEBUG_BEGIN_STMTs. testsuite/ * gcc.c-torture/compile/pr83547.c: New test. From-SVN: r255980 --- gcc/ChangeLog | 5 +++++ gcc/c/ChangeLog | 9 +++++++++ gcc/c/c-typeck.c | 18 ++++++++---------- gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/gcc.c-torture/compile/pr83547.c | 16 ++++++++++++++++ gcc/tree-iterator.c | 5 ++++- 6 files changed, 45 insertions(+), 11 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr83547.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a75db0731af..aba9ae7ea5a 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,10 @@ 2017-12-22 Jakub Jelinek + PR debug/83547 + * tree-iterator.c (alloc_stmt_list): Start with cleared + TREE_SIDE_EFFECTS regardless whether a new STATEMENT_LIST is allocated + or old one reused. + PR target/83488 * config/i386/avx512vnniintrin.h: Don't check for __AVX512F__ nor enable avx512f explicitly in #pragma GCC target. diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index f4756c800a1..581f7df149b 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,12 @@ +2017-12-22 Jakub Jelinek + + PR debug/83547 + * c-typeck.c (c_finish_stmt_expr): Ignore !TREE_SIDE_EFFECTS as + indicator of ({ }), instead skip all trailing DEBUG_BEGIN_STMTs first, + and consider empty ones if there are no other stmts. For + -Wunused-value walk all statements before the one only followed by + DEBUG_BEGIN_STMTs. + 2017-12-22 Mike Stump Eric Botcazou diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index 5ae12d9c8a9..98062c76b90 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -10751,17 +10751,21 @@ c_finish_stmt_expr (location_t loc, tree body) continue_searching: if (TREE_CODE (last) == STATEMENT_LIST) { - tree_stmt_iterator i; + tree_stmt_iterator l = tsi_last (last); + + while (!tsi_end_p (l) && TREE_CODE (tsi_stmt (l)) == DEBUG_BEGIN_STMT) + tsi_prev (&l); /* This can happen with degenerate cases like ({ }). No value. */ - if (!TREE_SIDE_EFFECTS (last)) + if (tsi_end_p (l)) return body; /* If we're supposed to generate side effects warnings, process all of the statements except the last. */ if (warn_unused_value) { - for (i = tsi_start (last); !tsi_one_before_end_p (i); tsi_next (&i)) + for (tree_stmt_iterator i = tsi_start (last); + tsi_stmt (i) != tsi_stmt (l); tsi_next (&i)) { location_t tloc; tree t = tsi_stmt (i); @@ -10770,13 +10774,7 @@ c_finish_stmt_expr (location_t loc, tree body) emit_side_effect_warnings (tloc, t); } } - else - i = tsi_last (last); - if (TREE_CODE (tsi_stmt (i)) == DEBUG_BEGIN_STMT) - do - tsi_prev (&i); - while (TREE_CODE (tsi_stmt (i)) == DEBUG_BEGIN_STMT); - last_p = tsi_stmt_ptr (i); + last_p = tsi_stmt_ptr (l); last = *last_p; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 297e80fe17f..0102564068c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2017-12-22 Jakub Jelinek + PR debug/83547 + * gcc.c-torture/compile/pr83547.c: New test. + PR target/83488 * gcc.target/i386/pr83488-2.c: New test. * gcc.target/i386/pr83488-3.c: New test. diff --git a/gcc/testsuite/gcc.c-torture/compile/pr83547.c b/gcc/testsuite/gcc.c-torture/compile/pr83547.c new file mode 100644 index 00000000000..98a1e0453f2 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr83547.c @@ -0,0 +1,16 @@ +/* PR debug/83547 */ + +void +foo (void) +{ + if (({ 0; })) + ; + if (({ 0; 0; })) + ; + if (({ })) /* { dg-error "void value not ignored as it ought to be" } */ + ; + if (({ 0; { 0; } })) /* { dg-error "void value not ignored as it ought to be" } */ + ; + if (({ 0; {} })) /* { dg-error "void value not ignored as it ought to be" } */ + ; +} diff --git a/gcc/tree-iterator.c b/gcc/tree-iterator.c index 10e510db092..b0b88f4d2c7 100644 --- a/gcc/tree-iterator.c +++ b/gcc/tree-iterator.c @@ -41,7 +41,10 @@ alloc_stmt_list (void) TREE_SET_CODE (list, STATEMENT_LIST); } else - list = make_node (STATEMENT_LIST); + { + list = make_node (STATEMENT_LIST); + TREE_SIDE_EFFECTS (list) = 0; + } TREE_TYPE (list) = void_type_node; return list; } -- 2.30.2