https://gcc.gnu.org/g:07216b7ca41fe224e3c8e974dbcaff4af5eced23

commit 07216b7ca41fe224e3c8e974dbcaff4af5eced23
Author: Mikael Morin <[email protected]>
Date:   Sat Oct 17 13:59:19 2026 +0200

    Modif retrieve_last_ref

Diff:
---
 gcc/fortran/trans-array.cc | 16 +++++++++-------
 gcc/fortran/trans-stmt.cc  |  2 ++
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index df65f82be80b..a77aa3604fc6 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -6469,18 +6469,20 @@ 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.  */
 
-bool
-retrieve_last_ref (gfc_ref **ref_in, gfc_ref **prev_ref_in)
+static bool
+retrieve_array_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 != NULL)
+  while (ref
+        && (ref->type != REF_ARRAY
+            || ref->u.ar.type == AR_ELEMENT
+            || (ref->u.ar.dimen == 0
+                && ref->u.ar.codimen > 0)))
     {
-      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;
     }
@@ -6528,7 +6530,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_last_ref (&ref, &prev_ref))
+  if (!retrieve_array_ref (&ref, &prev_ref))
     return false;
 
   /* Take the allocatable and coarray properties solely from the expr-ref's
@@ -6572,7 +6574,7 @@ gfc_array_allocate (gfc_se * se, gfc_expr * expr, tree 
status, tree errmsg,
       ref = expr3->ref;
 
       /* Find the last reference in the chain.  */
-      if (!retrieve_last_ref (&ref, &prev_ref))
+      if (!retrieve_array_ref (&ref, &prev_ref))
        {
          if (expr3->expr_type == EXPR_FUNCTION
              && gfc_expr_attr (expr3).dimension)
diff --git a/gcc/fortran/trans-stmt.cc b/gcc/fortran/trans-stmt.cc
index cfde1f15a14f..e59708903c1e 100644
--- a/gcc/fortran/trans-stmt.cc
+++ b/gcc/fortran/trans-stmt.cc
@@ -6727,6 +6727,7 @@ gfc_trans_allocate (gfc_code * code, gfc_omp_namelist 
*omp_allocate)
        vtab_needed = (al->expr->ts.type == BT_CLASS);
 
       gfc_init_se (&se, NULL);
+#if 0
       /* When expr3 is a variable, i.e., a very simple expression, then
         convert it once here.  If one has a source expression that has
         substring references, part-refs, or %re/%im inquiries, wrap the
@@ -6734,6 +6735,7 @@ gfc_trans_allocate (gfc_code * code, gfc_omp_namelist 
*omp_allocate)
       if (code->expr3->expr_type == EXPR_VARIABLE
          && is_subobject_ref (code->expr3))
        code->expr3 = gfc_get_parentheses (code->expr3);
+#endif
 
       if (code->expr3->expr_type == EXPR_VARIABLE
          || code->expr3->expr_type == EXPR_ARRAY

Reply via email to