]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
fortran: Use array descriptor offset setter when possible
authorMikael Morin <mikael@gcc.gnu.org>
Sun, 3 Aug 2025 13:21:08 +0000 (15:21 +0200)
committerMikael Morin <mikael@gcc.gnu.org>
Tue, 5 Aug 2025 14:20:40 +0000 (16:20 +0200)
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.

gcc/fortran/trans-array.cc
gcc/fortran/trans-expr.cc

index e3b273744bb3627db0bb819c2ceef9f18cb5aa20..45980d6565729ebfe3b6ed361c0f57eaf5f10687 100644 (file)
@@ -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,
index ec240844a5e9978a07d61ded725776c6ddf3fefb..e6c32184435212a2ff1bb06e6d825fa72cf653ef 100644 (file)
@@ -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++)