https://gcc.gnu.org/g:85ff737a71f0684126ee887e92bfb72f39ea7031

commit 85ff737a71f0684126ee887e92bfb72f39ea7031
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 | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index ce7495ab1f34..6ada111b9e6e 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -1995,15 +1995,12 @@ gfc_set_descriptor_with_shape (stmtblock_t *block, tree 
desc, tree ptr,
       gfc_conv_expr (&lowerse, lower);
       gfc_add_block_to_block (&body, &lowerse.pre);
       lbound = fold_convert (gfc_array_index_type, lowerse.expr);
+      lbound = gfc_evaluate_now (lbound, &body);
       gfc_add_block_to_block (&body, &lowerse.post);
     }
   else
     lbound = gfc_index_one_node;
 
-  /* Set bounds and stride.  */
-  gfc_conv_descriptor_lbound_set (&body, desc, dim, lbound);
-  gfc_conv_descriptor_stride_set (&body, desc, dim, stride);
-
   gfc_conv_expr (&shapese, shape);
   gfc_add_block_to_block (&body, &shapese.pre);
   tree shapeval = fold_convert (gfc_array_index_type, shapese.expr);
@@ -2012,29 +2009,22 @@ gfc_set_descriptor_with_shape (stmtblock_t *block, tree 
desc, tree ptr,
                         lbound, gfc_index_one_node);
   tree ubound = fold_build2_loc (input_location, PLUS_EXPR,
                                 gfc_array_index_type, tmp, shapeval);
-  gfc_conv_descriptor_ubound_set (&body, desc, dim, ubound);
+  ubound = gfc_evaluate_now (ubound, &body);
   gfc_add_block_to_block (&body, &shapese.post);
 
-  /* Calculate offset.  */
-  tmp = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type,
-                        stride, lbound);
-  gfc_add_modify (&body, offset,
-                 fold_build2_loc (input_location, PLUS_EXPR,
-                                  gfc_array_index_type, offset, tmp));
+  set_dimension_fields (&body, desc, dim, lbound, ubound, stride, offset);
 
   /* Update stride.  */
   gfc_add_modify (&body, stride,
                  fold_build2_loc (input_location, MULT_EXPR,
                                   gfc_array_index_type, stride, shapeval));
+
   /* 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