https://gcc.gnu.org/g:55434a57e5c4a379a3c301d1c021a60f615bec56

commit r16-2792-g55434a57e5c4a379a3c301d1c021a60f615bec56
Author: Mikael Morin <mik...@gcc.gnu.org>
Date:   Sun Aug 3 15:21:08 2025 +0200

    fortran: Use array descriptor offset setter when possible
    
    Regression-tested on x86_64-pc-linux-gnu.
    OK for master?
    
    -- >8 --
    
        In some places, a write to an array descriptor offset field was
        generated simply by adding a modification of a reference to it that
        was already available.  This change uses the existing setter
        function instead in those places, to generate the same code.  It
        makes it more explicit that in those areas a write to the field is
        generated.
    
    gcc/fortran/ChangeLog:
    
            * trans-array.cc (gfc_alloc_allocatable_for_assignment): Use the
            offset setter instead of generating a write to the offset.
            (gfc_conv_array_parameter): Use the offset setter instead of
            generating a write to the value returned by the offset getter.
            * trans-expr.cc (gfc_trans_alloc_subarray_assign): Likewise.

Diff:
---
 gcc/fortran/trans-array.cc | 9 ++++-----
 gcc/fortran/trans-expr.cc  | 2 +-
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index e3b273744bb3..45980d656572 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -9578,9 +9578,8 @@ gfc_conv_array_parameter (gfc_se *se, gfc_expr *expr, 
bool g77,
              new_field = gfc_conv_descriptor_dtype (new_desc);
              gfc_add_modify (&se->pre, new_field, old_field);
 
-             old_field = gfc_conv_descriptor_offset (old_desc);
-             new_field = gfc_conv_descriptor_offset (new_desc);
-             gfc_add_modify (&se->pre, new_field, old_field);
+             old_field = gfc_conv_descriptor_offset_get (old_desc);
+             gfc_conv_descriptor_offset_set (&se->pre, new_desc, old_field);
 
              for (int i = 0; i < expr->rank; i++)
                {
@@ -11750,8 +11749,8 @@ gfc_alloc_allocatable_for_assignment (gfc_loopinfo 
*loop,
                                          gfc_index_zero_node);
        }
 
-      tmp = gfc_conv_descriptor_offset (desc);
-      gfc_add_modify (&loop_pre_block, tmp, gfc_index_zero_node);
+      gfc_conv_descriptor_offset_set (&loop_pre_block, desc,
+                                     gfc_index_zero_node);
 
       tmp = fold_build2_loc (input_location, EQ_EXPR,
                             logical_type_node, array1,
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index ec240844a5e9..e6c321844352 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -9583,8 +9583,8 @@ gfc_trans_alloc_subarray_assign (tree dest, gfc_component 
* cm,
 
   /* Shift the lbound and ubound of temporaries to being unity,
      rather than zero, based. Always calculate the offset.  */
+  gfc_conv_descriptor_offset_set (&block, dest, gfc_index_zero_node);
   offset = gfc_conv_descriptor_offset_get (dest);
-  gfc_add_modify (&block, offset, gfc_index_zero_node);
   tmp2 =gfc_create_var (gfc_array_index_type, NULL);
 
   for (n = 0; n < expr->rank; n++)

Reply via email to