https://gcc.gnu.org/g:647d2f277df300f51eb709a1a712be29014d2619
commit 647d2f277df300f51eb709a1a712be29014d2619 Author: Mikael Morin <mik...@gcc.gnu.org> Date: Fri Aug 15 22:08:28 2025 +0200 Refactor set_dimension_bounds 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 17d5aa1ec314..81f47eb9b147 100644 --- a/gcc/fortran/trans-descriptor.cc +++ b/gcc/fortran/trans-descriptor.cc @@ -1214,13 +1214,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); @@ -1232,14 +1259,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); } @@ -2007,15 +2029,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) @@ -2044,14 +2063,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); }