Bug 55700 - i386: incorrect divide-by-zero exception generated
Summary: i386: incorrect divide-by-zero exception generated
Status: RESOLVED DUPLICATE of bug 323
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.7.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-12-14 23:46 UTC by Søren Sandmann Pedersen
Modified: 2012-12-15 02:09 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
The reproducer program (702 bytes, text/x-csrc)
2012-12-14 23:46 UTC, Søren Sandmann Pedersen
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Søren Sandmann Pedersen 2012-12-14 23:46:59 UTC
Created attachment 28972 [details]
The reproducer program

The attached program generates a divide-by-zero on i686 when compiled with -O2.
The divide-by-zero comes from this fragment:

	if (t == 0.0f)
	    b = sa * da;
	else
	    b = sa * sa * d / (t);

which as far as I know should be a legitimate way to ensure division by zero doesn't happen. In particular, the t value generated is a negative zero, which should compare equal to 0.0f unless I'm misunderstanding something.

I have reproduced the bug with 4.7.0 and 4.7.2 running in 32 bit mode, and with 4.7.2 with -m32 on x86-64.

On x86-64:

localhost:~% gcc -m32 -W -Wextra -Wall -g -O2 gccfloat.c -lm
localhost:~% ./a.out 
Floating exception

localhost:~% gcc -v
Using built-in specs.
COLLECT_GCC=/usr/bin/gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.7.2/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --disable-build-with-cxx --disable-build-poststage1-with-cxx --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.7.2 20120921 (Red Hat 4.7.2-2) (GCC)
Comment 1 Andrew Pinski 2012-12-14 23:56:51 UTC
I bet this is a dup of bug 323.
Comment 2 Andrew Pinski 2012-12-14 23:59:37 UTC
In fact using -std=c99 or -ffloat-store it works correctly.
Comment 3 Søren Sandmann Pedersen 2012-12-15 02:09:20 UTC
Yeah, I guess it is. I had forgotten about this issue.

*** This bug has been marked as a duplicate of bug 323 ***