[gcc(refs/users/mikael/heads/refactor_descriptor_v291.01)] Factorisation shift_dimension_fields/set_dimension_fields gfc_set_temporaray_descriptor

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

commit ffbb6e7baced69d0973148d15c7bfc0b185ab75a
Author: Mikael Morin <[email protected]>
Date:   Sat Aug 16 18:41:13 2025 +0200

    Factorisation shift_dimension_fields/set_dimension_fields gfc_set_temporaray_descriptor
    
    Correction utilisation offset
    
    Revert "Revert partiel"
    
    This reverts commit 00ca0a062b284d18755fb50f9dece28fc3013ced.
    
    Correction régression pr77942

Diff:
---
 gcc/fortran/trans-descriptor.cc | 52 ++++++++++++++---------------------------
 1 file changed, 18 insertions(+), 34 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index 43697a96328b..219a91792b48 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -877,6 +877,18 @@ shift_dimension_bounds (stmtblock_t * block, tree descr, tree dim,
 }
 
 
+static void
+shift_dimension_fields (stmtblock_t * block, tree descr, tree dim,
+			tree new_lbound, tree orig_lbound, tree orig_ubound,
+			tree orig_stride, tree *offset_value)
+{
+  tree stride = gfc_evaluate_now (orig_stride, block);
+  shift_dimension_bounds (block, descr, dim, new_lbound, orig_lbound, orig_ubound,
+			  stride, offset_value);
+  gfc_conv_descriptor_stride_set (block, descr, dim, stride);
+}
+
+
 /* Modify a descriptor such that the lbound of a given dimension is the value
    specified.  This also updates ubound and offset accordingly.  */
 
@@ -1317,12 +1329,10 @@ gfc_conv_shift_descriptor (stmtblock_t *block, tree dest, tree src,
 
       tree dim = gfc_rank_cst[n];
       tree stride = gfc_conv_descriptor_stride_get (src, dim);
-      shift_dimension_bounds (block, dest, gfc_rank_cst[n],
+      shift_dimension_fields (block, dest, gfc_rank_cst[n],
 			      lbound, gfc_index_zero_node,
 			      gfc_conv_descriptor_ubound_get (src, dim),
 			      stride, &offset);
-
-      gfc_conv_descriptor_stride_set (block, dest, dim, stride);
     }
 
   gfc_conv_descriptor_offset_set (block, dest, offset);
@@ -2371,39 +2381,13 @@ gfc_set_temporary_descriptor (stmtblock_t *block, tree descr, tree class_src,
   if (!callee_allocated)
     for (int n = 0; n < rank; n++)
       {
-	/* Store the stride and bound components in the descriptor.  */
-	gfc_conv_descriptor_stride_set (block, descr, gfc_rank_cst[n],
-					stride[n]);
-
-	tree this_lbound = shift_bounds ? gfc_index_zero_node : lbound[n];
-	gfc_conv_descriptor_lbound_set (block, descr, gfc_rank_cst[n],
-					this_lbound);
-
-	tree this_ubound;
 	if (shift_bounds)
-	  {
-	    tree lbound_diff = fold_build2_loc (input_location, MINUS_EXPR,
-						gfc_array_index_type,
-						this_lbound, lbound[n]);
-	    this_ubound = fold_build2_loc (input_location, PLUS_EXPR,
-					   gfc_array_index_type,
-					   ubound[n], lbound_diff);
-	  }
+	  shift_dimension_fields (block, descr, gfc_rank_cst[n],
+				  gfc_index_zero_node, lbound[n], ubound[n],
+				  stride[n], &offset);
 	else
-	  this_ubound = ubound[n];
-
-	gfc_conv_descriptor_ubound_set (block, descr, gfc_rank_cst[n],
-					this_ubound);
-
-	if (!shift_bounds)
-	  {
-	    tree tmp = fold_build2_loc (input_location, MULT_EXPR,
-					gfc_array_index_type, this_lbound,
-					stride[n]);
-	    tmp = fold_build2_loc (input_location, MINUS_EXPR,
-				   gfc_array_index_type, offset, tmp);
-	    offset = gfc_evaluate_now (tmp, block);
-	  }
+	  set_dimension_fields (block, descr, gfc_rank_cst[n], lbound[n],
+				ubound[n], stride[n], &offset);
       }
 
   gfc_conv_descriptor_span_set (block, descr, elemsize);
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.