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

commit 0f51ef03f19f788b844fd863398a9b860fab60f4
Author: Mikael Morin <mik...@gcc.gnu.org>
Date:   Sat Aug 16 18:19:27 2025 +0200

    Factorisation set_dimension_fields gfc_set_descriptor_with_shape
    
    Correction régression c_f_pointer_tests_4

Diff:
---
 gcc/fortran/trans-descriptor.cc | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index 632fef449d16..a5a755eb044d 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -1974,34 +1974,26 @@ gfc_set_descriptor_with_shape (stmtblock_t *block, tree 
desc,
   tree dim = fold_build2_loc (input_location, MINUS_EXPR, gfc_array_index_type,
                              loop.loopvar[0], loop.from[0]);
 
-  /* Set bounds and stride.  */
-  gfc_conv_descriptor_lbound_set (&body, desc, dim, gfc_index_one_node);
-  gfc_conv_descriptor_stride_set (&body, desc, dim, stride);
-
   gfc_conv_expr (&shapese, shape);
   gfc_add_block_to_block (&body, &shapese.pre);
-  gfc_conv_descriptor_ubound_set (&body, desc, dim, shapese.expr);
+  tree ubound = fold_convert (gfc_array_index_type, shapese.expr);
+  ubound = gfc_evaluate_now (ubound, &body);
   gfc_add_block_to_block (&body, &shapese.post);
 
-  /* Calculate offset.  */
-  gfc_add_modify (&body, offset,
-                 fold_build2_loc (input_location, PLUS_EXPR,
-                                  gfc_array_index_type, offset, stride));
+  set_dimension_fields (&body, desc, dim, gfc_index_one_node, ubound, stride,
+                       offset);
+
   /* 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, ubound));
+
   /* Finish scalarization loop.  */
   gfc_trans_scalarizing_loops (&loop, &body);
   gfc_add_block_to_block (block, &loop.pre);
   gfc_add_block_to_block (block, &loop.post);
   gfc_cleanup_loop (&loop);
 
-  gfc_add_modify (block, offset,
-                 fold_build1_loc (input_location, NEGATE_EXPR,
-                                  gfc_array_index_type, offset));
   gfc_conv_descriptor_offset_set (block, desc, offset);
 }

Reply via email to