Bug 54458 (get_loop_body) - [4.8 Regression] ICE get_loop_body, at cfgloop.c:830
Summary: [4.8 Regression] ICE get_loop_body, at cfgloop.c:830
Status: RESOLVED FIXED
Alias: get_loop_body
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: 4.8.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-09-02 15:38 UTC by Francesco Zappa Nardelli
Modified: 2012-09-04 10:32 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-09-02 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Francesco Zappa Nardelli 2012-09-02 15:38:25 UTC

    
Comment 1 Francesco Zappa Nardelli 2012-09-02 15:42:45 UTC
$ gcc -v       
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/home/yquem/moscova/zappa/source/gcc-svn-bin/libexec/gcc/x86_64-unknown-linux-gnu/4.8.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-svn/configure --prefix=/home/yquem/moscova/zappa/source/gcc-svn-bin/
Thread model: posix
gcc version 4.8.0 20120627 (experimental) (GCC) 

[a recent but not the latest svn trunk]

$ cat input.c

int a, b, c, d;
void
func_34 () {
lbl_424:
  if (c ? 0 : 0 % 0)
    for (; a; a--)
lbl_130: {
    }
  else if (d)
    for (;;) {
    }
  if (b)
    goto lbl_130;
  goto lbl_424;
}
void
main () {
}

$ gcc -O3 input.c
input.c: In function 'func_34':
input.c:5:17: warning: division by zero [-Wdiv-by-zero]
   if (c ? 0 : 0 % 0)
                 ^
input.c:3:1: internal compiler error: in get_loop_body, at cfgloop.c:830
 func_34 () {
 ^
Please submit a full bug report.
Comment 2 Francesco Zappa Nardelli 2012-09-02 16:23:35 UTC
Can reproduce with the latest svn trunk as well:

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/home/yquem/moscova/zappa/source/gcc-svn-bin/libexec/gcc/x86_64-unknown-linux-gnu/4.8.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-svn/configure --disable-bootstrap --enable-languages=c,c++ --prefix=/home/yquem/moscova/zappa/source/gcc-svn-bin : (reconfigured) ../gcc-svn/configure --disable-bootstrap --enable-languages=c --prefix=/home/yquem/moscova/zappa/source/gcc-svn-bin
Thread model: posix
gcc version 4.8.0 20120902 (experimental) (GCC) 

and the exact error message now is:

input.c:3:1: internal compiler error: in get_loop_body, at cfgloop.c:823
 func_34 () {
 ^
Please submit a full bug report.
Comment 3 H.J. Lu 2012-09-02 17:05:24 UTC
It is caused by revision

http://gcc.gnu.org/ml/gcc-cvs/2012-03/msg01244.html
Comment 4 Francesco Zappa Nardelli 2012-09-02 17:55:10 UTC
Just to be precise, the program has an undefined behaviour in the test of the first 'if':

  (c ? 0 : 0 % 0)

because the right operand of % cannot be 0 (according to the standard, ยง6.5.5#5).  Unclear to me if a compiler is allowed to crash on programs with undefined behaviours or not.  

However an undefined-behaviour free (I believe) variant of that code makes gcc crash similarly:

int g_24[][0];
int g_42;
int g_168[];

void func_34 (p_38) {
lbl_424:
  if (g_24[0][0] == 0 ? 1 : 1 % (g_24[0][0]))
    for (; g_42; g_42--)
lbl_130: {
    }
  else if (p_38)
    for (;;) {
    }
  if (g_168[0])
    goto lbl_130;
  goto lbl_424;
}

void main () {
  g_24[0][0] = 1;
  func_34(0);
}

$ gcc -O3 input.c   (gcc version 4.8.0 20120902 (experimental) (GCC) )

input-hand.c: In function 'func_34':
input-hand.c:5:6: internal compiler error: in get_loop_body, at cfgloop.c:823
 void func_34 (p_38) {
      ^
Please submit a full bug report.

Not sure that it helps, but while I was performing test-case reduction I noticed that the % operator plays a key role in making gcc crash here.
Comment 5 Richard Biener 2012-09-03 09:00:53 UTC
I will have a look.
Comment 6 Jakub Jelinek 2012-09-03 09:06:29 UTC
Cleaned up testcase (and no longer invalid):
unsigned int a, b, c;

void
foo (unsigned int x)
{
  do
    {
      if (a == 0 ? 1 : 1 % a)
        for (; b; b--)
          lab:;
      else
        while (x)
          ;
      if (c)
        goto lab;
    }
  while (1);
}
Comment 7 Richard Biener 2012-09-03 14:27:27 UTC
I'm testing

Index: gcc/tree-ssa-threadupdate.c
===================================================================
--- gcc/tree-ssa-threadupdate.c (revision 190889)
+++ gcc/tree-ssa-threadupdate.c (working copy)
@@ -1037,11 +1037,21 @@ thread_through_loop_header (struct loop
        }
       free (bblocks);
 
+      /* If the new header has multiple latches mark it so.  */
+      FOR_EACH_EDGE (e, ei, loop->header->preds)
+       if (e->src->loop_father == loop
+           && e->src != loop->latch)
+         {
+           loop->latch = NULL;
+           loops_state_set (LOOPS_MAY_HAVE_MULTIPLE_LATCHES);
+         }
+
       /* Cancel remaining threading requests that would make the
         loop a multiple entry loop.  */
       FOR_EACH_EDGE (e, ei, header->preds)
Comment 8 Richard Biener 2012-09-04 09:29:02 UTC
Author: rguenth
Date: Tue Sep  4 09:28:58 2012
New Revision: 190918

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=190918
Log:
2012-09-04  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/54458
	* tree-ssa-threadupdate.c (thread_through_loop_header): If we
	turn the loop into one with multiple latches mark it so.

	* gcc.dg/torture/pr54458.c: New testcase.

Added:
    trunk/gcc/testsuite/gcc.dg/torture/pr54458.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-ssa-threadupdate.c
Comment 9 Richard Biener 2012-09-04 10:32:22 UTC
Fixed.