------- Comment #9 from kreckel at ginac dot de 2006-09-23 22:58 -------
(In reply to comment #8)
I am still not entirely sure whether we are really talking about the same
problem. The original problem was that the compiler optimized assuming that the
floating point division cannot have side effects, such that the offending
division happens after the call to fetestexcept(3):
#include <fenv.h>
#include <stdio.h>
int main()
{
double x = (double)printf("") + 1.0; // one
double y = (double)printf(""); // zero
feclearexcept(FE_ALL_EXCEPT);
double z = x / y; // should set FE_DIVBYZERO
if (fetestexcept(FE_ALL_EXCEPT)) {
printf("flag set after call.\n");
}
printf("%f/%f==%f\n",x,y,z);
}
Neither -ftrapping-math, nor -frounding-math change anything, as long as -O1 is
turned on: The printf inside the if statement is *not* executed.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29186