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

commit a039cb83bd35122a6f93ecb0be3634c33fd6afe6
Author: Mikael Morin <[email protected]>
Date:   Sun Sep 28 14:07:41 2025 +0200

    Correction régression coarray/ptr_comp_3.f08

Diff:
---
 gcc/fortran/trans-array.cc      | 13 +++++++++++--
 gcc/fortran/trans-descriptor.cc | 13 +++++++------
 2 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index c999c59f01dd..96889efaa18b 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -6225,8 +6225,17 @@ gfc_array_allocate (gfc_se * se, gfc_expr * expr, tree 
status, tree errmsg,
                                          element_size, explicit_ts,
                                          &empty_array_cond);
 
-  tree size = get_array_memory_size (element_size, count, empty_array_cond,
-                                    &se->pre, &overflow);
+  tree size;
+  if (GFC_BYTES_STRIDES_ARRAY_TYPE_P (TREE_TYPE (se->expr)))
+    size = count;
+  else
+    {
+      /* The stride is the number of elements in the array, so multiply by the
+        size of an element to get the total size.  */
+
+      size = get_array_memory_size (element_size, count, empty_array_cond,
+                                   &se->pre, &overflow);
+    }
 
   if (dimension)
     {
diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index 13f1d659ce43..57cfe7f575fb 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -2917,11 +2917,15 @@ gfc_descriptor_init_count (tree descriptor, int rank, 
int corank,
   int n;
 
   type = TREE_TYPE (descriptor);
-  gcc_assert (!GFC_BYTES_STRIDES_ARRAY_TYPE_P (type));
 
-  bool bytes_counted_strides = false;
+  bool bytes_counted_strides = GFC_BYTES_STRIDES_ARRAY_TYPE_P (type);
+
+  if (bytes_counted_strides)
+    stride = fold_convert_loc (input_location, gfc_array_index_type,
+                              element_size);
+  else
+    stride = gfc_index_one_node;
 
-  stride = gfc_index_one_node;
   offset = gfc_index_zero_node;
 
   /* Set the dtype before the alloc, because registration of coarrays needs
@@ -3120,9 +3124,6 @@ gfc_descriptor_init_count (tree descriptor, int rank, int 
corank,
        }
     }
 
-  /* The stride is the number of elements in the array, so multiply by the
-     size of an element to get the total size.  */
-
   if (rank == 0)
     return gfc_index_one_node;

Reply via email to