https://gcc.gnu.org/g:7d1f9d040048083f39d7f0a3e16257a4c496638f

commit 7d1f9d040048083f39d7f0a3e16257a4c496638f
Author: Mikael Morin <[email protected]>
Date:   Sun Sep 28 11:02:58 2025 +0200

    Correction régression alloc_comp_basics_7.f90

Diff:
---
 gcc/fortran/class.cc            |  1 +
 gcc/fortran/trans-array.cc      | 18 ++++++++++--------
 gcc/fortran/trans-descriptor.cc |  2 +-
 3 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/gcc/fortran/class.cc b/gcc/fortran/class.cc
index ef714b8e7a7d..6e0704c9e502 100644
--- a/gcc/fortran/class.cc
+++ b/gcc/fortran/class.cc
@@ -2725,6 +2725,7 @@ gfc_find_derived_vtab (gfc_symbol *derived)
                  arg->attr.intent = INTENT_INOUT;
                  arg->attr.dimension = 1;
                  arg->attr.allocatable = 1;
+                 arg->attr.contiguous = 1;
                  arg->as = gfc_get_array_spec();
                  arg->as->type = AS_ASSUMED_SHAPE;
                  arg->as->rank = 1;
diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 4b7e0fab8808..9894cd16fa7c 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -9189,7 +9189,6 @@ structure_alloc_comps (gfc_symbol * der_type, tree decl, 
tree dest,
   tree dcmp;
   tree nelems;
   tree index;
-  tree var;
   tree cdecl;
   tree ctype;
   tree vref, dref;
@@ -9224,9 +9223,6 @@ structure_alloc_comps (gfc_symbol * der_type, tree decl, 
tree dest,
   if (TREE_CODE (decl_type) == ARRAY_TYPE
       || (GFC_DESCRIPTOR_TYPE_P (decl_type) && rank != 0))
     {
-      tmp = gfc_conv_array_data (decl);
-      var = build_fold_indirect_ref_loc (input_location, tmp);
-
       /* Get the number of elements - 1 and set the counter.  */
       if (GFC_DESCRIPTOR_TYPE_P (decl_type))
        {
@@ -9257,13 +9253,19 @@ structure_alloc_comps (gfc_symbol * der_type, tree 
decl, tree dest,
       /* Build the body of the loop.  */
       gfc_init_block (&loopbody);
 
-      vref = gfc_build_array_ref (var, index);
+      gfc_se vse;
+      gfc_init_se (&vse, nullptr);
+      build_array_ref (&vse, decl, nullptr, nullptr, index);
+      vref = vse.expr;
+      gfc_add_block_to_block (&loopbody, &vse.pre);
 
       if (purpose == COPY_ALLOC_COMP || purpose == COPY_ONLY_ALLOC_COMP)
        {
-         tmp = build_fold_indirect_ref_loc (input_location,
-                                            gfc_conv_array_data (dest));
-         dref = gfc_build_array_ref (tmp, index);
+         gfc_se dse;
+         gfc_init_se (&dse, nullptr);
+         build_array_ref (&dse, dest, nullptr, nullptr, index);
+         dref = dse.expr;
+         gfc_add_block_to_block (&loopbody, &dse.pre);
          tmp = structure_alloc_comps (der_type, vref, dref, rank,
                                       COPY_ALLOC_COMP, caf_mode, args,
                                       no_finalization);
diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index cb4a6fbe6b71..16e05f001073 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -2091,7 +2091,7 @@ void
 gfc_set_contiguous_descriptor (stmtblock_t *block, tree desc, tree size,
                               tree data_ptr)
 {
-  gcc_assert (!GFC_BYTES_STRIDES_ARRAY_TYPE_P (desc));
+  gcc_assert (!GFC_BYTES_STRIDES_ARRAY_TYPE_P (TREE_TYPE (desc)));
   gfc_conv_descriptor_dtype_set (block, desc,
                                 gfc_get_dtype_rank_type (1, TREE_TYPE (desc),
                                                          false));

Reply via email to