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

--- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> ---
The submitted patch at http://gcc.gnu.org/ml/fortran/2013-06/msg00005.html
actually solves the problem for REAL(16).

NOTE: I forgot to change one "isfinite" to "ISFINITE" in OUTPUT_FLOAT_FMT_G.

* * *

Pre-remark: All the tests below were done on x86-64-gnu-linux with -m64, but I
also tried -m32.

For REAL(10) it fails at the call:

+       if (!__finitel (tmp))

I tried the following simple C example, compiled with "gfortran
-ffpe-trap=overflow file.c file.f90". Result: no failure (and "T" as output).
------------------------------------
#include <math.h>
_Bool myIsFinite (long double x) {
  return isfinite (x);
}
------------------------------------
use iso_c_binding
interface
  logical(c_bool) function myIsFinite (x) bind(C, name="myIsFinite")
    import
    real(c_long_double), value :: x
  end function myIsFinite
end interface
print *, myIsFinite(huge(0.0_c_long_double))
end
------------------------------------

The __finitel is handled on x86-64 as library call. I tried to set the break
point into __finitel but it seems as if the overflow error occurs before.

If I place a printf in libgfortran before the __finitel call, it prints
"1.189731e+4932" - before failing in the next line.

However, if I compile the file with -ffloat-store, it already fails in the
"printf" line; it also fails in that line if compiled with -O0 (and w/o
-ffloat-store).


For libgfortran's write_float in "case 10:", I now have after manual macro
expansion:
    case 10:
      {
        GFC_REAL_10 tmp;
        tmp = * (GFC_REAL_10 *)source;
        sign_bit = signbit (tmp);
        printf ("DEBUG: %Le\n", tmp); /* Added.  */
        if (!__finitel (tmp))
The assembler code is (without -ffloat-store):
        call    printf
.LVL694:
        .loc 3 1287 0
        fldt    -192(%rbp)
        fld     %st(0)
        fstpt   (%rsp)
.LVL695:
        fstpt   -192(%rbp)
        call    __finitel
.LVL696:
        testl   %eax, %eax
        fldt    -192(%rbp)
        je      .L971

While the simple C test case - which doesn't fail - above gives:
        subq    $24, %rsp
        .cfi_def_cfa_offset 32
        fldt    32(%rsp)
        fstpt   (%rsp)
        call    __finitel
        testl   %eax, %eax
        setne   %al
        addq    $24, %rsp
        .cfi_def_cfa_offset 8
        ret

Reply via email to