On Dec 21, 2017, Jakub Jelinek <ja...@redhat.com> wrote: > On Wed, Dec 20, 2017 at 10:02:24PM -0200, Alexandre Oliva wrote: >> + if (tsi_one_before_end_p (i)) >> + TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (tsi_stmt (i));
> So DEBUG_BEGIN_STMTs after the single non-DEBUG_BEGIN_STMT stmt in > the STATEMENT_LIST can't happen (or just we don't have a testcase for it)? I know I said it couldn't, but while looking into PR83527 I decided to actually check that, and my conclusion quickly proved to be false. So the patch below fixes that, as well as the newer PR. This has completed -fcompare-debug bootstrap on i686- and ppc64le-linux-gnu; x86_64-linux-gnu is almost done, and regression testing for them all is underway or about to start. Ok to install if it all passes? for gcc/c-family/ChangeLog PR debug/83527 PR debug/83419 * c-semantics.c (only_debug_stmts_after_p): New. (pop_stmt_list): Clear side effects in debug-only stmt list. Check for single nondebug stmt followed by debug stmts only. for gcc/testsuite/ChangeLog PR debug/83527 PR debug/83419 * gcc.dg/pr83527.c: New. --- gcc/c-family/c-semantics.c | 23 +++++++++++++++++++---- gcc/testsuite/gcc.dg/pr83527.c | 26 ++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr83527.c diff --git a/gcc/c-family/c-semantics.c b/gcc/c-family/c-semantics.c index 3a972c32c8ea..21d908ed06c1 100644 --- a/gcc/c-family/c-semantics.c +++ b/gcc/c-family/c-semantics.c @@ -35,6 +35,17 @@ push_stmt_list (void) return t; } +/* Return TRUE if, after I, there are any nondebug stmts. */ + +static inline bool +only_debug_stmts_after_p (tree_stmt_iterator i) +{ + for (tsi_next (&i); !tsi_end_p (i); tsi_next (&i)) + if (TREE_CODE (tsi_stmt (i)) != DEBUG_BEGIN_STMT) + return false; + return true; +} + /* Finish the statement tree rooted at T. */ tree @@ -99,11 +110,15 @@ pop_stmt_list (tree t) while (!tsi_end_p (i) && TREE_CODE (tsi_stmt (i)) == DEBUG_BEGIN_STMT) tsi_next (&i); - /* If there's only one nondebug stmt in the list, we'd have - extracted the stmt and dropped the list, and we'd take - TREE_SIDE_EFFECTS from that statement, so keep the list's + /* If there are only debug stmts in the list, without them + we'd have an empty stmt without side effects. If there's + only one nondebug stmt, we'd have extracted the stmt and + dropped the list, and we'd take TREE_SIDE_EFFECTS from + that statement. In either case, keep the list's TREE_SIDE_EFFECTS in sync. */ - if (tsi_one_before_end_p (i)) + if (tsi_end_p (i)) + TREE_SIDE_EFFECTS (t) = 0; + else if (only_debug_stmts_after_p (i)) TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (tsi_stmt (i)); } } diff --git a/gcc/testsuite/gcc.dg/pr83527.c b/gcc/testsuite/gcc.dg/pr83527.c new file mode 100644 index 000000000000..effef439ac07 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr83527.c @@ -0,0 +1,26 @@ +/* PR debug/83527 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fcompare-debug" } */ + +extern void fn2(void); +extern void fn3(void); +int a, b; +void fn1() { + int c; + short d; + switch (a) { + case 32800: + fn2(); + case 32769: + b = 0; + case 32771: + case 32772: + case 32782: + fn3(); + } + if (d || c) { + do + ; + while (0); + } +} -- Alexandre Oliva, freedom fighter http://FSFLA.org/~lxoliva/ You must be the change you wish to see in the world. -- Gandhi Be Free! -- http://FSFLA.org/ FSF Latin America board member Free Software Evangelist|Red Hat Brasil GNU Toolchain Engineer