From 6674f8f4860ae57efba5770d90ecb12b3f31a097 Mon Sep 17 00:00:00 2001 From: ktkachov Date: Tue, 24 Nov 2015 11:03:51 +0000 Subject: [PATCH] [cfgloop] PR middle-end/68375: Restructure get_loop_body_in_bfs_order to handle loops with only a header PR middle-end/68375 * cfgloop.c (get_loop_body_in_bfs_order): Restructure loop to avoid bogus assertion. * gcc.dg/pr68375.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@230798 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 7 +++++++ gcc/cfgloop.c | 19 +++++++------------ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/pr68375.c | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 12 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr68375.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d91c929..cffa083 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2015-11-24 Richard Biener + Kyrylo Tkachov + + PR middle-end/68375 + * cfgloop.c (get_loop_body_in_bfs_order): Restructure loop to avoid + bogus assertion. + 2015-11-24 Jakub Jelinek PR target/68483 diff --git a/gcc/cfgloop.c b/gcc/cfgloop.c index bf00e0e..83a5262 100644 --- a/gcc/cfgloop.c +++ b/gcc/cfgloop.c @@ -913,37 +913,32 @@ get_loop_body_in_bfs_order (const struct loop *loop) basic_block *blocks; basic_block bb; bitmap visited; - unsigned int i = 0; - unsigned int vc = 1; + unsigned int i = 1; + unsigned int vc = 0; gcc_assert (loop->num_nodes); gcc_assert (loop->latch != EXIT_BLOCK_PTR_FOR_FN (cfun)); blocks = XNEWVEC (basic_block, loop->num_nodes); visited = BITMAP_ALLOC (NULL); - - bb = loop->header; + blocks[0] = loop->header; + bitmap_set_bit (visited, loop->header->index); while (i < loop->num_nodes) { edge e; edge_iterator ei; - - if (bitmap_set_bit (visited, bb->index)) - /* This basic block is now visited */ - blocks[i++] = bb; + gcc_assert (i > vc); + bb = blocks[vc++]; FOR_EACH_EDGE (e, ei, bb->succs) { if (flow_bb_inside_loop_p (loop, e->dest)) { + /* This bb is now visited. */ if (bitmap_set_bit (visited, e->dest->index)) blocks[i++] = e->dest; } } - - gcc_assert (i > vc); - - bb = blocks[vc++]; } BITMAP_FREE (visited); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3c3e3cd..d5a1023 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-11-24 Kyrylo Tkachov + + PR middle-end/68375 + * gcc.dg/pr68375.c: New test. + 2015-11-24 Jakub Jelinek PR target/68483 diff --git a/gcc/testsuite/gcc.dg/pr68375.c b/gcc/testsuite/gcc.dg/pr68375.c new file mode 100644 index 0000000..bbbdd91 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr68375.c @@ -0,0 +1,39 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized-graph" } */ + +int a, c, d, e, g, h; +short f; + +int +foo () +{ +} + +short +fn1 (void) +{ + int j[2]; + for (; e; e++) + if (j[0]) + for (;;) + ; + if (!g) + return f; +} + +int +main (void) +{ + for (; a < 1; a++) + { + for (c = 0; c < 2; c++) + { + d && (f = 0); + h = fn1 (); + } + __builtin_printf ("%d\n", (char) f); + } + + return 0; +} + -- 2.7.4