https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128634
Bug ID: 128634
Summary: wrong code at -O0: long long -> _Decimal32 conversion
rounds twice (libbid __bid_floatdisd via _Decimal64)
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: dfp, wrong-code
Severity: normal
Priority: P3
Component: libgcc
Assignee: unassigned at gcc dot gnu.org
Reporter: jeffchen006 at gmail dot com
Target Milestone: ---
int printf(const char *, ...);
int main(void) {
long long x = 10000005000000001;
_Decimal32 d = x;
printf("%d\n", d == 1000001E10DF);
}
$ gcc -O0 t.c && ./a.out
0
$ gcc -O1 t.c && ./a.out
1
Expected: 1. 10000005000000001 rounded to 7 digits is 1000001E+10 (the dropped
part 5000000001 is more than half). -O1 folds correctly. -O0 calls
__bid_floatdisd, which goes through _Decimal64 (10000005000000000, then a tie,
round to even: 1000000E+10).
Suspected cause: libgcc/config/libbid _di_to_sd.c / _udi_to_sd.c convert
through _Decimal64 (double rounding). Code from the 2007 libbid import.
Known to fail: 8.5.0, 10.5.0, 11.4.0, 12.5.0, 13.4.0, 14.3.0, 15.2.0, 16.2.0,
17.0.
-O0 -fsanitize=undefined,address is clean.
gcc version 17.0.0 20261111 (experimental) (a2a11abfad3), x86_64-pc-linux-gnu
Configured with: --enable-languages=c,c++ --disable-multilib
--disable-bootstrap --enable-checking=release