Bug 56020 - FE_INVALID flag not set on comparison with NAN (unordered)
Summary: FE_INVALID flag not set on comparison with NAN (unordered)
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks: 16989
  Show dependency treegraph
 
Reported: 2013-01-17 13:13 UTC by Vincent Lefèvre
Modified: 2019-06-26 05:38 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-01-17 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vincent Lefèvre 2013-01-17 13:13:42 UTC
GCC doesn't set the FE_INVALID flag on comparison with NAN (<=, >=, <, >), e.g. with:

#include <stdio.h>
#include <math.h>
#include <fenv.h>

#pragma STDC FENV_ACCESS ON

int main (void)
{
  double d = NAN;
  int err;

  feclearexcept (FE_INVALID);
  d <= 0.0;
  err = ! fetestexcept(FE_INVALID);
  if (err)
    printf ("The FE_INVALID flag is not set\n");
  return err;
}

$ gcc-snapshot --version
gcc (Debian 20130113-1) 4.8.0 20130113 (experimental) [trunk revision 195136]
[...]
$ gcc-snapshot -std=c99 -Wall nancmp.c -o nancmp -lm
nancmp.c:5:0: warning: ignoring #pragma STDC FENV_ACCESS [-Wunknown-pragmas]
 #pragma STDC FENV_ACCESS ON
 ^
nancmp.c: In function 'main':
nancmp.c:13:3: warning: statement with no effect [-Wunused-value]
   d <= 0.0;
   ^
$ ./nancmp
The FE_INVALID flag is not set

The "statement with no effect" warning would also be incorrect once this bug is fixed.
Comment 1 Richard Biener 2013-01-17 13:21:26 UTC
The comparison is dead.  FENV_ACCESS is not implemented (side-effects on
FENV are not preserved).  Use

  if (d <= 0.0)
    __asm("");

GCC uses ucomisd for the comparison, even with -fsignalling-nans.