diff mbox series

[Committed] PR fortran/87994 -- Inquiry parameter as data constant

Message ID 20181216033538.GA14782@troutmask.apl.washington.edu
State New
Headers show
Series [Committed] PR fortran/87994 -- Inquiry parameter as data constant | expand

Commit Message

Steve Kargl Dec. 16, 2018, 3:35 a.m. UTC
I've committed the attached after testing on i586-*-freebsd
and x86_64-*-freebsd.  It removes an ICE by allowing the
inquiry parametes of len and kind in data statements as
data constants.

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

	PR fortran/87944
	* decl.c (match_data_constant): Allow inquiry parameter as data
	constant in data statement.

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

	PR fortran/87944
	* gfortran.dg/pr87994_1.f90: New test.
	* gfortran.dg/pr87994_2.f90: Ditto.
	* gfortran.dg/pr87994_3.f90: Ditto.
diff mbox series

Patch

Index: gcc/fortran/decl.c
===================================================================
--- gcc/fortran/decl.c	(revision 267180)
+++ gcc/fortran/decl.c	(working copy)
@@ -399,6 +399,14 @@  match_data_constant (gfc_expr **result)
     }
   else if (m == MATCH_YES)
     {
+      /* If a parameter inquiry ends up here, symtree is NULL but **result
+	 contains the right constant expression.  Check here.  */
+      if ((*result)->symtree == NULL
+	  && (*result)->expr_type == EXPR_CONSTANT
+	  && ((*result)->ts.type == BT_INTEGER 
+	      || (*result)->ts.type == BT_REAL))
+	return m;
+
       /* F2018:R845 data-stmt-constant is initial-data-target.
 	 A data-stmt-constant shall be ... initial-data-target if and
 	 only if the corresponding data-stmt-object has the POINTER
Index: gcc/testsuite/gfortran.dg/pr87994_1.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr87994_1.f90	(nonexistent)
+++ gcc/testsuite/gfortran.dg/pr87994_1.f90	(working copy)
@@ -0,0 +1,7 @@ 
+! { dg-do run }
+! PR fortran/87994
+program p
+   real :: a, b
+   data b /a%kind/
+   if (b /= kind(a)) stop 1
+end
Index: gcc/testsuite/gfortran.dg/pr87994_2.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr87994_2.f90	(nonexistent)
+++ gcc/testsuite/gfortran.dg/pr87994_2.f90	(working copy)
@@ -0,0 +1,7 @@ 
+! { dg-do run }
+! PR fortran/87994
+program p
+   real, parameter :: a = 1.0
+   data b /a%kind/
+   if (b /= kind(a)) stop 1
+end
Index: gcc/testsuite/gfortran.dg/pr87994_3.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr87994_3.f90	(nonexistent)
+++ gcc/testsuite/gfortran.dg/pr87994_3.f90	(working copy)
@@ -0,0 +1,8 @@ 
+! { dg-do run }
+! PR fortran/87994
+program p
+   integer, parameter :: a = 1
+   integer :: b
+   data b /a%kind/
+   if (b /= kind(a)) stop = 1
+end