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

            Bug ID: 128315
           Summary: wrong code at -O1 and above with -frounding-math: sin
                    and cos of +Inf after feclearexcept leave FE_INVALID
                    clear
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: tree-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>
#include <math.h>
#include <stdio.h>

volatile double v = INFINITY;
volatile double s, c;

int main(void)
{
  double x = v;
  feclearexcept(FE_ALL_EXCEPT);
  s = sin(x);
  c = cos(x);
  printf("%d\n", fetestexcept(FE_INVALID) != 0);
  return 0;
}

godbolt: https://godbolt.org/z/srj5znrGP

sin(+Inf) and cos(+Inf) raise FE_INVALID (C17 F.10.1.5, F.10.1.6), so with
-ftrapping-math -frounding-math -lm the program must print 1, as it does at
-O0, with -O2 -fdisable-tree-sincos, and at -O2 when the cos call is removed.
At -O1, -O2, -O3 and -Os it prints 0, and the -fdump-tree-sincos dump shows the
__builtin_cexpi call that replaces sin and cos placed before the feclearexcept
call.
  • [Bug tree-optimization/128315] N... kyuwoncho18 at gmail dot com via Gcc-bugs

Reply via email to