public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/56463] New: infinite loop when having integer overflow in a simple accumulator
@ 2013-02-26 16:06 nakacristo at hotmail dot com
  2013-02-26 16:16 ` [Bug c/56463] " jakub at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: nakacristo at hotmail dot com @ 2013-02-26 16:06 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56463

             Bug #: 56463
           Summary: infinite loop when having integer overflow in a simple
                    accumulator
    Classification: Unclassified
           Product: gcc
           Version: 4.6.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: nakacristo@hotmail.com


A colleague has showed me a problem and I have reduced it to this code:

#include <stdio.h>
int main()
{
    int i,j;
    int a=0;
    for(i=0;i<20000;i++)
        for(j=0;j<600;j++)
            a=a+3435345234440;
    printf("%d\n",a);
    return 0;
}

With 'gcc test.c' or 'gcc test.c -O' works correctly, but with 'gcc test.c -O2'
fails. More exactly, fails with 'gcc test.c -O -fstrict-overflow -ftree-pre
-ftree-vrp'.

With the optimization it becomes an infinite loop
00000000004004f4 <main>:
  4004f4:    b8 58 02 00 00           mov    $0x258,%eax
  4004f9:    ba 58 02 00 00           mov    $0x258,%edx
  4004fe:    83 e8 01                 sub    $0x1,%eax
  400501:    0f 44 c2                 cmove  %edx,%eax
  400504:    eb f8                    jmp    4004fe <main+0xa>

The overflow could make the variable 'a' to take any value, but never to make
the loop infinite.


My gcc version: gcc version 4.6.3 (Gentoo 4.6.3 p1.9, pie-0.5.2)
I have checked that in gcc-4.5.3 works correctly.


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2013-12-02 19:04 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-26 16:06 [Bug c/56463] New: infinite loop when having integer overflow in a simple accumulator nakacristo at hotmail dot com
2013-02-26 16:16 ` [Bug c/56463] " jakub at gcc dot gnu.org
2013-02-26 17:40 ` nakacristo at hotmail dot com
2013-02-26 17:54 ` jakub at gcc dot gnu.org
2013-02-26 18:42 ` dominiq at lps dot ens.fr
2013-02-27  8:19 ` nakacristo at hotmail dot com
2013-02-27  8:31 ` jakub at gcc dot gnu.org
2013-12-02 19:03 ` Joost.VandeVondele at mat dot ethz.ch
2013-12-02 19:04 ` Joost.VandeVondele at mat dot ethz.ch

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).