https://gcc.gnu.org/g:207ff4fb7d55d715c25269f847d05c686f3bcd99

commit 207ff4fb7d55d715c25269f847d05c686f3bcd99
Author: Mikael Morin <[email protected]>
Date:   Sun Sep 28 19:13:44 2025 +0200

    Correction régression alloc_comp_scalar_1.f90

Diff:
---
 gcc/fortran/trans-array.cc | 42 ++++++++++++++++++++++++++++++------------
 1 file changed, 30 insertions(+), 12 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index fafe96c6e298..df5eb5ef93ce 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -8877,19 +8877,37 @@ gfc_full_array_size (stmtblock_t *block, tree decl, int 
rank)
   tree nelems;
   tree tmp;
 
-  gcc_assert (!GFC_BYTES_STRIDES_ARRAY_TYPE_P (TREE_TYPE (decl)));
-
-  if (rank < 0)
-    idx = gfc_conv_descriptor_rank_get (decl);
+  if (GFC_BYTES_STRIDES_ARRAY_TYPE_P (TREE_TYPE (decl))
+      && rank > 0)
+    {
+      idx = gfc_rank_cst[rank - 1];
+      tree prod = gfc_index_one_node;
+      for (int i = 0; i < rank; i++)
+       {
+         tmp = gfc_conv_descriptor_extent_get (decl, idx);
+         prod = fold_build2_loc (input_location, MULT_EXPR,
+                                 gfc_array_index_type, prod, tmp);
+       }
+      return gfc_evaluate_now (prod, block);
+    }
   else
-    idx = gfc_rank_cst[rank - 1];
-  tmp = gfc_conv_descriptor_extent_get (decl, idx);
-  tmp = gfc_evaluate_now (tmp, block);
-
-  nelems = gfc_conv_descriptor_stride_get (decl, idx);
-  tmp = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type,
-                        nelems, tmp);
-  return gfc_evaluate_now (tmp, block);
+    {
+      if (rank < 0)
+       idx = gfc_conv_descriptor_rank_get (decl);
+      else
+       idx = gfc_rank_cst[rank - 1];
+      tmp = gfc_conv_descriptor_extent_get (decl, idx);
+      tmp = gfc_evaluate_now (tmp, block);
+
+      nelems = gfc_conv_descriptor_stride_get (decl, idx);
+      tmp = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type,
+                            nelems, tmp);
+      if (GFC_BYTES_STRIDES_ARRAY_TYPE_P (TREE_TYPE (decl)))
+       tmp = fold_build2_loc (input_location, EXACT_DIV_EXPR,
+                              gfc_array_index_type,
+                              tmp, gfc_conv_descriptor_span_get (decl));
+      return gfc_evaluate_now (tmp, block);
+    }
 }

Reply via email to