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

            Bug ID: 128313
           Summary: -fsignaling-nans: x != 1.0 with a signaling NaN x is
                    folded at -O1 and above, so FE_INVALID is not raised
           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>
#include <stdio.h>
#include <string.h>

int main(void)
{
  unsigned long long bits = 0x7ff0000000000001ULL; /* signaling NaN */
  double x;
  memcpy(&x, &bits, sizeof x);
  feclearexcept(FE_ALL_EXCEPT);
  int ne = x != 1.0;
  printf("ne=%d invalid=%d\n", ne, fetestexcept(FE_INVALID) != 0);
  return 0;
}

godbolt: https://godbolt.org/z/fs478rMTE

A comparison with a signaling NaN operand raises FE_INVALID, so with
-fsignaling-nans -ftrapping-math -frounding-math -lm the program must print
"ne=1 invalid=1", as it does at -O0 and with -O1 -fno-tree-fre. At -O1, -O2,
-O3 and -Os it prints "ne=1 invalid=0".
  • [Bug middle-end/128313] New: -fs... kyuwoncho18 at gmail dot com via Gcc-bugs

Reply via email to