From: Mikael Morin <[email protected]>

Fortran-tested on aarch64-unknown-linux-gnu.  OK for mainline?

-- >8 --

The span in an array descriptor is a multiplier of the stride representing
the address difference between two consecutive array elements.  For scalar
descriptors, there is a single element, so the span can't be used in any
useful way.

This patch removes the initialization of the span of descriptors in the
scalar case.

One tweak is required to avoid regressing.  In the library implementation of
the ASSOCIATED intrinsic, the two descriptors are checked to have the same
span, assuming the span to be always set.  Make that check conditional on
the rank being non-zero.

The testcase coarry_collectives_18.f90, which counts the number of array
descriptor references in the generated tree dump, needs to be updated as a
result of this change.  There are two descriptor initializations, and for
each of them the change causes a copy from the elem_len field to the span
field to be removed.  So the count is decreased by 4.

        PR fortran/122521

gcc/fortran/ChangeLog:

        * trans-descriptor.cc (gfc_set_descriptor_from_scalar): Remove
        descriptor span initialization.

libgfortran/ChangeLog:

        * intrinsics/associated.c (associated): Only compare spans if
        the rank is non-zero.

gcc/testsuite/ChangeLog:

        * gfortran.dg/coarray_collectives_18.f90: Update pattern count.
---
 gcc/fortran/trans-descriptor.cc                      | 2 --
 gcc/testsuite/gfortran.dg/coarray_collectives_18.f90 | 2 +-
 libgfortran/intrinsics/associated.c                  | 5 +++--
 3 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index 3f86be58442..23321b5b48c 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -907,8 +907,6 @@ gfc_set_descriptor_from_scalar (stmtblock_t *block, tree 
descr, tree scalar)
   gfc_conv_descriptor_dtype_set (block, descr,
                                 gfc_get_dtype_rank_type (0, etype));
   gfc_conv_descriptor_data_set (block, descr, scalar);
-  gfc_conv_descriptor_span_set (block, descr,
-                               gfc_conv_descriptor_elem_len_get (descr));
 }
 
 
diff --git a/gcc/testsuite/gfortran.dg/coarray_collectives_18.f90 
b/gcc/testsuite/gfortran.dg/coarray_collectives_18.f90
index c83899de0e5..5636a89e94a 100644
--- a/gcc/testsuite/gfortran.dg/coarray_collectives_18.f90
+++ b/gcc/testsuite/gfortran.dg/coarray_collectives_18.f90
@@ -33,5 +33,5 @@ end program
 ! This lead to access to non exsitant memory in opencoarrays.
 ! In single image mode just checking for reduced number of
 ! descriptors is possible, i.e., execute always works.
-! { dg-final { scan-tree-dump-times "desc\\.\[0-9\]+" 12 "original" } }
+! { dg-final { scan-tree-dump-times "desc\\.\[0-9\]+" 8 "original" } }
 
diff --git a/libgfortran/intrinsics/associated.c 
b/libgfortran/intrinsics/associated.c
index fecc1b3a283..b597b862d03 100644
--- a/libgfortran/intrinsics/associated.c
+++ b/libgfortran/intrinsics/associated.c
@@ -37,13 +37,14 @@ associated (const gfc_array_void *pointer, const 
gfc_array_void *target)
     return 0;
   if (GFC_DESCRIPTOR_DATA (pointer) != GFC_DESCRIPTOR_DATA (target))
     return 0;
-  if (GFC_DESCRIPTOR_SPAN (pointer) != GFC_DESCRIPTOR_SPAN (target))
-    return 0;
   if (GFC_DESCRIPTOR_DTYPE (pointer).type != GFC_DESCRIPTOR_DTYPE 
(target).type)
     return 0;
   rank = GFC_DESCRIPTOR_RANK (pointer);
   if (rank != GFC_DESCRIPTOR_RANK (target))
     return 0;
+  if (rank != 0
+      && GFC_DESCRIPTOR_SPAN (pointer) != GFC_DESCRIPTOR_SPAN (target))
+    return 0;
   for (n = 0; n < rank; n++)
     {
       long extent;
-- 
2.53.0

Reply via email to