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

commit e407c503b69f44aebad803f1eccdaaa1b910fa19
Author: Mikael Morin <[email protected]>
Date:   Sat Oct 17 14:12:18 2026 +0200

    Correction allocate_with_mold_7

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

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index a77aa3604fc6..634aec0b1376 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -6466,6 +6466,34 @@ gfc_array_init_size (tree descriptor, int rank, int 
corank, tree * poffset,
 }
 
 
+/* Retrieve the last ref from the chain.  This routine is specific to
+   gfc_array_allocate ()'s needs.  */
+
+static bool
+retrieve_last_ref (gfc_ref **ref_in, gfc_ref **prev_ref_in)
+{
+  gfc_ref *ref, *prev_ref;
+
+  ref = *ref_in;
+  /* Prevent warnings for uninitialized variables.  */
+  prev_ref = *prev_ref_in;
+  while (ref && ref->next != nullptr)
+    {
+      gcc_assert (ref->type != REF_ARRAY || ref->u.ar.type == AR_ELEMENT
+                 || (ref->u.ar.dimen == 0 && ref->u.ar.codimen > 0));
+      prev_ref = ref;
+      ref = ref->next;
+    }
+
+  if (ref == NULL || ref->type != REF_ARRAY)
+    return false;
+
+  *ref_in = ref;
+  *prev_ref_in = prev_ref;
+  return true;
+}
+
+
 /* Retrieve the last ref from the chain.  This routine is specific to
    gfc_array_allocate ()'s needs.  */
 
@@ -6530,7 +6558,7 @@ gfc_array_allocate (gfc_se * se, gfc_expr * expr, tree 
status, tree errmsg,
   ref = expr->ref;
 
   /* Find the last reference in the chain.  */
-  if (!retrieve_array_ref (&ref, &prev_ref))
+  if (!retrieve_last_ref (&ref, &prev_ref))
     return false;
 
   /* Take the allocatable and coarray properties solely from the expr-ref's

Reply via email to