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

commit bd3fd914be677aa6b791524822b9eede57af1855
Author: Mikael Morin <mik...@gcc.gnu.org>
Date:   Mon Feb 17 21:28:01 2025 +0100

    Correction régression realloc_on_assign_23.f90

Diff:
---
 gcc/fortran/trans-expr.cc | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 95060af47859..23c82f22c3ef 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -12574,6 +12574,7 @@ gfc_trans_assignment_1 (gfc_expr * expr1, gfc_expr * 
expr2, bool init_flag,
       rhs_caf_attr = gfc_caf_attr (expr2, false, &rhs_refs_comp);
     }
 
+  tree reallocation = NULL_TREE;
   if (lss != gfc_ss_terminator)
     {
       /* The assignment needs scalarization.  */
@@ -12647,9 +12648,7 @@ gfc_trans_assignment_1 (gfc_expr * expr1, gfc_expr * 
expr2, bool init_flag,
        {
          realloc_lhs_warning (expr1->ts.type, true, &expr1->where);
          ompws_flags &= ~OMPWS_SCALARIZER_WS;
-         tmp = gfc_alloc_allocatable_for_assignment (&loop, expr1, expr2);
-         if (tmp != NULL_TREE)
-           gfc_add_expr_to_block (&loop.pre, tmp);
+         reallocation = gfc_alloc_allocatable_for_assignment (&loop, expr1, 
expr2);
        }
 
       for (gfc_ss *s = loop.ss; s != gfc_ss_terminator; s = s->loop_chain)
@@ -12982,6 +12981,9 @@ gfc_trans_assignment_1 (gfc_expr * expr1, gfc_expr * 
expr2, bool init_flag,
       if (maybe_workshare)
        ompws_flags &= ~OMPWS_SCALARIZER_BODY;
 
+      if (reallocation != NULL_TREE)
+       gfc_add_expr_to_block (&loop.code[loop.dimen - 1], reallocation);
+
       /* Generate the copying loops.  */
       gfc_trans_scalarizing_loops (&loop, &body);

Reply via email to