https://gcc.gnu.org/g:5847f0d9f09ec7ccd096bc678f70fd16ac0e6148

commit 5847f0d9f09ec7ccd096bc678f70fd16ac0e6148
Author: Mikael Morin <mik...@gcc.gnu.org>
Date:   Mon Mar 17 12:26:44 2025 +0100

    Déplacement copy_descriptor

Diff:
---
 gcc/fortran/trans-descriptor.cc | 42 +++++++++++++++++++++++++++++++++++++
 gcc/fortran/trans-descriptor.h  |  4 ++++
 gcc/fortran/trans-stmt.cc       | 46 ++---------------------------------------
 3 files changed, 48 insertions(+), 44 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index f8b2bf93afd7..f6ffc55cccf3 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -3536,3 +3536,45 @@ gfc_class_array_data_assign (stmtblock_t *block, tree 
lhs_desc, tree rhs_desc,
 }
 
 
+void
+gfc_copy_descriptor (stmtblock_t *block, tree dst, tree src, int rank)
+{
+  int n;
+  tree dim;
+  tree tmp;
+  tree tmp2;
+  tree size;
+  tree offset;
+
+  offset = gfc_index_zero_node;
+
+  /* Use memcpy to copy the descriptor. The size is the minimum of
+     the sizes of 'src' and 'dst'. This avoids a non-trivial conversion.  */
+  tmp = TYPE_SIZE_UNIT (TREE_TYPE (src));
+  tmp2 = TYPE_SIZE_UNIT (TREE_TYPE (dst));
+  size = fold_build2_loc (input_location, MIN_EXPR,
+                         TREE_TYPE (tmp), tmp, tmp2);
+  tmp = builtin_decl_explicit (BUILT_IN_MEMCPY);
+  tmp = build_call_expr_loc (input_location, tmp, 3,
+                            gfc_build_addr_expr (NULL_TREE, dst),
+                            gfc_build_addr_expr (NULL_TREE, src),
+                            fold_convert (size_type_node, size));
+  gfc_add_expr_to_block (block, tmp);
+
+  /* Set the offset correctly.  */
+  for (n = 0; n < rank; n++)
+    {
+      dim = gfc_rank_cst[n];
+      tmp = gfc_conv_descriptor_lbound_get (src, dim);
+      tmp2 = gfc_conv_descriptor_stride_get (src, dim);
+      tmp = fold_build2_loc (input_location, MULT_EXPR, TREE_TYPE (tmp),
+                            tmp, tmp2);
+      offset = fold_build2_loc (input_location, MINUS_EXPR,
+                       TREE_TYPE (offset), offset, tmp);
+      offset = gfc_evaluate_now (offset, block);
+    }
+
+  gfc_conv_descriptor_offset_set (block, dst, offset);
+}
+
+
diff --git a/gcc/fortran/trans-descriptor.h b/gcc/fortran/trans-descriptor.h
index 009f6a30a126..cdc9b323afbf 100644
--- a/gcc/fortran/trans-descriptor.h
+++ b/gcc/fortran/trans-descriptor.h
@@ -109,3 +109,7 @@ gfc_set_contiguous_array (stmtblock_t *block, tree desc, 
tree size,
 void
 gfc_class_array_data_assign (stmtblock_t *, tree, tree, bool);
 
+void
+gfc_copy_descriptor (stmtblock_t *, tree, tree, int);
+
+
diff --git a/gcc/fortran/trans-stmt.cc b/gcc/fortran/trans-stmt.cc
index afe323875b38..f61a1b08599f 100644
--- a/gcc/fortran/trans-stmt.cc
+++ b/gcc/fortran/trans-stmt.cc
@@ -1685,48 +1685,6 @@ class_has_len_component (gfc_symbol *sym)
 }
 
 
-static void
-copy_descriptor (stmtblock_t *block, tree dst, tree src, int rank)
-{
-  int n;
-  tree dim;
-  tree tmp;
-  tree tmp2;
-  tree size;
-  tree offset;
-
-  offset = gfc_index_zero_node;
-
-  /* Use memcpy to copy the descriptor. The size is the minimum of
-     the sizes of 'src' and 'dst'. This avoids a non-trivial conversion.  */
-  tmp = TYPE_SIZE_UNIT (TREE_TYPE (src));
-  tmp2 = TYPE_SIZE_UNIT (TREE_TYPE (dst));
-  size = fold_build2_loc (input_location, MIN_EXPR,
-                         TREE_TYPE (tmp), tmp, tmp2);
-  tmp = builtin_decl_explicit (BUILT_IN_MEMCPY);
-  tmp = build_call_expr_loc (input_location, tmp, 3,
-                            gfc_build_addr_expr (NULL_TREE, dst),
-                            gfc_build_addr_expr (NULL_TREE, src),
-                            fold_convert (size_type_node, size));
-  gfc_add_expr_to_block (block, tmp);
-
-  /* Set the offset correctly.  */
-  for (n = 0; n < rank; n++)
-    {
-      dim = gfc_rank_cst[n];
-      tmp = gfc_conv_descriptor_lbound_get (src, dim);
-      tmp2 = gfc_conv_descriptor_stride_get (src, dim);
-      tmp = fold_build2_loc (input_location, MULT_EXPR, TREE_TYPE (tmp),
-                            tmp, tmp2);
-      offset = fold_build2_loc (input_location, MINUS_EXPR,
-                       TREE_TYPE (offset), offset, tmp);
-      offset = gfc_evaluate_now (offset, block);
-    }
-
-  gfc_conv_descriptor_offset_set (block, dst, offset);
-}
-
-
 /* Do proper initialization for ASSOCIATE names.  */
 
 static void
@@ -1855,7 +1813,7 @@ trans_associate_var (gfc_symbol *sym, gfc_wrapped_block 
*block)
         attributes so the selector descriptor must be copied in and
         copied out.  */
       if (rank > 0)
-       copy_descriptor (&se.pre, desc, se.expr, rank);
+       gfc_copy_descriptor (&se.pre, desc, se.expr, rank);
       else
        {
          tmp = gfc_conv_descriptor_data_get (se.expr);
@@ -1884,7 +1842,7 @@ trans_associate_var (gfc_symbol *sym, gfc_wrapped_block 
*block)
                  || CLASS_DATA (sym)->attr.pointer)))
        {
          if (rank > 0)
-           copy_descriptor (&se.post, se.expr, desc, rank);
+           gfc_copy_descriptor (&se.post, se.expr, desc, rank);
          else
            gfc_conv_descriptor_data_set (&se.post, se.expr, desc);

Reply via email to