https://gcc.gnu.org/g:d0e5db8755d5cc26106c2939eb66519a4df43516

commit d0e5db8755d5cc26106c2939eb66519a4df43516
Author: Mikael Morin <mik...@gcc.gnu.org>
Date:   Sun Aug 17 19:56:14 2025 +0200

    Factorisation utilisation shapeval

Diff:
---
 gcc/fortran/trans-descriptor.cc | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index d283c741767f..f3d6d83fd902 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -1755,12 +1755,12 @@ gfc_set_descriptor_with_shape (stmtblock_t *block, tree 
desc, tree ptr,
 
   gfc_conv_expr (&shapese, shape);
   gfc_add_block_to_block (&body, &shapese.pre);
+  tree shapeval = fold_convert (gfc_array_index_type, shapese.expr);
+  shapeval = gfc_evaluate_now (shapeval, &body);
   tmp = fold_build2_loc (input_location, MINUS_EXPR, gfc_array_index_type,
                         lbound, gfc_index_one_node);
   tree ubound = fold_build2_loc (input_location, PLUS_EXPR,
-                                gfc_array_index_type, tmp,
-                                fold_convert (gfc_array_index_type,
-                                              shapese.expr));
+                                gfc_array_index_type, tmp, shapeval);
   gfc_conv_descriptor_ubound_set (&body, desc, dim, ubound);
   gfc_add_block_to_block (&body, &shapese.post);
 
@@ -1774,9 +1774,7 @@ gfc_set_descriptor_with_shape (stmtblock_t *block, tree 
desc, tree ptr,
   /* Update stride.  */
   gfc_add_modify (&body, stride,
                  fold_build2_loc (input_location, MULT_EXPR,
-                                  gfc_array_index_type, stride,
-                                  fold_convert (gfc_array_index_type,
-                                                shapese.expr)));
+                                  gfc_array_index_type, stride, shapeval));
   /* Finish scalarization loop.  */
   gfc_trans_scalarizing_loops (&loop, &body);
   gfc_add_block_to_block (block, &loop.pre);

Reply via email to