public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH, part 2] PR 102458 - issues with simplification of SIZE intrinsic applied to automatic arrays
@ 2021-09-29 19:20 Harald Anlauf
  2021-09-30 17:03 ` Tobias Burnus
  0 siblings, 1 reply; 2+ messages in thread
From: Harald Anlauf @ 2021-09-29 19:20 UTC (permalink / raw)
  To: fortran, gcc-patches

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

Dear Fortranners,

I think I have solved the remaining issue in PR 102458 that prevented the
simplification of an expression involving a static initialization and the
evaluation of the SIZE of an automatic array which has provable constant
size.  My previous related query to the ML has thus become obsolete.

My solution is to attempt the resolution of the array specification
within simplify_size so that the simplification actually works.

Regtested on x86_64-pc-linux-gnu.  OK for mainline and same branches
as the patch for part1?

Thanks,
Harald


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

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.

diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c
index b46cbfa90ab..f40e4930b58 100644
--- a/gcc/fortran/simplify.c
+++ b/gcc/fortran/simplify.c
@@ -7471,6 +7471,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
@@ -7527,6 +7528,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] 2+ messages in thread

* Re: [PATCH, part 2] PR 102458 - issues with simplification of SIZE intrinsic applied to automatic arrays
  2021-09-29 19:20 [PATCH, part 2] PR 102458 - issues with simplification of SIZE intrinsic applied to automatic arrays Harald Anlauf
@ 2021-09-30 17:03 ` Tobias Burnus
  0 siblings, 0 replies; 2+ messages in thread
From: Tobias Burnus @ 2021-09-30 17:03 UTC (permalink / raw)
  To: Harald Anlauf, fortran, gcc-patches

Dear Harald, dear all,

On 29.09.21 21:20, Harald Anlauf via Fortran wrote:
> I think I have solved the remaining issue in PR 102458 that prevented the
> simplification of an expression involving a static initialization and the
> evaluation of the SIZE of an automatic array which has provable constant
> size.  My previous related query to the ML has thus become obsolete.
>
> My solution is to attempt the resolution of the array specification
> within simplify_size so that the simplification actually works.
>
> Regtested on x86_64-pc-linux-gnu.  OK for mainline and same branches
> as the patch for part1?

Thanks. I wonder whether that should be placed at some more generic
place, but for now add it to another intrinsic-simplify function ...

I note that this resolution is also used for (u,l)(,co)bounds/this_image
(via simplify_bound_dim) and in gfc_resolve_formal_arglist,
resolve_component, resolve_symbol.

OK.

Thanks,

Tobias

> 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.
-----------------
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] 2+ messages in thread

end of thread, other threads:[~2021-09-30 17:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-29 19:20 [PATCH, part 2] PR 102458 - issues with simplification of SIZE intrinsic applied to automatic arrays Harald Anlauf
2021-09-30 17:03 ` 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).