[gcc(refs/users/mikael/heads/refactor_descriptor_v291.01)] Extraction gfc_shift_descriptor

Mikael Morin via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:ef98d635fa01610e145d11fbc3b4691436647b16

commit ef98d635fa01610e145d11fbc3b4691436647b16
Author: Mikael Morin <[email protected]>
Date:   Wed Jul 23 14:59:35 2025 +0200

    Extraction gfc_shift_descriptor

Diff:
---
 gcc/fortran/trans-descriptor.cc | 32 ++++++++++++++++++++++++++++++++
 gcc/fortran/trans-descriptor.h  |  2 ++
 gcc/fortran/trans-expr.cc       | 39 ++-------------------------------------
 3 files changed, 36 insertions(+), 37 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index 59975d870d5a..bc76d0c4a8e3 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -1288,3 +1288,35 @@ gfc_set_subarray_descriptor (stmtblock_t *block, tree descr, tree value,
       gfc_conv_descriptor_offset_set (block, descr, tmp);
     }
 }
+
+
+void
+gfc_shift_descriptor (stmtblock_t *block, tree descr, int rank,
+		      tree lbound[GFC_MAX_DIMENSIONS],
+		      tree ubound[GFC_MAX_DIMENSIONS])
+{
+  tree size = gfc_index_one_node;
+  tree offset = gfc_index_zero_node;
+  for (int n = 0; n < rank; n++)
+    {
+      tree tmp = gfc_conv_descriptor_ubound_get (descr, gfc_rank_cst[n]);
+      tmp = fold_build2_loc (input_location, PLUS_EXPR,
+			     gfc_array_index_type, tmp,
+			     gfc_index_one_node);
+      gfc_conv_descriptor_ubound_set (block, descr, gfc_rank_cst[n], tmp);
+      gfc_conv_descriptor_lbound_set (block, descr, gfc_rank_cst[n],
+				      gfc_index_one_node);
+      size = gfc_evaluate_now (size, block);
+      offset = fold_build2_loc (input_location, MINUS_EXPR,
+				gfc_array_index_type, offset, size);
+      offset = gfc_evaluate_now (offset, block);
+      tmp = fold_build2_loc (input_location, MINUS_EXPR,
+			     gfc_array_index_type, ubound[n], lbound[n]);
+      tmp = fold_build2_loc (input_location, PLUS_EXPR,
+			     gfc_array_index_type, tmp, gfc_index_one_node);
+      size = fold_build2_loc (input_location, MULT_EXPR,
+			      gfc_array_index_type, size, tmp);
+    }
+
+  gfc_conv_descriptor_offset_set (block, descr, offset);
+}
diff --git a/gcc/fortran/trans-descriptor.h b/gcc/fortran/trans-descriptor.h
index f9360930d1df..65e1a193d204 100644
--- a/gcc/fortran/trans-descriptor.h
+++ b/gcc/fortran/trans-descriptor.h
@@ -90,6 +90,8 @@ void gfc_conv_shift_descriptor (stmtblock_t *, tree, int);
 void gfc_conv_shift_descriptor (stmtblock_t *, tree, const gfc_array_ref &);
 void gfc_conv_shift_descriptor (stmtblock_t *, tree, tree, int, tree);
 void gfc_set_subarray_descriptor (stmtblock_t *, tree, tree, gfc_expr *, gfc_expr *);
+void gfc_shift_descriptor (stmtblock_t *, tree, int, tree [GFC_MAX_DIMENSIONS],
+			   tree [GFC_MAX_DIMENSIONS]);
 
 void gfc_set_descriptor_from_scalar_class (stmtblock_t *, tree, tree, gfc_expr *);
 void gfc_set_descriptor_from_scalar (stmtblock_t *, tree, tree, symbol_attribute,
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index f4a816315c95..6f5a3308b76c 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -5463,7 +5463,6 @@ gfc_conv_subref_array_arg (gfc_se *se, gfc_expr * expr, int g77,
   tree tmp_index;
   tree tmp;
   tree base_type;
-  tree size;
   stmtblock_t body;
   int n;
   int dimen;
@@ -5706,42 +5705,8 @@ class_array_fcn:
   /* Determine the offset for pointer formal arguments and set the
      lbounds to one.  */
   if (formal_ptr)
-    {
-      size = gfc_index_one_node;
-      offset = gfc_index_zero_node;
-      for (n = 0; n < dimen; n++)
-	{
-	  tmp = gfc_conv_descriptor_ubound_get (parmse->expr,
-						gfc_rank_cst[n]);
-	  tmp = fold_build2_loc (input_location, PLUS_EXPR,
-				 gfc_array_index_type, tmp,
-				 gfc_index_one_node);
-	  gfc_conv_descriptor_ubound_set (&parmse->pre,
-					  parmse->expr,
-					  gfc_rank_cst[n],
-					  tmp);
-	  gfc_conv_descriptor_lbound_set (&parmse->pre,
-					  parmse->expr,
-					  gfc_rank_cst[n],
-					  gfc_index_one_node);
-	  size = gfc_evaluate_now (size, &parmse->pre);
-	  offset = fold_build2_loc (input_location, MINUS_EXPR,
-				    gfc_array_index_type,
-				    offset, size);
-	  offset = gfc_evaluate_now (offset, &parmse->pre);
-	  tmp = fold_build2_loc (input_location, MINUS_EXPR,
-				 gfc_array_index_type,
-				 rse.loop->to[n], rse.loop->from[n]);
-	  tmp = fold_build2_loc (input_location, PLUS_EXPR,
-				 gfc_array_index_type,
-				 tmp, gfc_index_one_node);
-	  size = fold_build2_loc (input_location, MULT_EXPR,
-				  gfc_array_index_type, size, tmp);
-	}
-
-      gfc_conv_descriptor_offset_set (&parmse->pre, parmse->expr,
-				      offset);
-    }
+    gfc_shift_descriptor (&parmse->pre, parmse->expr, dimen,
+			  rse.loop->from, rse.loop->to);
 
   /* We want either the address for the data or the address of the descriptor,
      depending on the mode of passing array arguments.  */
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.