public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR fortran/82314 - ICE in gfc_conv_expr_descriptor, at fortran/trans-array.c:6972
@ 2021-09-07 21:44 Harald Anlauf
  2021-09-12 18:31 ` *PING* " Harald Anlauf
  2021-09-13  8:21 ` Tobias Burnus
  0 siblings, 2 replies; 3+ messages in thread
From: Harald Anlauf @ 2021-09-07 21:44 UTC (permalink / raw)
  To: fortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 897 bytes --]

When adding the initializer for an array, we need to make sure that
array bounds are properly simplified if that array is a PARAMETER.
Otherwise the generated initializer could be wrong and screw up
subsequent simplifications, see PR.

The minimal solution is to attempt simplification of array bounds
before adding the initializer as in the attached patch.  (We could
place that part in a helper function if this functionality is
considered useful elsewhere).

Regtested on x86_64-pc-linux-gnu.  OK for mainline?

Thanks,
Harald


Fortran - ensure simplification of bounds of array-valued named constants

gcc/fortran/ChangeLog:

	PR fortran/82314
	* decl.c (add_init_expr_to_sym): For proper initialization of
	array-valued named constants the array bounds need to be
	simplified before adding the initializer.

gcc/testsuite/ChangeLog:

	PR fortran/82314
	* gfortran.dg/pr82314.f90: New test.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr82314.patch --]
[-- Type: text/x-patch, Size: 1556 bytes --]

diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
index 2e49a673e15..f2e8896b562 100644
--- a/gcc/fortran/decl.c
+++ b/gcc/fortran/decl.c
@@ -2169,6 +2169,24 @@ add_init_expr_to_sym (const char *name, gfc_expr **initp, locus *var_locus)
 	  sym->as->type = AS_EXPLICIT;
 	}

+      /* Ensure that explicit bounds are simplified.  */
+      if (sym->attr.flavor == FL_PARAMETER && sym->attr.dimension
+	  && sym->as->type == AS_EXPLICIT)
+	{
+	  for (int dim = 0; dim < sym->as->rank; ++dim)
+	    {
+	      gfc_expr *e;
+
+	      e = sym->as->lower[dim];
+	      if (e->expr_type != EXPR_CONSTANT)
+		gfc_reduce_init_expr (e);
+
+	      e = sym->as->upper[dim];
+	      if (e->expr_type != EXPR_CONSTANT)
+		gfc_reduce_init_expr (e);
+	    }
+	}
+
       /* Need to check if the expression we initialized this
 	 to was one of the iso_c_binding named constants.  If so,
 	 and we're a parameter (constant), let it be iso_c.
diff --git a/gcc/testsuite/gfortran.dg/pr82314.f90 b/gcc/testsuite/gfortran.dg/pr82314.f90
new file mode 100644
index 00000000000..3a147e22711
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr82314.f90
@@ -0,0 +1,11 @@
+! { dg-do run }
+! PR fortran/82314 - ICE in gfc_conv_expr_descriptor
+
+program p
+  implicit none
+  integer, parameter :: karray(merge(3,7,.true.):merge(3,7,.false.)) = 1
+  integer, parameter :: i = size   (karray)
+  integer, parameter :: l = lbound (karray,1)
+  integer, parameter :: u = ubound (karray,1)
+  if (l /= 3 .or. u /= 7 .or. i /= 5) stop 1
+end

^ permalink raw reply	[flat|nested] 3+ messages in thread

* *PING* [PATCH] PR fortran/82314 - ICE in gfc_conv_expr_descriptor, at fortran/trans-array.c:6972
  2021-09-07 21:44 [PATCH] PR fortran/82314 - ICE in gfc_conv_expr_descriptor, at fortran/trans-array.c:6972 Harald Anlauf
@ 2021-09-12 18:31 ` Harald Anlauf
  2021-09-13  8:21 ` Tobias Burnus
  1 sibling, 0 replies; 3+ messages in thread
From: Harald Anlauf @ 2021-09-12 18:31 UTC (permalink / raw)
  To: Harald Anlauf; +Cc: fortran, gcc-patches

Early *PING*.

> Gesendet: Dienstag, 07. September 2021 um 23:44 Uhr
> Von: "Harald Anlauf" <anlauf@gmx.de>
> An: "fortran" <fortran@gcc.gnu.org>, "gcc-patches" <gcc-patches@gcc.gnu.org>
> Betreff: [PATCH] PR fortran/82314 - ICE in gfc_conv_expr_descriptor, at fortran/trans-array.c:6972
>
> When adding the initializer for an array, we need to make sure that
> array bounds are properly simplified if that array is a PARAMETER.
> Otherwise the generated initializer could be wrong and screw up
> subsequent simplifications, see PR.
>
> The minimal solution is to attempt simplification of array bounds
> before adding the initializer as in the attached patch.  (We could
> place that part in a helper function if this functionality is
> considered useful elsewhere).
>
> Regtested on x86_64-pc-linux-gnu.  OK for mainline?
>
> Thanks,
> Harald
>
>
> Fortran - ensure simplification of bounds of array-valued named constants
>
> gcc/fortran/ChangeLog:
>
> 	PR fortran/82314
> 	* decl.c (add_init_expr_to_sym): For proper initialization of
> 	array-valued named constants the array bounds need to be
> 	simplified before adding the initializer.
>
> gcc/testsuite/ChangeLog:
>
> 	PR fortran/82314
> 	* gfortran.dg/pr82314.f90: New test.
>
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] PR fortran/82314 - ICE in gfc_conv_expr_descriptor, at fortran/trans-array.c:6972
  2021-09-07 21:44 [PATCH] PR fortran/82314 - ICE in gfc_conv_expr_descriptor, at fortran/trans-array.c:6972 Harald Anlauf
  2021-09-12 18:31 ` *PING* " Harald Anlauf
@ 2021-09-13  8:21 ` Tobias Burnus
  1 sibling, 0 replies; 3+ messages in thread
From: Tobias Burnus @ 2021-09-13  8:21 UTC (permalink / raw)
  To: Harald Anlauf, fortran, gcc-patches

On 07.09.21 23:44, Harald Anlauf via Fortran wrote:
> When adding the initializer for an array, we need to make sure that
> array bounds are properly simplified if that array is a PARAMETER.
> Otherwise the generated initializer could be wrong and screw up
> subsequent simplifications, see PR.
>
> The minimal solution is to attempt simplification of array bounds
> before adding the initializer as in the attached patch.  (We could
> place that part in a helper function if this functionality is
> considered useful elsewhere).
>
> Regtested on x86_64-pc-linux-gnu.  OK for mainline?

OK. Thanks for the patch,

Tobias

> Fortran - ensure simplification of bounds of array-valued named constants
>
> gcc/fortran/ChangeLog:
>
>       PR fortran/82314
>       * decl.c (add_init_expr_to_sym): For proper initialization of
>       array-valued named constants the array bounds need to be
>       simplified before adding the initializer.
>
> gcc/testsuite/ChangeLog:
>
>       PR fortran/82314
>       * gfortran.dg/pr82314.f90: New test.
>
-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-09-13  8:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-07 21:44 [PATCH] PR fortran/82314 - ICE in gfc_conv_expr_descriptor, at fortran/trans-array.c:6972 Harald Anlauf
2021-09-12 18:31 ` *PING* " Harald Anlauf
2021-09-13  8:21 ` Tobias Burnus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).