https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116680
Bug ID: 116680
Summary: wrong code at -O1 and above with "-ffast-math"
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: rtl-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: iamanonymous.cs at gmail dot com
Target Milestone: ---
*******************************************************************************
OS and Platform:
$ uname -a:
Linux 65dac7c84719 4.15.0-213-generic #224-Ubuntu SMP Mon Jun 19 13:30:12 UTC
2023 x86_64 x86_64 x86_64 GNU/Linux
*******************************************************************************
gcc version:
Using built-in specs.
COLLECT_GCC=/home/software/gcc-trunk-3aa004f/bin/gcc
COLLECT_LTO_WRAPPER=/home/software/gcc-trunk-3aa004f/libexec/gcc/x86_64-pc-linux-gnu/15.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc/configure --disable-multilib --disable-bootstrap
--enable-languages=c,c++ --prefix=/home/software/gcc-trunk-3aa004f
--enable-coverage
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 15.0.0 20240630 (experimental) (GCC)
*******************************************************************************
Program:
$ cat mutant.c
float a = 1.e20f;
inline __attribute__((optimize("-fno-associative-math")))
__attribute__((always_inline)) float
b() {
return 1.f + a - a;
}
void c() {
if (b())
__builtin_abort();
}
void main() { c(); }
*******************************************************************************
Command Lines:
$ gcc -ffast-math mutant.c -o a.out; ./a.out
$ gcc -O1 -ffast-math mutant.c -o a.out; ./a.out
Aborted (core dumped)
Compiler Explorer: https://godbolt.org/z/n3z8aYrY4
I'm wondering whether it's a bug, as it seems related to floating-point
precision.