[PATCH] fortran: Fix up initializers of param(0) PARAMETERs [PR103691]

Jakub Jelinek jakub@redhat.com
Fri Mar 25 08:57:42 GMT 2022


On the gfortran.dg/pr103691.f90 testcase the Fortran ICE emits
  static real(kind=4) a[0] = {[0 ... -1]=2.0e+0};
That is an invalid RANGE_EXPR where the maximum is smaller than the minimum.

The following patch fixes that.  If TYPE_MAX_VALUE is smaller than
TYPE_MIN_VALUE, the array is empty and so doesn't need any initializer,
if the two are equal, we don't need to bother with a RANGE_EXPR and
can just use that INTEGER_CST as the index and finally for the 2+ values
in the range it uses a RANGE_EXPR as before.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2022-03-25  Jakub Jelinek  <jakub@redhat.com>

	PR fortran/103691
	* trans-array.cc (gfc_conv_array_initializer): If TYPE_MAX_VALUE is
	smaller than TYPE_MIN_VALUE (i.e. empty array), throw the initializer
	on the floor, if TYPE_MIN_VALUE is equal to TYPE_MAX_VALUE, use just
	the TYPE_MIN_VALUE as index instead of RANGE_EXPR.

--- gcc/fortran/trans-array.cc.jj	2022-02-04 14:36:55.113603791 +0100
+++ gcc/fortran/trans-array.cc	2022-03-24 16:14:58.334498775 +0100
@@ -6267,10 +6267,17 @@ gfc_conv_array_initializer (tree type, g
 	gfc_conv_structure (&se, expr, 1);
-      CONSTRUCTOR_APPEND_ELT (v, build2 (RANGE_EXPR, gfc_array_index_type,
-					 TYPE_MAX_VALUE (TYPE_DOMAIN (type))),
-			      se.expr);
+      if (tree_int_cst_lt (TYPE_MAX_VALUE (TYPE_DOMAIN (type)),
+			   TYPE_MIN_VALUE (TYPE_DOMAIN (type))))
+	break;
+      else if (tree_int_cst_equal (TYPE_MIN_VALUE (TYPE_DOMAIN (type)),
+				   TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
+	range = TYPE_MIN_VALUE (TYPE_DOMAIN (type));
+      else
+	range = build2 (RANGE_EXPR, gfc_array_index_type,
+      CONSTRUCTOR_APPEND_ELT (v, range, se.expr);
     case EXPR_ARRAY:


More information about the Gcc-patches mailing list