public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-4967] Fortran: fix simplification of array-valued parameter expressions
@ 2021-11-05 22:50 Harald Anlauf
  0 siblings, 0 replies; only message in thread
From: Harald Anlauf @ 2021-11-05 22:50 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:bcf3728abe8488882922005166d3065fc5fdfea1

commit r12-4967-gbcf3728abe8488882922005166d3065fc5fdfea1
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Fri Nov 5 23:48:20 2021 +0100

    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.

Diff:
---
 gcc/fortran/expr.c                     |  2 ++
 gcc/testsuite/gfortran.dg/pr102817.f90 | 17 +++++++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c
index 087d822021a..941d29cf7cd 100644
--- a/gcc/fortran/expr.c
+++ b/gcc/fortran/expr.c
@@ -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
index 00000000000..c081a69f0ea
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr102817.f90
@@ -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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-11-05 22:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-05 22:50 [gcc r12-4967] Fortran: fix simplification of array-valued parameter expressions Harald Anlauf

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).