From 3b778d9d1268ec838c22fca98cd4dd351feb5914 Mon Sep 17 00:00:00 2001 From: Alexandre Oliva Date: Wed, 13 Dec 2017 18:46:43 +0000 Subject: [PATCH] re PR bootstrap/83396 (Bootstrap failures with Statement Frontiers) PR bootstrap/83396 PR debug/83391 * tree-cfgcleanup.c (remove_forwarder_block): Keep after labels debug stmts that can only appear after labels. * gcc.dg/torture/pr83396.c: New test. * g++.dg/torture/pr83391.C: New test. Co-Authored-By: Jakub Jelinek From-SVN: r255609 --- gcc/ChangeLog | 8 ++++++ gcc/testsuite/ChangeLog | 8 ++++++ gcc/testsuite/g++.dg/torture/pr83391.C | 36 ++++++++++++++++++++++++ gcc/testsuite/gcc.dg/torture/pr83396.c | 38 ++++++++++++++++++++++++++ gcc/tree-cfgcleanup.c | 24 ++++++++++++++-- 5 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/torture/pr83391.C create mode 100644 gcc/testsuite/gcc.dg/torture/pr83396.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d32bd1b5c43..a72b4bcfef8 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2017-12-13 Alexandre Oliva + Jakub Jelinek + + PR bootstrap/83396 + PR debug/83391 + * tree-cfgcleanup.c (remove_forwarder_block): Keep after + labels debug stmts that can only appear after labels. + 2017-12-13 Alexander Monakov PR rtl-optimization/82398 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c5f1d44d2e9..4af0d0c4d69 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2017-12-13 Alexandre Oliva + Jakub Jelinek + + PR bootstrap/83396 + PR debug/83391 + * gcc.dg/torture/pr83396.c: New test. + * g++.dg/torture/pr83391.C: New test. + 2017-12-13 Segher Boessenkool PR rtl-optimization/83393 diff --git a/gcc/testsuite/g++.dg/torture/pr83391.C b/gcc/testsuite/g++.dg/torture/pr83391.C new file mode 100644 index 00000000000..902d7fbcb74 --- /dev/null +++ b/gcc/testsuite/g++.dg/torture/pr83391.C @@ -0,0 +1,36 @@ +// PR debug/83391 +// { dg-do compile } +// { dg-options "-g" } +// { dg-additional-options "-mbranch-cost=1" { target { i?86-*-* x86_64-*-* mips*-*-* s390*-*-* avr*-*-* } } } + +unsigned char a; +enum E { F, G, H } b; +int c, d; + +void +foo () +{ + int e; + bool f; + E g = b; + while (1) + { + unsigned char h = a ? d : 0; + switch (g) + { + case 0: + f = h <= 'Z' || h >= 'a' && h <= 'z'; + break; + case 1: + { + unsigned char i = h; + e = 0; + } + if (e || h) + g = H; + /* FALLTHRU */ + default: + c = 0; + } + } +} diff --git a/gcc/testsuite/gcc.dg/torture/pr83396.c b/gcc/testsuite/gcc.dg/torture/pr83396.c new file mode 100644 index 00000000000..24c1d5de980 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr83396.c @@ -0,0 +1,38 @@ +/* PR bootstrap/83396 */ +/* { dg-do compile } */ +/* { dg-options "-g" } */ + +int fn1 (void); +void fn2 (void *, const char *); +void fn3 (void); + +void +fn4 (long long x) +{ + fn3 (); +} + +void +fn5 (long long x) +{ + if (x) + fn3(); +} + +void +fn6 (long long x) +{ + switch (fn1 ()) + { + case 0: + fn5 (x); + case 2: + fn2 (0, ""); + break; + case 1: + case 3: + fn4(x); + case 5: + fn2 (0, ""); + } +} diff --git a/gcc/tree-cfgcleanup.c b/gcc/tree-cfgcleanup.c index 0bee21756f2..a0e5797ec0e 100644 --- a/gcc/tree-cfgcleanup.c +++ b/gcc/tree-cfgcleanup.c @@ -536,9 +536,14 @@ remove_forwarder_block (basic_block bb) defined labels and labels with an EH landing pad number to the new block, so that the redirection of the abnormal edges works, jump targets end up in a sane place and debug information for - labels is retained. */ + labels is retained. + + While at that, move any debug stmts that appear before or in between + labels, but not those that can only appear after labels. */ gsi_to = gsi_start_bb (dest); - for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); ) + gsi = gsi_start_bb (bb); + gimple_stmt_iterator gsie = gsi_after_labels (bb); + while (gsi_stmt (gsi) != gsi_stmt (gsie)) { tree decl; label = gsi_stmt (gsi); @@ -557,6 +562,21 @@ remove_forwarder_block (basic_block bb) gsi_next (&gsi); } + /* Move debug statements if the destination has a single predecessor. */ + if (can_move_debug_stmts && !gsi_end_p (gsi)) + { + gcc_assert (gsi_stmt (gsi) == gsi_stmt (gsie)); + gimple_stmt_iterator gsie_to = gsi_after_labels (dest); + do + { + gimple *debug = gsi_stmt (gsi); + gcc_assert (is_gimple_debug (debug)); + gsi_remove (&gsi, false); + gsi_insert_before (&gsie_to, debug, GSI_SAME_STMT); + } + while (!gsi_end_p (gsi)); + } + bitmap_set_bit (cfgcleanup_altered_bbs, dest->index); /* Update the dominators. */ -- 2.30.2