On 9/19/26 1:16 PM, Mikael Morin wrote:
From: Mikael Morin <[email protected]>

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

Yes, this is OK,

Jerry


-- >8 --

Move guess of decl for span from build_array_ref argument to within
build_array_ref.

When its input array is to be accessed using span addressing, the function
gfc_get_dataptr_offset sets the input array as decl argument to
build_array_ref, so that the span can be guessed from it.  With a later
change extending span addressing to more arrays, the value provided as
decl argument prevents code in build_array_ref to guess a (better) default
decl value, causing a regression.  This change moves what was as argument
to the function body after the existing default decl guess, and passes
NULL_TREE as argument, so that in the function the default guess prevails,
and if no decl is guessed, the decl for a span-addressed array is the array
itself as before.

gcc/fortran/ChangeLog:

        * trans-array.cc (gfc_get_dataptr_offset): Move guess of decl
        for span from function argument...
        (build_array_ref): ... to function body.  Only set the decl if it
        was empty on input and wasn't set by a previous guess.
---
  gcc/fortran/trans-array.cc | 7 +++++--
  1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index dd2ee7a53e9..abf6f907f05 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -4151,6 +4151,10 @@ build_array_ref (tree desc, tree offset, tree decl, tree 
vptr)
        }
      }
+ if (decl == NULL_TREE
+      && is_span_addressed_array (desc))
+    decl = desc;
+
    tmp = gfc_conv_array_data (desc);
    tmp = build_fold_indirect_ref_loc (input_location, tmp);
    tmp = gfc_build_array_ref (tmp, offset, decl,
@@ -7736,8 +7740,7 @@ gfc_get_dataptr_offset (stmtblock_t *block, tree parm, 
tree desc, tree offset,
/* An array whose elements are spaced by the span needs pointer arithmetic
       to reference an element.  */
-  tree decl = is_span_addressed_array (desc) ? desc : NULL_TREE;
-  tmp = build_array_ref (desc, offset, decl, NULL);
+  tmp = build_array_ref (desc, offset, NULL, NULL);
/* Offset the data pointer for pointer assignments from arrays with
       subreferences; e.g. my_integer => my_type(:)%integer_component.  */

Reply via email to