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

commit aec47e1c4d1c2d5899c06f68825d508fb4695a35
Author: Mikael Morin <mik...@gcc.gnu.org>
Date:   Fri May 2 12:08:51 2025 +0200

    Revert "Correction régression realloc_on_assign_10"
    
    This reverts commit dc0220b64f510e20fb6316aeb2cfc7d3f5b6fda7.

Diff:
---
 gcc/fortran/trans-descriptor.cc | 32 +++++++++++++++++++++++++++++---
 gcc/fortran/trans-descriptor.h  |  2 +-
 gcc/fortran/trans-expr.cc       |  2 +-
 3 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index 03a6d71bbabf..b58c90e073af 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -2155,10 +2155,27 @@ conv_shift_descriptor (stmtblock_t *block, tree desc, 
int rank,
 }
 
 
-void
-gfc_conv_shift_descriptor (stmtblock_t* block, tree dest, tree src, int rank)
+class cond_descr_lb : public lb_info_base
+{
+  tree desc;
+  tree cond;
+public:
+  cond_descr_lb (tree arg_desc, tree arg_cond)
+    : desc (arg_desc), cond (arg_cond) { }
+
+  virtual tree lower_bound (stmtblock_t *block, int dim) const;
+  virtual bool zero_based_src () const { return true; }
+};
+
+
+tree
+cond_descr_lb::lower_bound (stmtblock_t *block ATTRIBUTE_UNUSED, int dim) const
 {
-  conv_shift_descriptor (block, src, dest, rank, unset_lb ());
+  tree lbound = gfc_conv_descriptor_lbound_get (desc, gfc_rank_cst[dim]);
+  lbound = fold_build3_loc (input_location, COND_EXPR,
+                           gfc_array_index_type, cond,
+                           gfc_index_one_node, lbound);
+  return lbound;
 }
 
 
@@ -2436,6 +2453,15 @@ gfc_conv_remap_descriptor (stmtblock_t *block, tree 
dest, tree src,
 }
 
 
+void
+gfc_conv_shift_descriptor (stmtblock_t *block, tree dest, tree src,
+                          int rank, tree zero_cond)
+{
+  conv_shift_descriptor (block, src, dest, rank,
+                        cond_descr_lb (src, zero_cond));
+}
+
+
 void
 gfc_copy_descriptor (stmtblock_t *block, tree dest, tree src,
                     gfc_expr *src_expr, bool subref)
diff --git a/gcc/fortran/trans-descriptor.h b/gcc/fortran/trans-descriptor.h
index 3244359c176e..e431aeb9a7a3 100644
--- a/gcc/fortran/trans-descriptor.h
+++ b/gcc/fortran/trans-descriptor.h
@@ -81,7 +81,7 @@ tree gfc_get_cfi_dim_sm (tree, tree);
 tree gfc_build_desc_array_type (tree, tree, int, tree *, tree *);
 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);
+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 *);
 
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 7f2a156c30ef..cc2a817a5df7 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -11501,7 +11501,7 @@ fcncall_realloc_result (gfc_se *se, int rank, tree 
dtype)
   /* Now reset the bounds returned from the function call to bounds based
      on the lhs lbounds, except where the lhs is not allocated or the shapes
      of 'variable and 'expr' are different. Set the offset accordingly.  */
-  gfc_conv_shift_descriptor (&se->post, desc, res_desc, rank);
+  gfc_conv_shift_descriptor (&se->post, desc, res_desc, rank, zero_cond);
 }

Reply via email to