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]

optimization/7726: Fails to produce the correct implementation-dependant output for loop optimization under x86 -> optimizes away a loop that should complete


>Number:         7726
>Category:       optimization
>Synopsis:       Fails to produce the correct implementation-dependant output for loop optimization under x86 -> optimizes away a loop that should complete
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Aug 26 08:36:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Carlos O'Donell
>Release:        gcc version 2.95.4 20011002 (Debian prerelease),  gcc version 3.0.4, gcc version 3.1.1 20020703 (Debian prerelease)
>Organization:
>Environment:
gcc       2.95.4-16         The GNU C compiler.
gcc-3.0   3.0.4-10          The GNU C compiler.
gcc-3.1   3.1.1-0pre3       The GNU C compiler.
libc6     2.2.5-7           GNU C Library
binutils  2.12.90.0.9-1     GNU Binutils
(Slightly modified dpkg -l output)
>Description:
Fails to produce the correct implementation-dependant output.

The compiler optimizes away the while loop that would 
eventually exit.

With 'gcc -O9 -o test test.c'
On the following compilers:

Reading specs from /usr/lib/gcc-lib/i386-linux/2.95.4/specs
gcc version 2.95.4 20011002 (Debian prerelease)

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

Reading specs from /usr/lib/gcc-lib/i386-linux/3.1.1/specs
Configured with: /mnt/data/gcc-3.1/gcc-3.1-3.1.1ds2/src/configure -v --enable-languages=c,c+
+,java,f77,proto,objc,ada --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --
with-gxx-include-dir=/usr/include/g++-v3-3.1 --enable-shared --with-system-zlib --enable-lon
g-long --enable-nls --without-included-gettext --enable-clocale=gnu --enable-__cxa_atexit --
enable-threads=posix --enable-java-gc=boehm --enable-objc-gc i386-linux
Thread model: posix
gcc version 3.1.1 20020703 (Debian prerelease)

---
union sconvert {
        unsigned int uval;
        signed int sval;
};

int main()
{
        union sconvert i = { 0 };
        union sconvert oldi = { 0 };

        i.uval++;
        while (i.sval > oldi.sval) {
                oldi = i;
                i.uval++;
        }
        return oldi.sval;
}
---

Signed overflow is undefined in ANSI C, but this
particular example uses defined unsigned overflow to
carry out the addition.

The comparison is between to signed values that gcc
must convert. This conversion is implementation-dependant.
As such, the implementation-dependant behaviour cannot
be optimized away and must remain consistent across 
optimization levels.

This bug is a correction/refinement of a previous bug that 
incorrectly assumed signed overflow to be defined.
>How-To-Repeat:
Insert the code in 'Description' -> test.c
$ gcc -O9 -o test test.c
$ ./test
This will run forever since the exit case for the loop
has been optimized away.
>Fix:
Workaround: 
Don't use -ON (N>0)
or
Use and 'asm' statement as an optimization barrier.
>Release-Note:
>Audit-Trail:
>Unformatted:


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