]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: fix simplification of array-valued parameter expressions
authorHarald Anlauf <anlauf@gmx.de>
Fri, 5 Nov 2021 22:48:20 +0000 (23:48 +0100)
committerHarald Anlauf <anlauf@gmx.de>
Fri, 5 Nov 2021 22:48:20 +0000 (23:48 +0100)
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.

gcc/fortran/expr.c
gcc/testsuite/gfortran.dg/pr102817.f90 [new file with mode: 0644]

index 087d822021afc8145157d31437f8d95d64e866d7..941d29cf7cd04dcc5c20278ddde3de958c33efb8 100644 (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)
diff --git a/gcc/testsuite/gfortran.dg/pr102817.f90 b/gcc/testsuite/gfortran.dg/pr102817.f90
new file mode 100644 (file)
index 0000000..c081a69
--- /dev/null
@@ -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