http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52907

             Bug #: 52907
           Summary: Underflowing floating point expressions wrongly folded
                    to zero
    Classification: Unclassified
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: js...@gcc.gnu.org


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; }

Reply via email to