https://gcc.gnu.org/g:20f2e28a0de001cce1518fb847eb6a58e6521e9a

commit 20f2e28a0de001cce1518fb847eb6a58e6521e9a
Author: Mikael Morin <mik...@gcc.gnu.org>
Date:   Fri Apr 25 11:46:54 2025 +0200

    Correction régression auto_char_dummy_array_3

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

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 0b0fcb36c8ea..b6688af5953d 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -6266,15 +6266,6 @@ gfc_trans_auto_array_allocation (tree decl, gfc_symbol * 
sym,
        }
     }
 
-  if (onstack)
-    {
-      gfc_add_init_cleanup (block, gfc_finish_block (&init), NULL_TREE,
-                           back);
-      return;
-    }
-
-  type = TREE_TYPE (type);
-
   gcc_assert (!sym->attr.use_assoc);
   gcc_assert (!sym->module);
 
@@ -6282,17 +6273,23 @@ gfc_trans_auto_array_allocation (tree decl, gfc_symbol 
* sym,
       && !INTEGER_CST_P (sym->ts.u.cl->backend_decl))
     gfc_conv_string_length (sym->ts.u.cl, NULL, &init);
 
+  if (!onstack)
+    type = TREE_TYPE (type);
+
   size = gfc_trans_array_bounds (type, sym, &offset, &init);
 
+  /* Set offset of the array.  */
+  if (VAR_P (GFC_TYPE_ARRAY_OFFSET (type)))
+    gfc_add_modify (&init, GFC_TYPE_ARRAY_OFFSET (type), offset);
+
   /* Don't actually allocate space for Cray Pointees.  */
-  if (sym->attr.cray_pointee)
+  if (onstack || sym->attr.cray_pointee)
     {
-      if (VAR_P (GFC_TYPE_ARRAY_OFFSET (type)))
-       gfc_add_modify (&init, GFC_TYPE_ARRAY_OFFSET (type), offset);
-
-      gfc_add_init_cleanup (block, gfc_finish_block (&init), NULL_TREE);
+      gfc_add_init_cleanup (block, gfc_finish_block (&init), NULL_TREE,
+                           onstack && back);
       return;
     }
+
   if (sym->attr.omp_allocate)
     {
       size = gfc_evaluate_now (size, &init);
@@ -6322,10 +6319,6 @@ gfc_trans_auto_array_allocation (tree decl, gfc_symbol * 
sym,
       space = NULL_TREE;
     }
 
-  /* Set offset of the array.  */
-  if (VAR_P (GFC_TYPE_ARRAY_OFFSET (type)))
-    gfc_add_modify (&init, GFC_TYPE_ARRAY_OFFSET (type), offset);
-
   /* Automatic arrays should not have initializers.  */
   gcc_assert (!sym->value);

Reply via email to