[Bug c/23109] New: compiler generates wrong code leading to spurious division by zero

p dot van-hoof at qub dot ac dot uk gcc-bugzilla@gcc.gnu.org
Thu Jul 28 10:43:00 GMT 2005


The attached code crashes on a division by zero when compiled as follows:

dogbert> gcc -O1 -funsafe-math-optimizations -ftrapping-math b.c
dogbert> a.out
Floating exception
dogbert> gcc -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../gcc/configure --prefix=/usr/local/gcc410
--enable-languages=c,c++,f95
Thread model: posix
gcc version 4.1.0 20050725 (experimental)

I don't believe that -funsafe-math-optimizations enables -fno-trapping-math, but
to be really sure I added the -ftrapping-math command line option. It makes no
difference.

Taken at face value it looks like the optimizer lifts the division by d outside
the conditional on line 19, even though that could lead to a spurious division
by zero and -ftrapping-math is in effect.

This behavior only shows up on the mainline, and not on the 3.4 and 4.0
branches. A slightly modified version (to enable FP traps on Suns) also crashes
with gcc 4.1.0 on the target sparc-sun-solaris2.9.

-- 
           Summary: compiler generates wrong code leading to spurious
                    division by zero
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: p dot van-hoof at qub dot ac dot uk
                CC: gcc-bugs at gcc dot gnu dot org
GCC target triplet: i686-pc-linux-gnu


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



More information about the Gcc-bugs mailing list