https://gcc.gnu.org/g:9e9030951592f83556ac71fc36ab41c119e482ee
commit 9e9030951592f83556ac71fc36ab41c119e482ee Author: Mikael Morin <mik...@gcc.gnu.org> Date: Fri Feb 14 09:34:02 2025 +0100 Déplacement fonction Diff: --- gcc/fortran/trans-array.cc | 53 ++++++++++++++++++++++++++++++++++++++-------- gcc/fortran/trans-array.h | 1 + gcc/fortran/trans-expr.cc | 41 ++--------------------------------- 3 files changed, 47 insertions(+), 48 deletions(-) diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc index 5be7e29130d3..2ec19e44a465 100644 --- a/gcc/fortran/trans-array.cc +++ b/gcc/fortran/trans-array.cc @@ -2227,6 +2227,44 @@ gfc_conv_shift_descriptor_subarray (stmtblock_t *block, tree desc, } +void +gfc_conv_shift_descriptor (stmtblock_t *block, tree desc, 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 (desc, 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, + desc, + gfc_rank_cst[n], + tmp); + gfc_conv_descriptor_lbound_set (block, + desc, + 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 = gfc_conv_array_extent_dim (lbound[n], ubound[n], nullptr); + size = fold_build2_loc (input_location, MULT_EXPR, + gfc_array_index_type, size, tmp); + } + + gfc_conv_descriptor_offset_set (block, desc, + offset); +} + + + + int gfc_descriptor_rank (tree descriptor) { @@ -8412,15 +8450,12 @@ gfc_array_init_size (tree descriptor, int rank, int corank, tree * poffset, start at zero, but when allocating it, the standard expects the array to start at one. Therefore fix the upper bound to be (desc.ubound - desc.lbound) + 1. */ - tmp = fold_build2_loc (input_location, MINUS_EXPR, - gfc_array_index_type, - gfc_conv_descriptor_ubound_get ( - expr3_desc, gfc_rank_cst[n]), - gfc_conv_descriptor_lbound_get ( - expr3_desc, gfc_rank_cst[n])); - tmp = fold_build2_loc (input_location, PLUS_EXPR, - gfc_array_index_type, tmp, - gfc_index_one_node); + tmp = gfc_conv_array_extent_dim ( + gfc_conv_descriptor_lbound_get (expr3_desc, + gfc_rank_cst[n]), + gfc_conv_descriptor_ubound_get (expr3_desc, + gfc_rank_cst[n]), + nullptr); se.expr = gfc_evaluate_now (tmp, pblock); } else diff --git a/gcc/fortran/trans-array.h b/gcc/fortran/trans-array.h index 836a177da014..f37f09c21cff 100644 --- a/gcc/fortran/trans-array.h +++ b/gcc/fortran/trans-array.h @@ -237,6 +237,7 @@ void gfc_conv_shift_descriptor (stmtblock_t*, tree, const gfc_array_ref &); void gfc_conv_shift_descriptor (stmtblock_t*, tree, int); void gfc_conv_shift_descriptor (stmtblock_t*, tree, tree, int, tree); void gfc_conv_shift_descriptor_subarray (stmtblock_t*, tree, gfc_expr *, gfc_expr *); +void gfc_conv_shift_descriptor (stmtblock_t *, tree, int, tree *, tree *); /* Add pre-loop scalarization code for intrinsic functions which require special handling. */ diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc index f9078dd1b694..be5df5e1fa8e 100644 --- a/gcc/fortran/trans-expr.cc +++ b/gcc/fortran/trans-expr.cc @@ -5364,43 +5364,6 @@ gfc_apply_interface_mapping (gfc_interface_mapping * mapping, } -static void -shift_descriptor (stmtblock_t *block, tree desc, 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 (desc, 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, - desc, - gfc_rank_cst[n], - tmp); - gfc_conv_descriptor_lbound_set (block, - desc, - 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 = gfc_conv_array_extent_dim (lbound[n], ubound[n], nullptr); - size = fold_build2_loc (input_location, MULT_EXPR, - gfc_array_index_type, size, tmp); - } - - gfc_conv_descriptor_offset_set (block, desc, - offset); -} - - /* Returns a reference to a temporary array into which a component of an actual argument derived type array is copied and then returned after the function call. */ @@ -5671,8 +5634,8 @@ class_array_fcn: /* Determine the offset for pointer formal arguments and set the lbounds to one. */ if (formal_ptr) - shift_descriptor (&parmse->pre, parmse->expr, dimen, - rse.loop->from, rse.loop->to); + gfc_conv_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. */