Compiling the following code with -O2 produces an buggy excecutable:
(Using no optimization or -O1 produces an valid excecutable)
~~~ snip ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include <iostream>

int main( void )
{
    for ( int i = 1; i != 0; i = i + 1 )
    {
        if ( ! (i % 100000000) )
        {
            std::cout << i << std::endl;

            if ( i == 0 )
            {
                std::cout << i << std::endl;
            }
        }
    }

    return 0;
}
~~~ snip ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Commands to build and execute:

~/c++work/multtest> g++ -O2 -o multtest main.cpp
~/c++work/multtest> ./multtest
100000000
200000000
:
-200000000
-100000000
0
100000000
200000000
:                       // and continues

== Environment =======================================

~/c++work/multtest> gcc --version
gcc (GCC) 4.1.1 (Gentoo 4.1.1)
Copyright (C) 2006 Free Software Foundation, Inc.
Dies ist freie Software; die Kopierbedingungen stehen in den Quellen. Es
gibt KEINE Garantie; auch nicht für MARKTGÄNGIGKEIT oder FÜR SPEZIELLE ZWECKE.

~/c++work/multtest> uname --all
Linux atlantis 2.6.17-gentoo-r5 #5 SMP PREEMPT Mon Aug 14 19:48:18 CEST 2006
i686 AMD Athlon(tm) XP 2500+ AuthenticAMD GNU/Linux

~/c++work/multtest> cat /proc/cpuinfo
processor       : 0
vendor_id       : AuthenticAMD
cpu family      : 6
model           : 10
model name      : AMD Athlon(tm) XP 2500+
stepping        : 0
cpu MHz         : 1837.783
cache size      : 512 KB
fdiv_bug        : no
hlt_bug         : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 1
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov
pat pse36 mmx fxsr sse syscall mmxext 3dnowext 3dnow up ts
bogomips        : 3679.34


-- 
           Summary: Zerodetection (i != 0) compiled with -O2 don't work
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: hgsawicki at web dot de


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

Reply via email to