https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128643
Bug ID: 128643
Summary: [14/15/16/17 Regression] wrong code at -O1:
(float)u128 * 0.0f folded to 0, but the conversion can
give +Inf (NaN expected) since r12-1394
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: jeffchen006 at gmail dot com
Target Milestone: ---
int printf(const char *, ...);
static const float z = 0;
unsigned __int128 u = -1;
int main(void) {
printf("%d\n", (float)u * z != 0);
}
$ gcc -O0 t.c && ./a.out
1
$ gcc -O1 t.c && ./a.out
0
Expected: 1. (float)(2^128 - 1) rounds to +Inf (it is more than FLT_MAX + half
ulp), and Inf * 0 is NaN, so NaN != 0 is 1. The same happens for int ->
_Float16.
Suspected cause: fold-const tree_expr_maybe_infinite_p / tree_expr_finite_p
treat every FLOAT_EXPR as finite (first bad a761829ae06, 2021, PR96392).
Related: PR110335.
Known to fail: 12.5.0, 13.4.0, 14.3.0, 15.2.0, 16.2.0, 17.0.
Known to work: 8.5.0, 10.5.0, 11.4.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
Related: PR110335, PR96392.