It appears, that even with -O0, some "optimizations" are being done. These optimizations change the semantics (meaning) of the code and do the wrong thing. One such item is constant folding. #include <fenv.h> #include <stdio.h> #pragma STDC FENV_ACCESS ON int main(void){ double x; int i; feclearexcept(FE_ALL_EXCEPT); x = 1.0; x /= 3.0; /* should raise inexact; value computed depends upon rounding direction */ i = fetestexcept(FE_ALL_EXCEPT); if( FE_INEXACT != i ){ printf("missing inexact (got %i), x=%g\n", i, x); } return 0; ] If I add 'volatile' to the declaration of x, then the code works. The same kind of problem happens for: x=1.0; x /= 0.0; /* divide by zero */ x=0.0; x /= 0.0; /* invalid */ x=DBL_MAX; x *= DBL_MAX; /* overflow */ x=DBL_MIN; x *= DBL_MIN; /* underflow */
C requires constant folding in various places, and "not doing optimization" is not a bug. The problem is that clang doesn't support the FENV_ACCESS pragma, and LLVM IR doesn't support a way to express it. -Chris
*** Bug 10408 has been marked as a duplicate of this bug. ***
*** This bug has been marked as a duplicate of bug 8100 ***