https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128007
Bug ID: 128007
Summary: wrong code with -frounding-math -ffinite-math-only: x
- x is folded to +0.0 under FE_DOWNWARD
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: rtl-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: kyuwoncho18 at gmail dot com
Target Milestone: ---
Target: x86_64-pc-linux-gnu
#include <fenv.h>
__attribute__((noipa)) double f(double x) { return x - x; }
int main(void) {
fesetround(FE_DOWNWARD);
if (!__builtin_signbit(f(3.0)))
__builtin_abort();
}
godbolt: https://godbolt.org/z/YfjMeM75r
Under round-toward-negative, 3.0 - 3.0 is -0.0, which f returns at -O0 and at
-O2 -frounding-math (linked with -lm), and the program exits normally. With
-frounding-math -ffinite-math-only at -O1, -O2, -O3 or -Os, f returns +0.0 and
the program aborts. The runtime testcase in PR98420 comment 0 still aborts on
current trunk with the same flags.
Disclaimer: This test case was generated by a fuzzer, and the report was
written with LLM assistance.