]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
fortran: array descriptor: Move descriptor copy function [PR122521]
authorMikael Morin <mikael@gcc.gnu.org>
Thu, 2 Jul 2026 08:44:59 +0000 (10:44 +0200)
committerMikael Morin <mikael@gcc.gnu.org>
Thu, 2 Jul 2026 08:44:59 +0000 (10:44 +0200)
Move copy_descriptor in trans-stmt.cc to gfc_copy_descriptor in
trans-descriptor.cc.

PR fortran/122521

gcc/fortran/ChangeLog:

* trans-descriptor.h (gfc_copy_descriptor): Add declaration.
* trans-stmt.cc (trans_associate_var): Update caller.
(copy_descriptor): Rename function and move it ...
* trans-descriptor.cc (gfc_copy_descriptor): ... here.

gcc/fortran/trans-descriptor.cc
gcc/fortran/trans-descriptor.h
gcc/fortran/trans-stmt.cc

index 57297fcf75d7a90c763459c8e4349d1b333c2b0f..eff9108ef987272baab98f14870afaa924786fcd 100644 (file)
@@ -499,3 +499,45 @@ gfc_conv_shift_descriptor_lbound (stmtblock_t* block, tree desc,
   /* Finally set lbound to value we want.  */
   gfc_conv_descriptor_lbound_set (block, desc, gfc_rank_cst[dim], new_lbound);
 }
+
+
+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);
+}
index fefa152e2d769167d237f9b66138f757f47c6937..b1623a2180331f89d5d2f1c46b2c635c3e6e67a0 100644 (file)
@@ -60,4 +60,6 @@ tree gfc_conv_descriptor_cosize (tree, int, int);
 /* Shift lower bound of descriptor, updating ubound and offset.  */
 void gfc_conv_shift_descriptor_lbound (stmtblock_t*, tree, int, tree);
 
+void gfc_copy_descriptor (stmtblock_t *, tree, tree, int);
+
 #endif /* GFC_TRANS_DESCRIPTOR_H */
index b53db6fd74c6ab915ebb3c43621597d933bd2bdd..90ac572dd72581123e5a1ee6e7430c94c6a991f9 100644 (file)
@@ -1828,48 +1828,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
@@ -1998,7 +1956,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);
@@ -2027,7 +1985,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);