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

commit c71f62dca3b428c6af1d84d39f9b6bebe38e8c46
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 559016eb9ae7..b01618dae58e 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -2142,10 +2142,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;
 }
 
 
@@ -2423,6 +2440,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 176fc1492daf..f648ae131129 100644
--- a/gcc/fortran/trans-descriptor.h
+++ b/gcc/fortran/trans-descriptor.h
@@ -84,7 +84,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 c49dcf6aadb2..c23ff4fca78d 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -11546,7 +11546,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