This is the mail archive of the gcc-prs@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]

c/7949: Mishandled double != 0.0 at -O1


>Number:         7949
>Category:       c
>Synopsis:       Mishandling of double != 0.0 at -O1
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Tue Sep 17 07:06:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     ┼ke Sandgren
>Release:        3.2.1 20020830 (Debian prerelease) (Debian testing/unstable)
>Organization:
HPC2N, Umeň University, Sweden
>Environment:
System: Linux y-boda.hpc2n.umu.se 2.4.18.dell.i8k.5 #1 Fri Jun 7 11:15:41 CEST 2002 i686 unknown
Architecture: i686

	
host: i386-pc-linux-gnu
build: i386-pc-linux-gnu
target: i386-pc-linux-gnu
configured with: /mnt/data/gcc-3.1/gcc-3.2-3.2.1ds0/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/c++/3.2 --enable-shared --with-system-zlib --enable-nls --without-included-gettext --enable-__cxa_atexit --enable-java-gc=boehm --enable-objc-gc i386-linux
>Description:
The following code gives different results with -O0 and -O1/2 on x86
machines.
It works (with the relevant bigendian change) on sparc solaris8.
gcc 2.95.4 gives correct output at all -O levels.
gcc-3.[01] gives the same error as 3.2

This is IEEE correct code.

>How-To-Repeat:

double rvals(int v)
{
    union a {
	double d;
	unsigned int i[2];
    } aa;

    if (v == 0) {
	/* Return maximum double */
	/* For bigendian machines swap i[0] and i[1] */
	aa.i[0] = 0xffffffff;
	aa.i[1] = 0x7fefffff;
    } else {
	/* Return minimum double */
	/* For bigendian machines swap i[0] and i[1] */
	aa.i[0] = 0;
	aa.i[1] = 0x100000;
    }

    return aa.d;
}
main()
{
    double rmax, rmin, inf, zero;
    union a {
	double d;
	unsigned int i[2];
    } aa;

    rmax = rvals(0);
    rmin = rvals(1);

    inf = rmax / rmin;
    zero = 1.0 / inf;

    if (zero != 0.0) {
	printf("ERROR\n");
	aa.d = rmax;
	printf("rmax: i[0] = %x, i[1] = %x\n", aa.i[0], aa.i[1]);
	aa.d = rmin;
	printf("rmin: i[0] = %x, i[1] = %x\n", aa.i[0], aa.i[1]);
	aa.d = inf;
	printf("inf: i[0] = %x, i[1] = %x\n", aa.i[0], aa.i[1]);
	aa.d = zero;
	printf("zero: i[0] = %x, i[1] = %x\n", aa.i[0], aa.i[1]);
    } else {
	printf("This works.\n");
    }
}
# gcc-3.2 -O0 -o bug gcc.bug.c
# ./bug
This works.

# gcc-3.2 -O1 -o bug gcc.bug.c
# ./bug
ERROR
rmax: i[0] = ffffffff, i[1] = 7fefffff
rmin: i[0] = 0, i[1] = 100000
inf: i[0] = 0, i[1] = 7ff00000
zero: i[0] = 0, i[1] = 0

>Fix:
	
>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]