$ 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.
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.
It is caused by revision http://gcc.gnu.org/ml/gcc-cvs/2012-03/msg01244.html
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.
I will have a look.
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); }
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)
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
Fixed.