https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91690

--- Comment #3 from Steve Kargl <sgk at troutmask dot apl.washington.edu> ---
On Mon, Sep 09, 2019 at 08:05:33AM +0000, rguenth at gcc dot gnu.org wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91690
> 
> --- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
> __builtin_isnan is required to preserve FPU state, not sure why the Fortran FE
> thinks it needs some extra magic around it?
> 

The magic seems to come from trans-decl.c

/* Generate code for a function.  */

void
gfc_generate_function_code (gfc_namespace * ns)
{

...

  /* Check if an IEEE module is used in the procedure.  If so, save
     the floating point state.  */
  ieee = is_ieee_module_used (ns);
  if (ieee)
    fpstate = gfc_save_fp_state (&init);

...

  /* If IEEE modules are loaded, restore the floating-point state.  */
  if (ieee)
    gfc_restore_fp_state (&cleanup, fpstate);

}

The Fortran standard may require this behavior.  18-007r1 page 435

  In a scoping unit that has access to IEEE_EXCEPTIONS or IEEE_ARITHMETIC,
  if an intrinsic procedure or a procedure defined in an intrinsic module
  executes normally, the values of the flags IEEE_OVERFLOW,
IEEE_DIVIDE_BY_ZERO,
  and IEEE_INVALID shall be as on entry to the procedure, even if one or more
  of them signals during the calculation.

then on page 437

  In a procedure other than IEEE_SET_ROUNDING_MODE or IEEE_SET_STATUS, the
  processor shall not change the rounding modes on entry, and on return
  shall ensure that the rounding modes are the same as they were on entry.
...
  In a procedure other than IEEE_SET_UNDERFLOW_MODE or IEEE_SET_STATUS, the
  processor shall not change the underflow mode on entry, and on return
  shall ensure that the underflow mode is the same as it was on entry.

then on page 438

  In a procedure other than IEEE_SET_HALTING_MODE or IEEE_SET_STATUS, the
  processor shall not change the halting mode on entry, and on return shall
  ensure that the halting mode is the same as it was on entry.

Reply via email to