[PATCH] PR fortran/69101 -- IEEE_SELECTED_REAL_KIND part I

Steve Kargl sgk@troutmask.apl.washington.edu
Sat Jan 5 04:07:00 GMT 2019


2019-01-04  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/69101
	* expr.c (gfc_check_init_expr): If errors were emitted during
	simplification of ieee_selected_real_kind(), clear any additional
	errors anre return false.
	* simplify.c (simplify_ieee_selected_real_kind): make
        ieee_selected_real_kind() generic in an initialization expression, and
	check for conformance of actual arguments.

 2019-01-04  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/69101
	* gfortran.dg/ieee/ieee_7.f90: Remove invalid code.
	* gfortran.dg/ieee/pr69101_1.f90: Check for errors in actual
	arguments of ieee_selected_real_kind().
	* gfortran.dg/ieee/pr69101_2.f90: Test -std=f2003.  RADIX was added
	in F2008.

TL;DR version

The attached patch fixes ieee_selected_real_kind (ISRK) when
used in an initialization expression, where either keywords are
mixed up compared to their position or the actual arguments are
not default integer kind.  It does not fix the use of ISRK in
an ordinary expression.

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


Long version

ISRK is a function with a generic interface.  It is available from
the ieee_arithmetic intrinsic module.  The problem is that the
Fortran standard has specified a generic interface that is not
expressable in Fortran; and hence, gfortran cannot express it in the
file ieee_arithmetic.F90.  If one thinks about the situation, ISRK
is then neither a module procedure nor an intrinsic subprogram.

This patch expands upon the original simplification process when
an ISRK is seen.  It inspects the actual arguments for keywords
and provides a proper ordering.  It checks that each argument, if
present, is a scalar integer entity, and whether -std=F2008 or
later is in effect.  Because gfortran is performing simplification
in an initialization expression, queuing error messages with gfc_error()
is disabled.  Thus, errors are emitted with gfc_error_now().  If one
or more error is emitted, the portion of the patch in expr.c short
circuits simplification to prevent run-on errors.

It is now possible to do 

   program foo
      use ieee_arithmetic, only : isrk => ieee_selected_real_kind
      integer, parameter :: rknd = isrk(radix=2_1, p=6_8, r=200_2)
      print *, rknd
   end program foo

Note, ISRK must be available from the module to allow the renaming
that occurs above, but ideally gfortran should use its machinery
for intrinsic function.

The patch only fixes the use in initialization expression.  If ISRK
appears in a non-initialization expression, gfortran keels over.
Fixes that is Part II of addressing shortcoming with ISRK.

Finally, things are going to even more interesting when F2018's
ieee_real() and ieee_int() are added to gfortran.

-- 
Steve
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr69101.diff
Type: text/x-diff
Size: 6411 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20190105/5616b684/attachment.bin>


More information about the Fortran mailing list