public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r10-10170] Fortran: resolve expressions during SIZE simplification
@ 2021-10-05 19:51 Harald Anlauf
  0 siblings, 0 replies; only message in thread
From: Harald Anlauf @ 2021-10-05 19:51 UTC (permalink / raw)
  To: gcc-cvs

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

commit r10-10170-gdea2e6c7b5af2ec620fd94d824f006440907a34d
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Thu Sep 30 20:29:31 2021 +0200

    Fortran: resolve expressions during SIZE simplification
    
    gcc/fortran/ChangeLog:
    
            PR fortran/102458
            * simplify.c (simplify_size): Resolve expressions used in array
            specifications so that SIZE can be simplified.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/102458
            * gfortran.dg/pr102458b.f90: New test.
    
    (cherry picked from commit b19bbfb1482505367dd19ae4ab1ea19e36802b6a)

Diff:
---
 gcc/fortran/simplify.c                  |  5 +++++
 gcc/testsuite/gfortran.dg/pr102458b.f90 | 21 +++++++++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c
index d28aa7a3c16..48a109c1481 100644
--- a/gcc/fortran/simplify.c
+++ b/gcc/fortran/simplify.c
@@ -7379,6 +7379,7 @@ simplify_size (gfc_expr *array, gfc_expr *dim, int k)
   mpz_t size;
   gfc_expr *return_value;
   int d;
+  gfc_ref *ref;
 
   /* For unary operations, the size of the result is given by the size
      of the operand.  For binary ones, it's the size of the first operand
@@ -7435,6 +7436,10 @@ simplify_size (gfc_expr *array, gfc_expr *dim, int k)
       return simplified;
     }
 
+  for (ref = array->ref; ref; ref = ref->next)
+    if (ref->type == REF_ARRAY && ref->u.ar.as)
+      gfc_resolve_array_spec (ref->u.ar.as, 0);
+
   if (dim == NULL)
     {
       if (!gfc_array_size (array, &size))
diff --git a/gcc/testsuite/gfortran.dg/pr102458b.f90 b/gcc/testsuite/gfortran.dg/pr102458b.f90
new file mode 100644
index 00000000000..3e1026e635a
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr102458b.f90
@@ -0,0 +1,21 @@
+! { dg-do compile }
+! { dg-options "-fdump-tree-original" }
+! { dg-final { scan-tree-dump-times "_gfortran_stop_numeric" 0 "original" } }
+! PR fortran/102458
+
+subroutine s4
+  integer, parameter :: n = 4
+  integer            :: w(transfer(n, n)) = 1
+  integer            :: x(transfer(n, n))
+  integer            :: y(2*int(n) - n)
+  type t
+     integer         :: z(int(n))
+  end type t
+  type(t)            :: tt, uu(3)
+  integer, parameter :: i = size (w)
+  integer, parameter :: k = size (x)
+  integer, parameter :: m = size (y)
+  integer, parameter :: j = size (tt% z)
+  integer, parameter :: l = size (uu(2)% z)
+  if (i /= n .or. k /= n .or. m /= n .or. j /= n .or. l /= n) stop 1
+end


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

only message in thread, other threads:[~2021-10-05 19:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-05 19:51 [gcc r10-10170] Fortran: resolve expressions during SIZE simplification 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).