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

commit c0fcbc80556c9fed5d0c489eeebd42e1c81539f9
Author: Mikael Morin <mik...@gcc.gnu.org>
Date:   Thu Jul 31 17:47:15 2025 +0200

    Extraction gfc_set_empty_descriptor_bounds

Diff:
---
 gcc/fortran/trans-array.cc      | 18 ++----------------
 gcc/fortran/trans-descriptor.cc | 17 +++++++++++++++++
 gcc/fortran/trans-descriptor.h  |  1 +
 3 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 93bcd0161574..a559562057d3 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -10376,7 +10376,6 @@ gfc_alloc_allocatable_for_assignment (gfc_loopinfo 
*loop,
   stmtblock_t realloc_block;
   stmtblock_t alloc_block;
   stmtblock_t fblock;
-  stmtblock_t loop_pre_block;
   gfc_ref *ref;
   gfc_ss *rss;
   gfc_ss *lss;
@@ -10475,22 +10474,9 @@ gfc_alloc_allocatable_for_assignment (gfc_loopinfo 
*loop,
       tree guard = gfc_create_var (logical_type_node, 
"unallocated_init_guard");
       gfc_add_modify (&unalloc_init_block, guard, logical_false_node);
 
+      stmtblock_t loop_pre_block;
       gfc_start_block (&loop_pre_block);
-      for (n = 0; n < expr1->rank; n++)
-       {
-         gfc_conv_descriptor_lbound_set (&loop_pre_block, desc,
-                                         gfc_rank_cst[n],
-                                         gfc_index_one_node);
-         gfc_conv_descriptor_ubound_set (&loop_pre_block, desc,
-                                         gfc_rank_cst[n],
-                                         gfc_index_zero_node);
-         gfc_conv_descriptor_stride_set (&loop_pre_block, desc,
-                                         gfc_rank_cst[n],
-                                         gfc_index_zero_node);
-       }
-
-      gfc_conv_descriptor_offset_set (&loop_pre_block, desc,
-                                     gfc_index_zero_node);
+      gfc_set_empty_descriptor_bounds (&loop_pre_block, desc, expr1->rank);
 
       tmp = fold_build2_loc (input_location, EQ_EXPR,
                             logical_type_node, array1,
diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index 7b3bb912a968..afcea304fdbc 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -2860,3 +2860,20 @@ gfc_descriptor_init_count (tree descriptor, int rank, 
int corank,
   return stride;
 }
 
+
+void
+gfc_set_empty_descriptor_bounds (stmtblock_t *block, tree descr, int rank)
+{
+  for (int n = 0; n < rank; n++)
+    {
+      gfc_conv_descriptor_lbound_set (block, descr, gfc_rank_cst[n],
+                                     gfc_index_one_node);
+      gfc_conv_descriptor_ubound_set (block, descr, gfc_rank_cst[n],
+                                     gfc_index_zero_node);
+      gfc_conv_descriptor_stride_set (block, descr, gfc_rank_cst[n],
+                                     gfc_index_zero_node);
+    }
+
+  gfc_conv_descriptor_offset_set (block, descr, gfc_index_zero_node);
+}
+
diff --git a/gcc/fortran/trans-descriptor.h b/gcc/fortran/trans-descriptor.h
index f6d545669408..f66887ead234 100644
--- a/gcc/fortran/trans-descriptor.h
+++ b/gcc/fortran/trans-descriptor.h
@@ -156,5 +156,6 @@ gfc_descriptor_init_count (tree, int, int, gfc_expr **, 
gfc_expr **,
                           stmtblock_t * pblock, stmtblock_t *, tree *,
                           tree, gfc_expr *, tree, bool, gfc_expr *, tree,
                           bool, tree *);
+void gfc_set_empty_descriptor_bounds (stmtblock_t *, tree, int);
 
 #endif /* GFC_TRANS_DESCRIPTOR_H */

Reply via email to