https://gcc.gnu.org/g:4dc9086f3323604ffc8237f44f656c7b24c360f2

commit 4dc9086f3323604ffc8237f44f656c7b24c360f2
Author: Mikael Morin <[email protected]>
Date:   Thu Aug 20 20:43:23 2026 +0200

    fortran: array descriptor: Don't set the span in the scalar case [PR122521]
    
    TODO: 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 it 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.
    
            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.

Diff:
---
 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 3f86be584428..23321b5b48cb 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 c83899de0e5b..5636a89e94a9 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 fecc1b3a2832..b597b862d031 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;

Reply via email to