From: Martin Liska Date: Wed, 10 Dec 2014 14:07:47 +0000 (+0100) Subject: re PR ipa/63909 (ICE: SIGSEGV in ipa_icf_gimple::func_checker::compare_bb()) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=42c0b54df5517af870ae4f50c32886ac77af2046;p=gcc.git re PR ipa/63909 (ICE: SIGSEGV in ipa_icf_gimple::func_checker::compare_bb()) PR ipa/63909 * gimple-iterator.h (gsi_start_bb_nondebug): New function. * ipa-icf-gimple.c (func_checker::compare_bb): Correct iteration replaces loop based on precomputed number of non-debug statements. * gcc.dg/ipa/pr63909.c: New test. From-SVN: r218578 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index ccf49201f5f..8d502586f7f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2014-12-10 Martin Liska + + * gimple-iterator.h (gsi_start_bb_nondebug): New function. + * ipa-icf-gimple.c (func_checker::compare_bb): Correct iteration + replaces loop based on precomputed number of non-debug statements. + 2014-12-08 Alexander Ivchenko * config/linux.c (linux_has_ifunc_p): Remove. diff --git a/gcc/gimple-iterator.h b/gcc/gimple-iterator.h index fb6cc0718fb..e9602b34ffe 100644 --- a/gcc/gimple-iterator.h +++ b/gcc/gimple-iterator.h @@ -211,6 +211,19 @@ gsi_stmt (gimple_stmt_iterator i) return i.ptr; } +/* Return a new iterator pointing to the first non-debug statement + in basic block BB. */ + +static inline gimple_stmt_iterator +gsi_start_bb_nondebug (basic_block bb) +{ + gimple_stmt_iterator gsi = gsi_start_bb (bb); + while (!gsi_end_p (gsi) && is_gimple_debug (gsi_stmt (gsi))) + gsi_next (&gsi); + + return gsi; +} + /* Return a block statement iterator that points to the first non-label statement in block BB. */ diff --git a/gcc/ipa-icf-gimple.c b/gcc/ipa-icf-gimple.c index 8f2a438abc9..ec0290a4013 100644 --- a/gcc/ipa-icf-gimple.c +++ b/gcc/ipa-icf-gimple.c @@ -559,24 +559,16 @@ func_checker::parse_labels (sem_bb *bb) bool func_checker::compare_bb (sem_bb *bb1, sem_bb *bb2) { - unsigned i; gimple_stmt_iterator gsi1, gsi2; gimple s1, s2; - if (bb1->nondbg_stmt_count != bb2->nondbg_stmt_count - || bb1->edge_count != bb2->edge_count) - return return_false (); - - gsi1 = gsi_start_bb (bb1->bb); - gsi2 = gsi_start_bb (bb2->bb); + gsi1 = gsi_start_bb_nondebug (bb1->bb); + gsi2 = gsi_start_bb_nondebug (bb2->bb); - for (i = 0; i < bb1->nondbg_stmt_count; i++) + while (!gsi_end_p (gsi1)) { - if (is_gimple_debug (gsi_stmt (gsi1))) - gsi_next_nondebug (&gsi1); - - if (is_gimple_debug (gsi_stmt (gsi2))) - gsi_next_nondebug (&gsi2); + if (gsi_end_p (gsi2)) + return return_false (); s1 = gsi_stmt (gsi1); s2 = gsi_stmt (gsi2); @@ -646,10 +638,13 @@ func_checker::compare_bb (sem_bb *bb1, sem_bb *bb2) return return_false_with_msg ("Unknown GIMPLE code reached"); } - gsi_next (&gsi1); - gsi_next (&gsi2); + gsi_next_nondebug (&gsi1); + gsi_next_nondebug (&gsi2); } + if (!gsi_end_p (gsi2)) + return return_false (); + return true; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3bbb497009c..0cac309fedf 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2014-12-10 Martin Liska + + * gcc.dg/ipa/pr63909.c: New test. + 2014-12-10 Kai Tietz PR c++/64127 diff --git a/gcc/testsuite/gcc.dg/ipa/pr63909.c b/gcc/testsuite/gcc.dg/ipa/pr63909.c new file mode 100644 index 00000000000..8538e214be3 --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/pr63909.c @@ -0,0 +1,27 @@ +/* { dg-options "-O2 -fno-guess-branch-probability" } */ + +int z; + +__attribute__((noinline)) +void g () +{ + if (++z) + __builtin_exit (0); + g (); +} + +__attribute__((noinline)) +void f () +{ + if (++z) + __builtin_exit (0); + f (); +} + +int main() +{ + f (); + g (); + + return 0; +}