https://gcc.gnu.org/g:762a814bb82a3a6a10bbd5e460c69f0f658838cb

commit 762a814bb82a3a6a10bbd5e460c69f0f658838cb
Author: Mikael Morin <[email protected]>
Date:   Wed Oct 1 10:14:11 2025 +0200

    Correction régression array_function_1.f90

Diff:
---
 gcc/fortran/trans-array.cc | 26 ++++++++++++++++++++++----
 gcc/fortran/trans-array.h  |  2 +-
 gcc/fortran/trans.h        |  3 +++
 3 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 9308eb2174b4..5834b7d67ebe 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -229,7 +229,7 @@ gfc_get_array_ss (gfc_ss *next, gfc_expr *expr, int dimen, 
gfc_ss_type type)
 /* Creates and initializes a temporary type gfc_ss struct.  */
 
 gfc_ss *
-gfc_get_temp_ss (tree type, tree string_length, int dimen)
+gfc_get_temp_ss (tree type, tree string_length, int dimen, bool bytes_strided)
 {
   gfc_ss *ss;
   gfc_ss_info *ss_info;
@@ -240,6 +240,7 @@ gfc_get_temp_ss (tree type, tree string_length, int dimen)
   ss_info->type = GFC_SS_TEMP;
   ss_info->string_length = string_length;
   ss_info->data.temp.type = type;
+  ss_info->data.temp.bytes_strided = bytes_strided;
 
   ss = gfc_get_ss ();
   ss->info = ss_info;
@@ -1181,7 +1182,10 @@ gfc_trans_create_temp_array (stmtblock_t * pre, 
stmtblock_t * post, gfc_ss * ss,
     }
 
   info->descriptor = desc;
-  size = gfc_index_one_node;
+  if (GFC_BYTES_STRIDES_ARRAY_TYPE_P (TREE_TYPE (desc)))
+    size = elemsize;
+  else
+    size = gfc_index_one_node;
 
   /*
      Fill in the bounds and stride.  This is a packed array, so:
@@ -5852,6 +5856,7 @@ gfc_conv_loop_setup (gfc_loopinfo * loop, locus * where)
                         tmp_ss_info->string_length);
 
       bool preserve_bounds = tmp_ss_info->data.temp.preserve_bounds;
+      bool bytes_strided = tmp_ss_info->data.temp.bytes_strided;
 
       tmp = tmp_ss_info->data.temp.type;
       memset (&tmp_ss_info->data.array, 0, sizeof (gfc_array_info));
@@ -5861,7 +5866,7 @@ gfc_conv_loop_setup (gfc_loopinfo * loop, locus * where)
 
       gfc_trans_create_temp_array (&loop->pre, &loop->post, tmp_ss, tmp,
                                   NULL_TREE, false, true, false, where,
-                                  !preserve_bounds);
+                                  !preserve_bounds, !bytes_strided);
     }
 
   /* For array parameters we don't have loop variables, so don't calculate the
@@ -7989,7 +7994,8 @@ gfc_conv_expr_descriptor (gfc_se *se, gfc_expr *expr)
                                      ((expr->ts.type == BT_CHARACTER)
                                       ? expr->ts.u.cl->backend_decl
                                       : NULL),
-                                     loop.dimen);
+                                     loop.dimen,
+                                     se->bytes_strided);
 
       se->string_length = loop.temp_ss->info->string_length;
       gcc_assert (loop.temp_ss->dimen == loop.dimen);
@@ -8613,6 +8619,18 @@ gfc_conv_array_parameter (gfc_se *se, gfc_expr *expr, 
bool g77,
       /* Every other type of array.  */
       se->want_pointer = (ctree) ? 0 : 1;
       se->want_coarray = expr->corank;
+      se->bytes_strided = fsym
+                         && ((fsym->ts.type != BT_CLASS
+                              && !fsym->attr.contiguous
+                              && (fsym->attr.pointer
+                                  || (fsym->as
+                                      && fsym->as->type == AS_ASSUMED_SHAPE)))
+                             || (fsym->ts.type == BT_CLASS
+                                 && CLASS_DATA (fsym)->attr.contiguous
+                                 && (CLASS_DATA (fsym)->attr.class_pointer
+                                     || (CLASS_DATA (fsym)->as
+                                         && CLASS_DATA (fsym)->as->type
+                                            == AS_ASSUMED_SHAPE))));
       gfc_conv_expr_descriptor (se, expr);
 
       if (size)
diff --git a/gcc/fortran/trans-array.h b/gcc/fortran/trans-array.h
index 0ca42a892197..f055c58555d2 100644
--- a/gcc/fortran/trans-array.h
+++ b/gcc/fortran/trans-array.h
@@ -116,7 +116,7 @@ void gfc_free_ss (gfc_ss *);
 /* Allocate a new array type ss.  */
 gfc_ss *gfc_get_array_ss (gfc_ss *, gfc_expr *, int, gfc_ss_type);
 /* Allocate a new temporary type ss.  */
-gfc_ss *gfc_get_temp_ss (tree, tree, int);
+gfc_ss *gfc_get_temp_ss (tree, tree, int, bool bytes_strided = false);
 /* Allocate a new scalar type ss.  */
 gfc_ss *gfc_get_scalar_ss (gfc_ss *, gfc_expr *);
 
diff --git a/gcc/fortran/trans.h b/gcc/fortran/trans.h
index a5821c4a65ba..7c99230c8ed5 100644
--- a/gcc/fortran/trans.h
+++ b/gcc/fortran/trans.h
@@ -107,6 +107,8 @@ typedef struct gfc_se
 
   unsigned want_coarray:1;
 
+  unsigned bytes_strided:1;
+
   /* Scalarization parameters.  */
   struct gfc_se *parent;
   struct gfc_ss *ss;
@@ -307,6 +309,7 @@ typedef struct gfc_ss_info
     {
       tree type;
       bool preserve_bounds;
+      bool bytes_strided;
     }
     temp;

Reply via email to