wbhart / mpir

Multiple Precision Integers and Rationals
GNU General Public License v3.0
229 stars 135 forks source link

GCC 12: test FAIL: t-get_d #295

Open marxin opened 2 years ago

marxin commented 2 years ago

The test crashes with:

mpn_get_d wrong, didn't get 0.0 on underflow
  nsize    1
  exp      -999999
  sign     0
  got      =[00 00 00 00 00 00 00 1C] 8.0863492239043898133e-174
Aborted (core dumped)

Started with GCC revision https://github.com/gcc-mirror/gcc/commit/0288527f47cec6 but I think it's bug in MPIR, please run it with fsanitize=undefined:

LD_LIBRARY_PATH=.libs ./tests/mpn/.libs/t-get_d
get_d.c:107:154: runtime error: signed integer overflow: 2147483647 - -100 cannot be represented in type 'long int'
    #0 0xf7f90772 in __gmpn_get_d /home/marxin/Programming/mpir/mpn/get_d.c:107
    #1 0x565576cc in check_onebit /home/abuild/rpmbuild/BUILD/mpir-3.0.0/tests/mpn/t-get_d.c:101
    #2 0x5655745f in main /home/abuild/rpmbuild/BUILD/mpir-3.0.0/tests/mpn/t-get_d.c:474
    #3 0xf7c67354 in __libc_start_call_main (/lib/libc.so.6+0x25354)
    #4 0xf7c67425 in __libc_start_main@@GLIBC_2.34 (/lib/libc.so.6+0x25425)
    #5 0x565574c6 in _start (/home/abuild/rpmbuild/BUILD/mpir-3.0.0/tests/mpn/.libs/t-get_d+0x24c6)

get_d.c:160:31: runtime error: shift exponent 32 is too large for 32-bit type 'long unsigned int'
    #0 0xf7f4358b in __gmpn_get_d /home/marxin/Programming/mpir/mpn/get_d.c:160
    #1 0x565576cc in check_onebit /home/abuild/rpmbuild/BUILD/mpir-3.0.0/tests/mpn/t-get_d.c:101
    #2 0x5655745f in main /home/abuild/rpmbuild/BUILD/mpir-3.0.0/tests/mpn/t-get_d.c:474
    #3 0xf7c67354 in __libc_start_call_main (/lib/libc.so.6+0x25354)
    #4 0xf7c67425 in __libc_start_main@@GLIBC_2.34 (/lib/libc.so.6+0x25425)
    #5 0x565574c6 in _start (/home/abuild/rpmbuild/BUILD/mpir-3.0.0/tests/mpn/.libs/t-get_d+0x24c6)

get_d.c:161:31: runtime error: shift exponent 32 is too large for 32-bit type 'long unsigned int'
    #0 0xf7f4359b in __gmpn_get_d /home/marxin/Programming/mpir/mpn/get_d.c:161
    #1 0x565576cc in check_onebit /home/abuild/rpmbuild/BUILD/mpir-3.0.0/tests/mpn/t-get_d.c:101
    #2 0x5655745f in main /home/abuild/rpmbuild/BUILD/mpir-3.0.0/tests/mpn/t-get_d.c:474
    #3 0xf7c67354 in __libc_start_call_main (/lib/libc.so.6+0x25354)
    #4 0xf7c67425 in __libc_start_main@@GLIBC_2.34 (/lib/libc.so.6+0x25425)
    #5 0x565574c6 in _start (/home/abuild/rpmbuild/BUILD/mpir-3.0.0/tests/mpn/.libs/t-get_d+0x24c6)
marxin commented 2 years ago

I'm attaching self-container test-case get.c.txt

that works with -O2 -fwrapv. But as mentioned, it contains undefined behavior, namely the 'signed integer overflow'.