public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c/7949: Mishandled double != 0.0 at -O1
@ 2002-09-17  7:06 Ake.Sandgren
  0 siblings, 0 replies; only message in thread
From: Ake.Sandgren @ 2002-09-17  7:06 UTC (permalink / raw)
  To: gcc-gnats, debian-gcc

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2585 bytes --]


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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-09-17 14:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-17  7:06 c/7949: Mishandled double != 0.0 at -O1 Ake.Sandgren

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).