builtins.c:expand_errno_check() can only handle setting EDOM if the operation
returns NaN on error.  Most overflow/underflow conditions result in -Inf/+Inf
instead and with non-default rounding-mode (-frounding-math) the maximum or
minimum floating-point value will be returned (round to -Inf/+Inf or zero).

One testcase:

#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
  double y = atof(argv[1]);
  double x = exp (y);
  printf("%.6e %.6e\n", y, x);
  perror("errno");
  return 0;
}

which shall print "errno: Numerical result out of range" if you pass 5000
to the testcase executable but prints "errno: Success" if you build with
-funsafe-math-optimizations on i686 which will do an inline expansion for
exp ().


-- 
           Summary: wrong-code for errno handling on overflow/underflow
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: rguenth at gcc dot gnu dot org


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

Reply via email to