[Bug c/38960] New: Wrong floating point reorder
abramobagnara at tin dot it
gcc-bugzilla@gcc.gnu.org
Sat Jan 24 14:57:00 GMT 2009
The program below show that gcc reorder floating point instructions in such a
way to make inexact checking fruitless.
Reading generated assembler I see two problems:
1) the cast to float in x assignment is executed *after* fetestexcept and not
before as it's written (and needed to get the correct result). This infringes
C99 standard sequence point rules.
2) the second division is not recomputed (because CSE), then inexact flag is
not changed after feclearexcept
I guess that the latter is due to missing #pragma STDC FENV_ACCESS
implementation, but the former undermine the whole fetestexcept usability.
$ cat bug.c
#include <fenv.h>
#include <stdio.h>
double vf = 0x0fffffff;
double vg = 0x10000000;
/* vf/vg is exactly representable as IEC559 64 bit floating point,
while it's not representable exactly as a 32 bit one */
int main() {
double a = vf;
double b = vg;
feclearexcept(FE_INEXACT);
float x;
x = a / b;
printf("%i %.1000g\n", fetestexcept(FE_INEXACT), x);
feclearexcept(FE_INEXACT);
double y;
y = a / b;
printf("%i %.1000g\n", fetestexcept(FE_INEXACT), y);
return 0;
}
$ gcc -O2 bug.c -lm
$ ./a.out
0 1
0 0.9999999962747097015380859375
$
--
Summary: Wrong floating point reorder
Product: gcc
Version: 4.3.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: abramobagnara at tin dot it
GCC target triplet: i486-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38960
More information about the Gcc-bugs
mailing list