This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/11536] New: -O2 optimalization produces wrong code


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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

           Summary: -O2 optimalization produces wrong code
           Product: gcc
           Version: 3.0.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: samal at kam dot mff dot cuni dot cz
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i386-pc-linux-gnu
  GCC host triplet: i386-pc-linux-gnu
GCC target triplet: i386-pc-linux-gnu

On the following code, gcc (version 3.0 or 3.3) with -O2 (or higer) produces
wrong code from a very short program ...

Environment:
System: Linux camelot 2.4.19 #1 Fri Aug 16 17:01:16 CEST 2002 i686 unknown
Architecture: i686

	
host: i386-pc-linux-gnu
build: i386-pc-linux-gnu
target: i386-pc-linux-gnu
configured with: ../src/configure -v --enable-languages=c,c++,java,f77,proto,objc --prefix=/usr --infodir=/share/info --mandir=/share/man --enable-shared --with-gnu-as --with-gnu-ld --with-system-zlib --enable-long-long --enable-nls --without-included-gettext --disable-checking --enable-threads=posix --enable-java-gc=boehm --with-cpp-install-dir=bin --enable-objc-gc i386-linux

How-To-Repeat:
gcc -O2 the_following_file

/* bug in gcc -O2
Reading specs from /usr/lib/gcc-lib/i386-linux/3.0.4/specs
Configured with: ../src/configure -v
--enable-languages=c,c++,java,f77,proto,objc --prefix=/usr
 --infodir=/share/info --mandir=/share/man --enable-shared --with-gnu-as
 --with-gnu-ld --with-system-zlib --enable-long-long --enable-nls
 --without-included-gettext --disable-checking --enable-threads=posix
 --enable-java-gc=boehm --with-cpp-install-dir=bin --enable-objc-gc
 i386-linux
 Thread model: posix
 gcc version 3.0.4

The same problem at another machine
Reading specs from /usr/lib/gcc-lib/i386-linux/3.3/specs
Configured with: ../src/configure -v
--enable-languages=c,c++,java,f77,pascal,objc,ada,treelang --prefix=/usr
--mandir=/usr/share/man --infodir=/usr/share/info
--with-gxx-include-dir=/usr/include/c++/3.3 --enable-shared --with-system-zlib
--enable-nls --without-included-gettext --enable-__cxa_atexit
--enable-clocale=gnu --enable-debug --enable-java-gc=boehm
--enable-java-awt=xlib --enable-objc-gc i386-linux Thread model: posix
gcc version 3.3 (Debian)

****************

When compiled without optimalization, the program behaves correctly, it is
it print lines upto "B f=4, l=12". However, when compiled with -O2, 
it finishes with "  A f=1, l=3",  when the inner while cycle condition
is still satisfied ...
Maybe the two while-cycles are somehow mixed up?

*/

int main()
{
  int i;
  int first= 0;
  int last= 0;

  while (last<3) {
    last = first;
    while(first<=last) {
      first++;
      for (i=0;i<3;i++){
        last++;
        printf("C f=%d, l=%d\n",first,last);
      }
      printf("B f=%d, l=%d\n",first,last);
      if (last>10) return 0;
    }
    printf("  A f=%d, l=%d\n",first,last);
  }

  return 0;
}
------- Additional Comments From samal at kam dot mff dot cuni dot cz  2003-07-16 01:52 -------
Fix:
Compile without optimization or with version 2.95 ... ;-)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]