https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128004

            Bug ID: 128004
           Summary: wrong code with -frounding-math: 1.0 + -1.0 is folded
                    to +0.0 under FE_DOWNWARD
           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: kyuwoncho18 at gmail dot com
  Target Milestone: ---
            Target: x86_64-pc-linux-gnu

#include <fenv.h>

int main(void) {
  double a = 1.0, b = -1.0;
  fesetround(FE_DOWNWARD);
  double r = a + b;
  if (!__builtin_signbit(r))
    __builtin_abort();
}

godbolt: https://godbolt.org/z/MjYP9raWP

With -O0 -frounding-math the program exits normally: in roundTowardNegative the
exact sum 1.0 + -1.0 is -0.0. With -O1, -O2, -O3 or -Os -frounding-math (linked
with -lm) r is +0.0 and the program aborts.

Disclaimer: This test case was generated by a fuzzer, and the report was
written with LLM assistance.

Reply via email to