[gcc(refs/users/mikael/heads/refactor_descriptor_v202.02)] fortran: array descriptor: Add internal field accessor for data [PR122521]

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

commit c0408256b09e36a12c59d394a85a105b6cc174ce
Author: Mikael Morin <[email protected]>
Date:   Thu Oct 23 12:32:57 2025 +0200

    fortran: array descriptor: Add internal field accessor for data [PR122521]
    
    Regression tested on aarch64-unknown-linux-gnu.  OK for master?
    
    -- >8 --
    
    Add a static function producing a reference to the data field of array
    descriptors, like those existing for the other fields.
    
            PR fortran/122521
    
    gcc/fortran/ChangeLog:
    
            * trans-descriptor.cc (conv_descriptor_data): New function.
            (gfc_conv_descriptor_data_get, gfc_conv_descriptor_data_set): Use
            it.

Diff:
---
 gcc/fortran/trans-descriptor.cc | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index c9450414052b..6156f4e2db1e 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -88,6 +88,15 @@ gfc_get_descriptor_field (tree desc, unsigned field_idx)
 			  desc, field, NULL_TREE);
 }
 
+
+/* Return a reference to the data field of the array descriptor DESC.  */
+
+static tree
+conv_descriptor_data (tree desc)
+{
+  return gfc_get_descriptor_field (desc, DATA_FIELD);
+}
+
 /* This provides READ-ONLY access to the data field.  The field itself
    doesn't have the proper type.  */
 
@@ -98,8 +107,8 @@ gfc_conv_descriptor_data_get (tree desc)
   if (TREE_CODE (type) == REFERENCE_TYPE)
     gcc_unreachable ();
 
-  tree field = gfc_get_descriptor_field (desc, DATA_FIELD);
-  return fold_convert (GFC_TYPE_ARRAY_DATAPTR_TYPE (type), field);
+  tree data = conv_descriptor_data (desc);
+  return fold_convert (GFC_TYPE_ARRAY_DATAPTR_TYPE (type), data);
 }
 
 /* This provides WRITE access to the data field.  */
@@ -107,8 +116,8 @@ gfc_conv_descriptor_data_get (tree desc)
 void
 gfc_conv_descriptor_data_set (stmtblock_t *block, tree desc, tree value)
 {
-  tree field = gfc_get_descriptor_field (desc, DATA_FIELD);
-  gfc_add_modify (block, field, fold_convert (TREE_TYPE (field), value));
+  tree data = conv_descriptor_data (desc);
+  gfc_add_modify (block, data, fold_convert (TREE_TYPE (data), value));
 }
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.