https://gcc.gnu.org/g:d24241a333f7a34c54fe3b530dd6eb4a7906f56a

commit d24241a333f7a34c54fe3b530dd6eb4a7906f56a
Author: Mikael Morin <[email protected]>
Date:   Sun Jun 29 12:58:32 2025 +0200

    fortran: array descriptor: Add accessors for the version field [PR122521]
    
    Regression tested on aarch64-unknown-linux-gnu.  OK for master?
    
    -- >8 --
    
    Add accessor functions to get or set the value of the version field of array
    descriptors, and remove from the public API the function giving direct acces
    to the field.
    
            PR fortran/122521
    
    gcc/fortran/ChangeLog:
    
            * trans-descriptor.cc (gfc_conv_descriptor_version): Make static and
            rename ...
            (conv_descriptor_version): ... to this.
            (gfc_conv_descriptor_version_get, gfc_conv_descriptor_version_set):
            New functions.
            * trans-descriptor.h (gfc_conv_descriptor_version): Remove
            declaration.
            (gfc_conv_descriptor_version_get, gfc_conv_descriptor_version_set):
            New declarations.
            * trans.cc (gfc_deallocate_with_status): Use
            gfc_conv_descriptor_version_get to get the value of the version
            field, and gfc_conv_descriptor_version_set to set it.
            * trans-array.cc (gfc_array_allocate, structure_alloc_comps,
            gfc_alloc_allocatable_for_assignment): Likewise.

Diff:
---
 gcc/fortran/trans-array.cc      | 26 ++++++++++++++------------
 gcc/fortran/trans-descriptor.cc | 27 +++++++++++++++++++++++++--
 gcc/fortran/trans-descriptor.h  |  3 ++-
 gcc/fortran/trans.cc            |  5 ++---
 4 files changed, 43 insertions(+), 18 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 9a1c801384c2..bf2a828cb8d9 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -6603,10 +6603,10 @@ gfc_array_allocate (gfc_se * se, gfc_expr * expr, tree 
status, tree errmsg,
                     build_tree_list (NULL_TREE, alloc),
                     DECL_ATTRIBUTES (omp_alt_alloc));
       omp_alt_alloc = build_call_expr (omp_alt_alloc, 3, align, sz, alloc);
-      succ_add_expr = fold_build2_loc (input_location, MODIFY_EXPR,
-                                      void_type_node,
-                                      gfc_conv_descriptor_version (se->expr),
-                                      build_int_cst (integer_type_node, 1));
+      stmtblock_t tmp_block;
+      gfc_init_block (&tmp_block);
+      gfc_conv_descriptor_version_set (&tmp_block, se->expr, integer_one_node);
+      succ_add_expr = gfc_finish_block (&tmp_block);
     }
 
   /* The allocatable variant takes the old pointer as first argument.  */
@@ -11108,10 +11108,12 @@ structure_alloc_comps (gfc_symbol * der_type, tree 
decl, tree dest,
                {
                  tree cd, t;
                  if (c->attr.pdt_array)
-                   cd = fold_build2_loc (input_location, EQ_EXPR,
-                                         boolean_type_node,
-                                         gfc_conv_descriptor_version (comp),
-                                         build_int_cst (integer_type_node, 1));
+                   {
+                     tree version_val = gfc_conv_descriptor_version_get (comp);
+                     cd = fold_build2_loc (input_location, EQ_EXPR,
+                                           boolean_type_node, version_val,
+                                           integer_one_node);
+                   }
                  else
                    cd = gfc_omp_call_is_alloc (tmp);
                  t = builtin_decl_explicit (BUILT_IN_GOMP_FREE);
@@ -11121,8 +11123,8 @@ structure_alloc_comps (gfc_symbol * der_type, tree 
decl, tree dest,
                  gfc_init_block (&tblock);
                  gfc_add_expr_to_block (&tblock, t);
                  if (c->attr.pdt_array)
-                   gfc_add_modify (&tblock, gfc_conv_descriptor_version (comp),
-                                   integer_zero_node);
+                   gfc_conv_descriptor_version_set (&tblock, comp,
+                                                    integer_zero_node);
                  tmp = build3_loc (input_location, COND_EXPR, void_type_node,
                                    cd, gfc_finish_block (&tblock),
                                    gfc_call_free (tmp));
@@ -12184,8 +12186,8 @@ gfc_alloc_allocatable_for_assignment (gfc_loopinfo 
*loop,
        {
          tree cond, omp_tmp;
          cond = fold_build2_loc (input_location, EQ_EXPR, boolean_type_node,
-                                 gfc_conv_descriptor_version (desc),
-                                 build_int_cst (integer_type_node, 1));
+                                 gfc_conv_descriptor_version_get (desc),
+                                 integer_one_node);
          omp_tmp = builtin_decl_explicit (BUILT_IN_GOMP_REALLOC);
          omp_tmp = build_call_expr_loc (input_location, omp_tmp, 4,
                                 fold_convert (pvoid_type_node, array1), size2,
diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index 77ecb647f171..3f1e7c110bff 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -172,8 +172,11 @@ gfc_conv_descriptor_rank (tree desc)
 }
 
 
-tree
-gfc_conv_descriptor_version (tree desc)
+/* Return a reference to the format version field of the array descriptor
+   DESC.  */
+
+static tree
+conv_descriptor_version (tree desc)
 {
   tree tmp;
   tree dtype;
@@ -186,6 +189,26 @@ gfc_conv_descriptor_version (tree desc)
                          dtype, tmp, NULL_TREE);
 }
 
+/* Return the format version value of the array descriptor DESC.  */
+
+tree
+gfc_conv_descriptor_version_get (tree desc)
+{
+  return conv_descriptor_version (desc);
+}
+
+/* Add code to BLOCK assigning VALUE to the format version field of the array
+   descriptor DESC.  */
+
+void
+gfc_conv_descriptor_version_set (stmtblock_t *block, tree desc, tree value)
+{
+  location_t loc = input_location;
+  tree t = conv_descriptor_version (desc);
+  gfc_add_modify_loc (loc, block, t,
+                     fold_convert_loc (loc, TREE_TYPE (t), value));
+}
+
 
 /* Return a reference to the element length field of the array descriptor
    DESC.  */
diff --git a/gcc/fortran/trans-descriptor.h b/gcc/fortran/trans-descriptor.h
index afc8f5d442e3..ec60d7cb656b 100644
--- a/gcc/fortran/trans-descriptor.h
+++ b/gcc/fortran/trans-descriptor.h
@@ -22,7 +22,6 @@ along with GCC; see the file COPYING3.  If not see
 
 tree gfc_conv_descriptor_dtype (tree);
 tree gfc_conv_descriptor_rank (tree);
-tree gfc_conv_descriptor_version (tree);
 tree gfc_conv_descriptor_attribute (tree);
 tree gfc_conv_descriptor_type (tree);
 tree gfc_get_descriptor_dimension (tree);
@@ -32,6 +31,7 @@ tree gfc_conv_descriptor_token (tree);
 tree gfc_conv_descriptor_data_get (tree);
 tree gfc_conv_descriptor_offset_get (tree);
 tree gfc_conv_descriptor_elem_len_get (tree);
+tree gfc_conv_descriptor_version_get (tree);
 tree gfc_conv_descriptor_span_get (tree);
 
 tree gfc_conv_descriptor_stride_get (tree, tree);
@@ -41,6 +41,7 @@ tree gfc_conv_descriptor_ubound_get (tree, tree);
 void gfc_conv_descriptor_data_set (stmtblock_t *, tree, tree);
 void gfc_conv_descriptor_offset_set (stmtblock_t *, tree, tree);
 void gfc_conv_descriptor_elem_len_set (stmtblock_t *, tree, tree);
+void gfc_conv_descriptor_version_set (stmtblock_t *, tree, tree);
 void gfc_conv_descriptor_span_set (stmtblock_t *, tree, tree);
 void gfc_conv_descriptor_stride_set (stmtblock_t *, tree, tree, tree);
 void gfc_conv_descriptor_lbound_set (stmtblock_t *, tree, tree, tree);
diff --git a/gcc/fortran/trans.cc b/gcc/fortran/trans.cc
index 51252561b2e4..7418b811a72b 100644
--- a/gcc/fortran/trans.cc
+++ b/gcc/fortran/trans.cc
@@ -1932,7 +1932,7 @@ gfc_deallocate_with_status (tree pointer, tree status, 
tree errmsg, tree errlen,
          tree cond, omp_tmp;
          if (descr)
            cond = fold_build2_loc (input_location, EQ_EXPR, boolean_type_node,
-                                   gfc_conv_descriptor_version (descr),
+                                   gfc_conv_descriptor_version_get (descr),
                                    integer_one_node);
          else
            cond = gfc_omp_call_is_alloc (pointer);
@@ -1946,8 +1946,7 @@ gfc_deallocate_with_status (tree pointer, tree status, 
tree errmsg, tree errlen,
       gfc_add_modify (&non_null, pointer, build_int_cst (TREE_TYPE (pointer),
                                                         0));
       if (flag_openmp_allocators && descr)
-       gfc_add_modify (&non_null, gfc_conv_descriptor_version (descr),
-                       integer_zero_node);
+       gfc_conv_descriptor_version_set (&non_null, descr, integer_zero_node);
 
       if (status != NULL_TREE && !integer_zerop (status))
        {

Reply via email to