vivier / qemu-m68k

Other
41 stars 7 forks source link

isinf(1.0/sin(0.0)) yields incorrect result #26

Closed glaubitz closed 6 years ago

glaubitz commented 6 years ago

The following code produces incorrect code on qemu-m68k while working on real hardware:

#include <stdio.h>
#include <math.h>
int main(void){
   double rrdnan,rrdinf,rrdc,rrdzero;
   ;
   /* some math to see if we get a floating point exception */
   rrdzero=sin(0.0); /* don't let the compiler optimize us away */
   rrdnan=0.0/rrdzero; /* especially here */
   rrdinf=1.0/rrdzero; /* and here. I want to know if it can do the magic */
          /* at run time without sig fpe */
   rrdc = rrdinf + rrdnan;
   rrdc = rrdinf / rrdnan;
   if (! isnan(rrdnan)) {printf ("not isnan(NaN) ... "); return 1;}
   if (rrdnan == rrdnan) {printf ("nan == nan ... "); return 1;}
   if (! isinf(rrdinf)) {printf ("not isinf(oo) ... "); return 1;}
   if (! isinf(-rrdinf)) {printf ("not isinf(-oo) ... "); return 1;}
   if (! rrdinf > 0) {printf ("not inf > 0 ... "); return 1;}
   if (! -rrdinf < 0) {printf ("not -inf < 0 ... "); return 1;}
   return 0;
}

On my Amiga 4000, I get:

root@elgar:~> gcc -o rrdtool-test rrdtool-test.c 
root@elgar:~> ./rrdtool-test 
root@elgar:~> echo $?
0
root@elgar:~>

On qemu-m68k, I get:

(sid-m68k-sbuild)root@nofan:/# gcc -o rrdtool-test rrdtool-test.c 
(sid-m68k-sbuild)root@nofan:/# ./rrdtool-test 
not isinf(oo) ... (sid-m68k-sbuild)root@nofan:/# echo $?
1
(sid-m68k-sbuild)root@nofan:/#

See: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=890466

glaubitz commented 6 years ago

Definitely a regression:

root@nofan:~> cp -av qemu-m68k-static.20171228 /local_scratch/sid-m68k-sbuild/usr/bin/qemu-m68k-static 
'qemu-m68k-static.20171228' -> '/local_scratch/sid-m68k-sbuild/usr/bin/qemu-m68k-static'
root@nofan:~> cp -av qemu-m68k-static.20171228 /usr/bin/qemu-m68k-static 
'qemu-m68k-static.20171228' -> '/usr/bin/qemu-m68k-static'
root@nofan:~> chroot /local_scratch/sid-m68k-sbuild/
bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
(sid-m68k-sbuild)root@nofan:/# gcc -o rrdtool-test rrdtool-test.c 
(sid-m68k-sbuild)root@nofan:/# ./rrdtool-test 
not isinf(oo) ... (sid-m68k-sbuild)root@nofan:/# exit
root@nofan:~> 
root@nofan:~> cp -av qemu-m68k-static.20170705 /usr/bin/qemu-m68k-static 
'qemu-m68k-static.20170705' -> '/usr/bin/qemu-m68k-static'
root@nofan:~> cp -av qemu-m68k-static.20170705 /local_scratch/sid-m68k-sbuild/usr/bin/qemu-m68k-static 
'qemu-m68k-static.20170705' -> '/local_scratch/sid-m68k-sbuild/usr/bin/qemu-m68k-static'
root@nofan:~> chroot /local_scratch/sid-m68k-sbuild/
bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
(sid-m68k-sbuild)root@nofan:/# gcc -o rrdtool-test rrdtool-test.c 
(sid-m68k-sbuild)root@nofan:/# ./rrdtool-test 
(sid-m68k-sbuild)root@nofan:/#

The compiled binary from July 2017 works, the binary from December 2017 has the bug.

vivier commented 6 years ago

Please try latest version of qemu from branch m68k-dev: it works for me.

glaubitz commented 6 years ago

Just cloned freshly from git, switched to m68k-dev branch and built a static binary. Doesn't work.

With this version, even gcc is crashing.

(sid-m68k-sbuild)root@nofan:/# gcc -o rrdtool-test rrdtool-test.c 
rrdtool-test.c:1:0: internal compiler error: Segmentation fault
 #include <stdio.h>

executable file is not ELF
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-7/README.Bugs> for instructions.
(sid-m68k-sbuild)root@nofan:/# ./rrdtool-test 
not isinf(oo) ... (sid-m68k-sbuild)root@nofan:/#
vivier commented 6 years ago

OK, I'm able to reproduce it

vivier commented 6 years ago

Please try this isinf-fix.txt

vivier commented 6 years ago

Fix pushed in m68k-dev branch.

Please, open a new issue for the gcc internal error

glaubitz commented 6 years ago

Yes, the latest revision of m68k-dev fixes the problem. Closing.

gcc is still segfaulting though.