https://gcc.gnu.org/g:8773ceade0f9f3927c3428b928e69bc852227a9c

commit 8773ceade0f9f3927c3428b928e69bc852227a9c
Author: Mikael Morin <mik...@gcc.gnu.org>
Date:   Fri Feb 7 15:01:35 2025 +0100

    Correction régression bound_10.f90

Diff:
---
 gcc/fortran/trans-array.cc | 37 +++++++++++++++++++------------------
 1 file changed, 19 insertions(+), 18 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index e0412b22b170..b11bf5c1036e 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -1512,7 +1512,7 @@ set_descriptor_dimension (stmtblock_t *block, tree desc, 
int dim,
 
 static void
 conv_shift_descriptor_lbound (stmtblock_t* block, tree from_desc, tree 
to_desc, int dim,
-                             tree new_lbound, tree offset, bool 
relative_offset)
+                             tree new_lbound, tree offset, bool zero_based)
 {
   /* Set lbound to the value we want.  */
   new_lbound = fold_convert (gfc_array_index_type, new_lbound);
@@ -1523,9 +1523,16 @@ conv_shift_descriptor_lbound (stmtblock_t* block, tree 
from_desc, tree to_desc,
   tree ubound = gfc_conv_descriptor_ubound_get (from_desc, gfc_rank_cst[dim]);
   tree stride = gfc_conv_descriptor_stride_get (from_desc, gfc_rank_cst[dim]);
 
-  /* Get difference (new - old) by which to shift stuff.  */
-  tree diff = fold_build2_loc (input_location, MINUS_EXPR, 
gfc_array_index_type,
-                              new_lbound, lbound);
+  tree diff;
+  if (zero_based)
+    diff = new_lbound;
+  else
+    {
+      /* Get difference (new - old) by which to shift stuff.  */
+      diff = fold_build2_loc (input_location, MINUS_EXPR, gfc_array_index_type,
+                             new_lbound, lbound);
+      diff = gfc_evaluate_now (diff, block);
+    }
 
   /* Shift ubound and offset accordingly.  This has to be done before
      updating the lbound, as they depend on the lbound expression!  */
@@ -1533,14 +1540,8 @@ conv_shift_descriptor_lbound (stmtblock_t* block, tree 
from_desc, tree to_desc,
                               ubound, diff);
   gfc_conv_descriptor_ubound_set (block, to_desc, gfc_rank_cst[dim], tmp1);
 
-  tree offs_diff;
-  if (relative_offset)
-    offs_diff = diff;
-  else
-    offs_diff = lbound;
-
-  offs_diff = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type,
-                              offs_diff, stride);
+  tree offs_diff = fold_build2_loc (input_location, MULT_EXPR, 
gfc_array_index_type,
+                                   diff, stride);
   tree tmp2 = fold_build2_loc (input_location, MINUS_EXPR, 
gfc_array_index_type,
                               offset, offs_diff);
   gfc_add_modify (block, offset, tmp2);
@@ -1554,7 +1555,7 @@ class lb_info_base
 {
 public:
   virtual tree lower_bound (stmtblock_t *block, int dim) const = 0;
-  virtual bool relative_offset () const { return true; }
+  virtual bool zero_based_src () const { return false; }
 };
 
 
@@ -1626,10 +1627,10 @@ conv_shift_descriptor (stmtblock_t *block, tree src, 
tree dest, int rank,
 
   tree offset_var = gfc_create_var (gfc_array_index_type, "offset");
   tree init_offset;
-  if (info.relative_offset ())
-    init_offset = gfc_conv_descriptor_offset_get (src);
-  else
+  if (info.zero_based_src ())
     init_offset = gfc_index_zero_node;
+  else
+    init_offset = gfc_conv_descriptor_offset_get (src);
   gfc_add_modify (block, offset_var, init_offset);
 
   /* Apply a shift of the lbound when supplied.  */
@@ -1637,7 +1638,7 @@ conv_shift_descriptor (stmtblock_t *block, tree src, tree 
dest, int rank,
     {
       tree lower_bound = info.lower_bound (block, dim);
       conv_shift_descriptor_lbound (block, src, dest, dim, lower_bound, 
offset_var,
-                                   info.relative_offset ());
+                                   info.zero_based_src ());
     }
 
   gfc_conv_descriptor_offset_set (block, dest, offset_var);
@@ -1661,7 +1662,7 @@ public:
     : desc (arg_desc), cond (arg_cond) { }
 
   virtual tree lower_bound (stmtblock_t *block, int dim) const;
-  virtual bool relative_offset () const { return false; }
+  virtual bool zero_based_src () const { return true; }
 };

Reply via email to