I tried this program on many versions of GCC and it seems to trigger errors.
The curious can edit the program and un-comment various combinations of lines
to chase the error. It compiles as-is and demonstrates the error.


# gcc-3.3 -v
Reading specs from /usr/lib/gcc-lib/i486-linux/3.3.5/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
--enable-__cxa_atexit --with-system-zlib --enable-nls
--without-included-gettext --enable-clocale=gnu --enable-debug
--enable-java-gc=boehm --enable-java-awt=xlib --enable-objc-gc i486-linux
Thread model: posix
gcc version 3.3.5 (Debian 1:3.3.5-13)


# gcc-3.4 -v
Reading specs from /usr/lib/gcc/i486-linux-gnu/3.4.6/specs
Configured with: ../src/configure -v --enable-languages=c,c++,f77,pascal
--prefix=/usr --libexecdir=/usr/lib --with-gxx-include-dir=/usr/include/c++/3.4
--enable-shared --with-system-zlib --enable-nls --without-included-gettext
--program-suffix=-3.4 --enable-__cxa_atexit --enable-clocale=gnu
--enable-libstdcxx-debug --with-tune=i686 i486-linux-gnu
Thread model: posix
gcc version 3.4.6 (Debian 3.4.6-5)


# gcc-4.1 -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu
--enable-libstdcxx-debug --enable-mpfr --with-tune=i686
--enable-checking=release i486-linux-gnu
Thread model: posix
gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)


# gcc -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: /root/downloads/gcc-4_2-branch/configure --verbose
--enable-languages=c,ada,c++,fortran,java,objc,obj-c++ --with-tune=athlon-xp
--prefix=/usr --enable-objc-gc --enable-concept-checks --disable-multilib
--with-gxx-include-dir=/usr/include/c++/4.2 --enable-libstdcxx-debug
--enable-static --enable-shared --enable-initfini-array --enable-__cxa_atexit
--enable-threads=posix --enable-version-specific-runtime-libs --enable-libssp
--enable-libmudflap --enable-libgomp --disable-werror --enable-nls
--with-included-gettext --enable-decimal-float --with-long-double-128
--enable-debug --enable-java-gc=boehm --with-x --x-includes=/usr/X11R6/include
--x-libraries=/usr/X11R6/lib --enable-java-awt=gtk,xlib --enable-gtk-cairo
--enable-qt-peer --enable-xmlj --enable-gconf-peer --enable-tool-wrappers
--with-gjdoc --enable-portable-native-sync --enable-libgcj-multifile
--with-stabs --enable-hash-synchronization --enable-gc-debug
--enable-interpreter --with-system-zlib --enable-libada --with-tls
--with-cpu=athlon-xp --with-arch=athlon-xp --enable-checking
Thread model: posix
gcc version 4.2.0 20070501 (prerelease)


# /usr/test/bin/gcc -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: /root/downloads/gcc-4_3-trunk/configure --verbose
--enable-languages=c,ada,c++,fortran,java,objc,obj-c++ --prefix=/usr/test
--enable-objc-gc --enable-concept-checks --disable-multilib
--with-gxx-include-dir=/usr/test/include/c++/4.3 --enable-libstdcxx-debug
--enable-static --enable-shared --enable-initfini-array --enable-__cxa_atexit
--enable-threads=posix --enable-version-specific-runtime-libs --enable-libssp
--enable-libmudflap --enable-libgomp --disable-werror --enable-nls
--with-included-gettext --enable-decimal-float --enable-debug
--enable-java-gc=boehm --with-x --x-includes=/usr/X11R6/include
--x-libraries=/usr/X11R6/lib --enable-java-awt=gtk,xlib --enable-gtk-cairo
--enable-qt-peer --enable-xmlj --enable-gconf-peer --enable-tool-wrappers
--enable-portable-native-sync --enable-examples --with-stabs
--enable-hash-synchronization --enable-gc-debug --enable-interpreter
--with-system-zlib --enable-libada --with-tls --with-tune=athlon-xp
--with-cpu=athlon-xp --with-arch=athlon-xp
--enable-stage1-checking=assert,gc,misc,rtl,rtlflag,runtime,tree
Thread model: posix
gcc version 4.3.0 20070609 (experimental)



Here is what this program prints using gcc 3.3, 3.4, 4.1, 4.2, or 4.3 on
i686-pc-linux-gnu:


Try uncommenting various combinations of the printf() statements used in
this program to hide or trigger the abs/printf error. Printing QUESTION1
with abs() gives an error, printing QUESTION1 without using abs() is OK.
Uncommenting the unused sprintf() corrects printf() output, usually. The
program should print zero all the time but accuracy is another matter.
Notice in number 7 that it prints PLUS zero but otherwise NEGATIVE zero.
n= 1  QUESTION1=-0.000  QUESTION2=-0.000 
n= 1                    QUESTION2=+0.414 
n= 2  QUESTION1=-0.000  QUESTION2=-0.000 
n= 2                    QUESTION2=+0.236 
n= 3  QUESTION1=-0.000  QUESTION2=-0.000 
n= 3                    QUESTION2=+0.162 
n= 4  QUESTION1=-0.000  QUESTION2=-0.000 
n= 4                    QUESTION2=+0.123 
n= 5  QUESTION1=-16522743262502092537856.000  QUESTION2=-0.000 
n= 5                    QUESTION2=+0.099 
n= 6 
QUESTION1=-3721029422797390905264552616897318787693080694838285023794783705131793115153378545691097982837335151135903481248849330176.000
 QUESTION2=-0.000 
n= 6                    QUESTION2=+0.083 
n= 7  QUESTION1=+0.000  QUESTION2=-0.000 
n= 7                    QUESTION2=+0.071 
n= 8 
QUESTION1=+6031613735721727548569690008146484981792835303047262360203552731912464214457090838248418515794553484912424369429741130556727473755197034894720012190408277107933184.000
 QUESTION2=-0.000 
n= 8                    QUESTION2=+0.062 
n= 9 
QUESTION1=-255317213055347619461852498717677545874233184953584593781149061302390209188816780225236890307385767936779025481685187363340288.000
 QUESTION2=-0.000 
n= 9                    QUESTION2=+0.055 



On Cygwin 3.4.4 the output looks like this:

n= 1  QUESTION1=-0.000 
QUESTION2=+10616123003695640721911045079668438242222030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000
 
n= 1                    QUESTION2=+0.414 
n= 2  QUESTION1=-0.000 
QUESTION2=+10616123001910498887278330503471575952153310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000
 
n= 2                    QUESTION2=+0.236 
n= 3  QUESTION1=-0.000 
QUESTION2=+10616123000538905870424505112676888844605500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000
 
n= 3                    QUESTION2=+0.162 
...

Equally bad even though it looks more consistent.


-- 
           Summary: [3.3 / 3.4 / 4.1 / 4.2 / 4.3 Regression] abs / printf
                    bug
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: rob1weld at aol dot com


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

Reply via email to