[gcc r17-2541] fortran: array descriptor: Use the setter to modify the offset [PR122521]

Mikael Morin via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:0e4ae4ef73e5fe7ac3b6bfdf7913373ba0668878

commit r17-2541-g0e4ae4ef73e5fe7ac3b6bfdf7913373ba0668878
Author: Mikael Morin <[email protected]>
Date:   Mon Jul 20 11:07:41 2026 +0200

    fortran: array descriptor: Use the setter to modify the offset [PR122521]
    
    Use the setter function to generate code modifying the array descriptor
    offset and remove from the public API the function giving direct access to
    that field.
    
            PR fortran/122521
    
    gcc/fortran/ChangeLog:
    
            * trans-descriptor.cc (gfc_conv_descriptor_offset): Make static and
            rename ...
            (conv_descriptor_offset): ... to this.
            (gfc_conv_descriptor_offset_get,
            gfc_conv_descriptor_offset_set): Update callers.
            * trans-descriptor.h (gfc_conv_descriptor_offset): Remove
            declaration.
            * trans-array.cc (gfc_alloc_allocatable_for_assignment): Use the
            setter function to generate a modification of the array descriptor
            offset.

Diff:
---
 gcc/fortran/trans-array.cc      |  3 +--
 gcc/fortran/trans-descriptor.cc | 15 +++++++++++----
 gcc/fortran/trans-descriptor.h  |  1 -
 3 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 871a83207f38..950ebf758132 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -12056,8 +12056,7 @@ gfc_alloc_allocatable_for_assignment (gfc_loopinfo *loop,
   /* Set the lhs descriptor and scalarizer offsets.  For rank > 1,
      the array offset is saved and the info.offset is used for a
      running offset.  Use the saved_offset instead.  */
-  tmp = gfc_conv_descriptor_offset (desc);
-  gfc_add_modify (&fblock, tmp, offset);
+  gfc_conv_descriptor_offset_set (&fblock, desc, offset);
 
   /* Take into account _len of unlimited polymorphic entities, so that span
      for array descriptors and allocation sizes are computed correctly.  */
diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index 79c6439c08fa..d24e5c6f1787 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -98,24 +98,31 @@ gfc_conv_descriptor_data_set (stmtblock_t *block, tree desc, tree value)
 }
 
 
-tree
-gfc_conv_descriptor_offset (tree desc)
+/* Return a reference to the offset field of the array descriptor DESC.  */
+
+static tree
+conv_descriptor_offset (tree desc)
 {
   tree field = gfc_get_descriptor_field (desc, OFFSET_FIELD);
   gcc_assert (TREE_TYPE (field) == gfc_array_index_type);
   return field;
 }
 
+/* Return the offset value of the array descriptor DESC.  */
+
 tree
 gfc_conv_descriptor_offset_get (tree desc)
 {
-  return gfc_conv_descriptor_offset (desc);
+  return conv_descriptor_offset (desc);
 }
 
+/* Add code to BLOCK assigning VALUE to the offset field of the array descriptor
+   DESC.  */
+
 void
 gfc_conv_descriptor_offset_set (stmtblock_t *block, tree desc, tree value)
 {
-  tree t = gfc_conv_descriptor_offset (desc);
+  tree t = conv_descriptor_offset (desc);
   gfc_add_modify (block, t, fold_convert (TREE_TYPE (t), value));
 }
 
diff --git a/gcc/fortran/trans-descriptor.h b/gcc/fortran/trans-descriptor.h
index 816973825b65..b68a28bddffe 100644
--- a/gcc/fortran/trans-descriptor.h
+++ b/gcc/fortran/trans-descriptor.h
@@ -29,7 +29,6 @@ tree gfc_conv_descriptor_type (tree);
 tree gfc_get_descriptor_dimension (tree);
 tree gfc_conv_descriptor_dimension (tree, tree);
 tree gfc_conv_descriptor_token (tree);
-tree gfc_conv_descriptor_offset (tree);
 
 tree gfc_conv_descriptor_data_get (tree);
 tree gfc_conv_descriptor_offset_get (tree);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.