// { dg-do run } // { dg-options "-O2" } char heap[50000];
int main () { for (unsigned ix = sizeof (heap); ix--;) heap[ix] = ix; return 0; } (distilled from http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=113851 PR middle-end/27620 testcase) is miscompiled on {x86_64,i?86}-linux at -O2. At mergephi pass it still looks correct: int main() { unsigned int ix; char D.2349; bool retval.0; <bb 2>: goto <bb 4> (<L1>); <L0>:; ix_9 = ix_5; D.2349_10 = (char) ix_5; heap[ix_5] = D.2349_10; # ix_2 = PHI <50000(2), ix_5(3)>; <L1>:; ix_5 = ix_2 - 1; if (ix_5 != 4294967295) goto <L0>; else goto <L2>; <L2>:; return 0; } but then vrp1 folds ix_5 != 4294967295 as 1 and since that this is an endless loop which obviously segfaults. But, given that ix is unsigned, wrapping around is valid. -- Summary: [4.1/4.2 regression] VRP miscompilation of simple loop Product: gcc Version: 4.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: jakub at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27639