Fortran: fix simplification of array-valued parameter expressions

gcc/fortran/ChangeLog:

	PR fortran/102817
	* expr.c (simplify_parameter_variable): Copy shape of referenced
	subobject when simplifying.

gcc/testsuite/ChangeLog:

	PR fortran/102817
	* gfortran.dg/pr102817.f90: New test.
This commit is contained in:
Harald Anlauf 2021-11-05 23:48:20 +01:00
parent 5f37780372
commit bcf3728abe
2 changed files with 19 additions and 0 deletions

View File

@ -2128,6 +2128,8 @@ simplify_parameter_variable (gfc_expr *p, int type)
if (e == NULL)
return false;
gfc_free_shape (&e->shape, e->rank);
e->shape = gfc_copy_shape (p->shape, p->rank);
e->rank = p->rank;
if (e->ts.type == BT_CHARACTER && p->ts.u.cl)

View File

@ -0,0 +1,17 @@
! { dg-do compile }
! PR fortran/102817 - ICE in gfc_clear_shape
program test
type t
integer :: a(1,2) = 3
end type t
type(t), parameter :: u = t(4)
type(t), parameter :: x(1) = t(4)
integer, parameter :: p(1,2) = (x(1)%a)
integer :: z(1,2) = (x(1)%a)
integer :: y(1,2), v(1,2), w(1,2)
v = (u %a)
w = x(1)%a
y = (x(1)%a)
print *, v, w, y, z, p
end