[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Refactor set_dimension_bounds

Mikael Morin mikael@gcc.gnu.org
Mon Sep 15 13:35:21 GMT 2025


https://gcc.gnu.org/g:0e943e2ed9fadcc7d2c565875c0e533a37e21076

commit 0e943e2ed9fadcc7d2c565875c0e533a37e21076
Author: Mikael Morin <mikael@gcc.gnu.org>
Date:   Fri Aug 15 22:08:28 2025 +0200

    Refactor set_dimension_bounds
    
    Correction régression pr85938

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

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index a26a3b2b01a9..cddffac71246 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -989,13 +989,40 @@ gfc_set_descriptor_from_scalar (stmtblock_t *block, tree descr,
 }
 
 
+static void
+set_dimension_bounds (stmtblock_t * block, tree descr, tree dim,
+		      tree lbound, tree ubound, tree stride, tree *offset)
+{
+  lbound = gfc_evaluate_now (lbound, block);
+
+  gfc_conv_descriptor_ubound_set (block, descr, dim, ubound);
+
+  tree tmp = fold_build2_loc (input_location, MULT_EXPR,
+			      gfc_array_index_type, lbound, stride);
+  *offset = fold_build2_loc (input_location, MINUS_EXPR,
+			     gfc_array_index_type, *offset, tmp);
+
+  /* Finally set lbound to value we want.  */
+  gfc_conv_descriptor_lbound_set (block, descr, dim, lbound);
+}
+
+
+static void
+set_dimension_bounds (stmtblock_t * block, tree descr, tree dim,
+		      tree lbound, tree ubound, tree stride, tree offset_var)
+{
+  tree offset = offset_var;
+  set_dimension_bounds (block, descr, dim, lbound, ubound, stride, &offset);
+  gfc_add_modify (block, offset_var, offset);
+}
+
+
 static void
 shift_dimension_bounds (stmtblock_t * block, tree descr, tree dim,
 			tree new_lbound, tree orig_lbound, tree orig_ubound,
 			tree orig_stride, tree *offset_value)
 {
   new_lbound = fold_convert (gfc_array_index_type, new_lbound);
-  new_lbound = gfc_evaluate_now (new_lbound, block);
 
   orig_stride = gfc_evaluate_now (orig_stride, block);
 
@@ -1007,14 +1034,9 @@ shift_dimension_bounds (stmtblock_t * block, tree descr, tree dim,
      updating the lbound, as they depend on the lbound expression!  */
   tree ubound = fold_build2_loc (input_location, PLUS_EXPR,
 				 gfc_array_index_type, orig_ubound, diff);
-  gfc_conv_descriptor_ubound_set (block, descr, dim, ubound);
-  tree tmp = fold_build2_loc (input_location, MULT_EXPR,
-			      gfc_array_index_type, new_lbound, orig_stride);
-  *offset_value = fold_build2_loc (input_location, MINUS_EXPR,
-				   gfc_array_index_type, *offset_value, tmp);
 
-  /* Finally set lbound to value we want.  */
-  gfc_conv_descriptor_lbound_set (block, descr, dim, new_lbound);
+  set_dimension_bounds (block, descr, dim, new_lbound, ubound, orig_stride,
+			offset_value);
 }
 
 
@@ -1802,15 +1824,12 @@ set_gfc_dimension_from_cfi (stmtblock_t *block, tree gfc, tree cfi, tree idx,
 {
   /* gfc->dim[i].lbound = ... */
   lbound = fold_convert (gfc_array_index_type, lbound);
-  lbound = gfc_evaluate_now (lbound, block);
-  gfc_conv_descriptor_lbound_set (block, gfc, idx, lbound);
 
   /* gfc->dim[i].ubound = gfc->dim[i].lbound + cfi->dim[i].extent - 1. */
   tree tmp = fold_build2_loc (input_location, MINUS_EXPR, gfc_array_index_type,
 			      lbound, gfc_index_one_node);
-  tmp = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type,
-			 gfc_get_cfi_dim_extent (cfi, idx), tmp);
-  gfc_conv_descriptor_ubound_set (block, gfc, idx, tmp);
+  tree ubound = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type,
+				 gfc_get_cfi_dim_extent (cfi, idx), tmp);
 
   tree stride;
   if (contiguous)
@@ -1839,14 +1858,9 @@ set_gfc_dimension_from_cfi (stmtblock_t *block, tree gfc, tree cfi, tree idx,
 					   gfc_get_cfi_desc_elem_len (cfi)));
       stride = gfc_evaluate_now (tmp, block);
     }
-  gfc_conv_descriptor_stride_set (block, gfc, idx, stride);
 
-  /* gfc->offset -= gfc->dim[i].stride * gfc->dim[i].lbound. */
-  tmp = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type,
-			 stride, lbound);
-  tmp = fold_build2_loc (input_location, MINUS_EXPR, gfc_array_index_type,
-			 offset_var, tmp);
-  gfc_add_modify (block, offset_var, tmp);
+  set_dimension_bounds (block, gfc, idx, lbound, ubound, stride, offset_var);
+  gfc_conv_descriptor_stride_set (block, gfc, idx, stride);
 }


More information about the Gcc-cvs mailing list