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

commit b4229ea0f791c986b932e860b5c88aa9be2ae8dc
Author: Mikael Morin <mik...@gcc.gnu.org>
Date:   Wed Jul 23 16:34:39 2025 +0200

    Extraction gfc_copy_sequence_descriptor

Diff:
---
 gcc/fortran/trans-array.cc      | 18 +-----------------
 gcc/fortran/trans-descriptor.cc | 20 ++++++++++++++++++++
 gcc/fortran/trans-descriptor.h  |  2 ++
 3 files changed, 23 insertions(+), 17 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 3173deaeb6a8..ca512aeceeba 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -8833,23 +8833,7 @@ gfc_conv_array_parameter (gfc_se *se, gfc_expr *expr, 
bool g77,
              && CLASS_DATA (fsym)->as->type == AS_EXPLICIT && !no_pack)
            {
              tree arr = gfc_create_var (TREE_TYPE (tmp), "parm");
-             gfc_conv_descriptor_data_set (&block, arr,
-                                           gfc_conv_descriptor_data_get (
-                                             se->expr));
-             gfc_conv_descriptor_lbound_set (&block, arr, gfc_index_zero_node,
-                                             gfc_index_zero_node);
-             gfc_conv_descriptor_ubound_set (
-               &block, arr, gfc_index_zero_node,
-               gfc_conv_descriptor_size (se->expr, expr->rank));
-             gfc_conv_descriptor_stride_set (
-               &block, arr, gfc_index_zero_node,
-               gfc_conv_descriptor_stride_get (se->expr, gfc_index_zero_node));
-             tree tmp2 = gfc_conv_descriptor_dtype_get (se->expr);
-             gfc_conv_descriptor_dtype_set (&block, arr, tmp2);
-             gfc_conv_descriptor_rank_set (&block, arr, 1);
-             gfc_conv_descriptor_span_set (&block, arr,
-                                           gfc_conv_descriptor_span_get (arr));
-             gfc_conv_descriptor_offset_set (&block, arr, gfc_index_zero_node);
+             gfc_copy_sequence_descriptor (&block, arr, se->expr, expr->rank);
              se->expr = arr;
            }
          gfc_class_array_data_assign (&block, tmp, se->expr, true);
diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index cb5846896ccf..7b3c10f50994 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -1475,3 +1475,23 @@ gfc_shift_descriptor (stmtblock_t *block, tree descr, 
int rank,
 
   gfc_conv_descriptor_offset_set (block, descr, offset);
 }
+ 
+
+void
+gfc_copy_sequence_descriptor (stmtblock_t *block, tree dest, tree src, int 
rank)
+{
+  gfc_conv_descriptor_data_set (block, dest,
+                               gfc_conv_descriptor_data_get (src));
+  gfc_conv_descriptor_lbound_set (block, dest, gfc_index_zero_node,
+                                 gfc_index_zero_node);
+  gfc_conv_descriptor_ubound_set (block, dest, gfc_index_zero_node,
+                                 gfc_conv_descriptor_size (src, rank));
+  tree stride = gfc_conv_descriptor_stride_get (src, gfc_index_zero_node);
+  gfc_conv_descriptor_stride_set (block, dest, gfc_index_zero_node, stride);
+  gfc_conv_descriptor_dtype_set (block, dest,
+                                gfc_conv_descriptor_dtype_get (src));
+  gfc_conv_descriptor_rank_set (block, dest, 1);
+  gfc_conv_descriptor_span_set (block, dest,
+                               gfc_conv_descriptor_span_get (src));
+  gfc_conv_descriptor_offset_set (block, dest, gfc_index_zero_node);
+}
diff --git a/gcc/fortran/trans-descriptor.h b/gcc/fortran/trans-descriptor.h
index 45bc70ffdb29..1b02c86fcf37 100644
--- a/gcc/fortran/trans-descriptor.h
+++ b/gcc/fortran/trans-descriptor.h
@@ -112,6 +112,8 @@ void gfc_set_subarray_descriptor (stmtblock_t *, tree, 
tree, gfc_expr *, gfc_exp
 void gfc_shift_descriptor (stmtblock_t *, tree, int, tree [GFC_MAX_DIMENSIONS],
                           tree [GFC_MAX_DIMENSIONS]);
 
+void gfc_copy_sequence_descriptor (stmtblock_t *, tree, tree, int);
+
 void gfc_set_descriptor_from_scalar (stmtblock_t *, tree, tree);
 void gfc_set_descriptor_from_scalar (stmtblock_t *, tree, tree, gfc_expr *);
 void gfc_set_descriptor_from_scalar (stmtblock_t *, tree, tree, gfc_expr *,

Reply via email to