fold-const.c:const_binop avoids folding overflowing floating-point operations on constant operands to constants if flag_trapping_math: /* Don't constant fold this floating point operation if the result has overflowed and flag_trapping_math. */ if (flag_trapping_math && MODE_HAS_INFINITIES (mode) && REAL_VALUE_ISINF (result) && !REAL_VALUE_ISINF (d1) && !REAL_VALUE_ISINF (d2)) return NULL_TREE; However, there is no such check for underflow. This has the effect of miscompiling various code in glibc's libm that expects operations on constant values to be usable to produce an overflow or underflow exception when required. In particular, this appears to cause <http://sourceware.org/bugzilla/show_bug.cgi?id=10846>. Testcase, tested x86 and x86_64 (-O2 -ftrapping-math, wrongly compiled to return 0 rather than doing the given computation): static const double a = 1e-300; double f (void) { return a * a; }
Does real.c even communicate this fact?
On Tue, 10 Apr 2012, rguenth at gcc dot gnu.org wrote: > Does real.c even communicate this fact? You can identify underflow from the result of multiplication or division being zero or subnormal (unless an operand is zero or infinite), just as overflow is identified from an infinite result. Information about subnormal results may not be conveniently communicated by real.c, but simply handling zero results here would be enough for the use cases in glibc.
Still happens.