[PATCH] fortran/88342 -- interaction of -ffpe-trap and IEEE_VALUE

Steve Kargl sgk@troutmask.apl.washington.edu
Tue Dec 25 07:51:00 GMT 2018


All,

The IEEE modules and -ffpe-trap are to some extent orthogonal
features of gfortran.  Unfortunately, some users have the 
expectation of using -ffpe-trap for debugging while also using only
some of the mechanisms provided by the IEEE modules.  For example,

% t.f90
   program test
      use, intrinsic :: ieee_arithmetic
      real :: inf
      inf = ieee_value(inf,  ieee_positive_inf)
   end program test
% gfc8 -o z -ffpe-trap=overflow t.f90 && ./z
Floating exception (core dumped)

The correct use of the module would be along the lines of

   program test
      use, intrinsic :: ieee_arithmetic
      real :: inf
      logical h
      call ieee_get_halting_mode(ieee_overflow, h)       ! store halting mode
      call ieee_set_halting_mode(ieee_overflow, .false.) ! no halting
      inf = ieee_value(inf, ieee_positive_inf)
      call ieee_set_halting_mode(ieee_overflow, h)       ! restore halting mode
   end program test

Technically (as I have done in the patch), the user should also
use 'ieee_support_halting(ieee_overflow)', but that's just a detail.

Now, IEEE_VALUE() is specifically included in the Fortran standard
to allow it to provide qNaN, sNaN, +inf, and -inf (among a few other
questionable constants).  The attached patch allows gfortran to 
generate an executable that does not abort with SIGFPE.

2018-12-24  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/88342
	* ieee/ieee_arithmetic.F90: Prevent exceptions in IEEE_VALUE if
	-ffpe-trap=invalid or -ffpe-trap=overflow is used.

2018-12-24  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/88342
	* gfortran.dg/ieee/ieee_10.f90:  New test.

Regression tested on i586-*-freebsd and x86_64-*-freebsd.  OK to commit?

-- 
Steve
20170425 https://www.youtube.com/watch?v=VWUpyCsUKR4
20161221 https://www.youtube.com/watch?v=IbCHE-hONow
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr88342.diff
Type: text/x-diff
Size: 9700 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20181225/3ff4face/attachment.bin>


More information about the Fortran mailing list