[Bug c/57455] New: "internal compiler error: Floating point exception", in seemingly random places

2013-05-29 Thread theartlav at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57455

Bug ID: 57455
   Summary: "internal compiler error: Floating point exception",
in seemingly random places
   Product: gcc
   Version: 4.8.0
Status: UNCONFIRMED
  Severity: major
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: theartlav at gmail dot com

Created attachment 30216
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30216&action=edit
Bug examples

System is Intel Atom CPU (eeepc 901 laptop), 32 bit LFS Linux, 3.9.3 kernel.
Tried GCC 4.8.0, compiled by itself, GCC 4.7.2 compiled with 4.8.0 and GCC
4.7.2 compiled by itself.

During compilation of several different projects, including GCC itself, the
compiler produces a "internal compiler error: Floating point exception" error.

This error can often be worked around by reshuffling the statements in the C
code being compiled (i.e. changing z=a/(b+c); to x=b+c; z=a/x;).
I thought it was a GCC 4.8.0 bug at first, so i compiled GCC 4.7.2, and tried
it, but am getting exactly the same errors.

Included are reproduction examples from compiling gcc 4.7.2 with itself, and
compiling Python 2.7.5 with gcc 4.7.2.
With 4.7.2 the errors happen in exactly the same way as with 4.8.0, but i no
longer have 4.8.0. If it's critical, i can build it again, and report from it.

GCC configuration options: configure --prefix=/usr --libexecdir=/usr/lib
--enable-shared --enable-threads=posix --enable-__cxa_atexit
--enable-clocale=gnu --enable-languages=c,c++ --disable-multilib
--with-system-zlib

Full output for cmathmodule.i (comes from Python 2.7.5):
gcc -pthread -fPIC -fno-strict-aliasing -DNDEBUG -g -fwrapv -O0 -Wall
-Wstrict-prototypes -I. -IInclude -I./Include -I/usr/include
-I/usr/local/include -I/mnt/sdc1/bld/Python-2.7.5/Include
-I/mnt/sdc1/bld/Python-2.7.5 -c
/mnt/sdc1/bld/Python-2.7.5/Modules/cmathmodule.c -o
build/temp.linux-i686-2.7/mnt/sdc1/bld/Python-2.7.5/Modules/cmathmodule.o
-save-temps -v

Using built-in specs.
COLLECT_GCC=gcc
Target: i686-pc-linux-gnu
Configured with: ../gcc-4.7.2/configure --prefix=/usr --libexecdir=/usr/lib
--enable-shared --enable-threads=posix --enable-__cxa_atexit
--enable-clocale=gnu --enable-languages=c,c++ --disable-multilib
--with-system-zlib
Thread model: posix
gcc version 4.7.2 (GCC)
COLLECT_GCC_OPTIONS='-pthread' '-fPIC' '-fno-strict-aliasing' '-D' 'NDEBUG'
'-g' '-fwrapv' '-O0' '-Wall' '-Wstrict-prototypes' '-I' '.' '-I' 'Include' '-I'
'./Include' '-I' '/usr/include' '-I' '/usr/local/include' '-I'
'/mnt/sdc1/bld/Python-2.7.5/Include' '-I' '/mnt/sdc1/bld/Python-2.7.5' '-c'
'-o'
'build/temp.linux-i686-2.7/mnt/sdc1/bld/Python-2.7.5/Modules/cmathmodule.o'
'-save-temps' '-v' '-mtune=generic' '-march=pentiumpro'
 /usr/lib/gcc/i686-pc-linux-gnu/4.7.2/cc1 -E -quiet -v -I . -I Include -I
./Include -I /usr/include -I /usr/local/include -I
/mnt/sdc1/bld/Python-2.7.5/Include -I /mnt/sdc1/bld/Python-2.7.5 -D_REENTRANT
-D NDEBUG /mnt/sdc1/bld/Python-2.7.5/Modules/cmathmodule.c -mtune=generic
-march=pentiumpro -Wall -Wstrict-prototypes -fPIC -fno-strict-aliasing -fwrapv
-g -fworking-directory -O0 -fpch-preprocess -o cmathmodule.i
ignoring nonexistent directory
"/usr/lib/gcc/i686-pc-linux-gnu/4.7.2/../../../../i686-pc-linux-gnu/include"
ignoring duplicate directory "./Include"
ignoring duplicate directory "/usr/include"
  as it is a non-system directory that duplicates a system directory
ignoring duplicate directory "/usr/local/include"
  as it is a non-system directory that duplicates a system directory
ignoring duplicate directory "/mnt/sdc1/bld/Python-2.7.5/Include"
ignoring duplicate directory "/mnt/sdc1/bld/Python-2.7.5"
#include "..." search starts here:
#include <...> search starts here:
 .
 Include
 /usr/lib/gcc/i686-pc-linux-gnu/4.7.2/include
 /usr/local/include
 /usr/lib/gcc/i686-pc-linux-gnu/4.7.2/include-fixed
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-pthread' '-fPIC' '-fno-strict-aliasing' '-D' 'NDEBUG'
'-g' '-fwrapv' '-O0' '-Wall' '-Wstrict-prototypes' '-I' '.' '-I' 'Include' '-I'
'./Include' '-I' '/usr/include' '-I' '/usr/local/include' '-I'
'/mnt/sdc1/bld/Python-2.7.5/Include' '-I' '/mnt/sdc1/bld/Python-2.7.5' '-c'
'-o'
'build/temp.linux-i686-2.7

[Bug c/57455] "internal compiler error: Floating point exception", in seemingly random places

2013-05-31 Thread theartlav at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57455

--- Comment #2 from Artyom  ---
> Can you try to get at a backtrace using gdb?

Looks like i found the problem.

gcc -wrapper gdb,--args cmathmodule.i
...
Program received signal SIGFPE, Arithmetic exception.
0xb7f17c31 in __gmpn_divrem_2 () from /usr/lib/libgmp.so.10
(gdb) bt
#0  0xb7f17c31 in __gmpn_divrem_2 () from /usr/lib/libgmp.so.10
#1  0xed12ce80 in ?? ()
#2  0xbcfb951c in ?? ()
#3  0x6dd89843 in ?? ()
#4  0x4004abe0 in ?? ()
#5  0x55b8c549 in ?? ()
#6  0x8b827a40 in ?? ()
#7  0x0001 in ?? ()
#8  0xb7fef9c9 in ___tls_get_addr_internal () from /lib/ld-linux.so.2
#9  0xb7f75618 in mpfr_mul () from /usr/lib/libmpfr.so.4
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

Rebuilt GMP, no difference.
Rebuilt MPFR, bug gone.

Previously MPFR was built in a chroot on another machine with AMD CPU, maybe it
picked up some wrong processor optimizations, that fail on Intel's?

In any case, rebuilding MPFR natively removed the problem.
Sorry for a false alarm.