https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99494
Bug ID: 99494 Summary: isfinite gets optimized away with -Ofast Product: gcc Version: 10.2.0 Status: UNCONFIRMED Keywords: wrong-code Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: arek_koz at o2 dot pl Target Milestone: --- Host: x86_64-pc-linux-gnu Target: x86_64-pc-linux-gnu Build: x86_64-pc-linux-gnu Created attachment 50342 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50342&action=edit stripped _Py_HashDouble CPython compiled with -Ofast hangs forever on python -c 'hash(float("inf"))'. Attached is a program based on stripped _Py_HashDouble from CPython sources. It should print 314159 when it reads an infinite number from the input. It always prints 1 instead (the function gets reduced to "return 1"). When replacing -Ofast with -O3, the problem is gone. Likely to appear on other build/host/target configurations. Version: gcc (Gentoo 10.2.0-r5 p6) 10.2.0 Target architecture: x86_64 (generic) GCC is compiled to execute on: x86_64 (znver2) Invoked command: x86_64-pc-linux-gnu-gcc -Ofast -o bug bug.c My best guess: GCC -Ofast assumes that isfinite(v) is always true for any double v.