https://gcc.gnu.org/g:75d764c5a8caf35b58263faade53cf9ff92fbc45

commit 75d764c5a8caf35b58263faade53cf9ff92fbc45
Author: Mikael Morin <[email protected]>
Date:   Wed Sep 16 16:50:28 2026 +0200

    Sauvegarde modifs

Diff:
---
 gcc/fortran/symbol.cc      |  1 -
 gcc/fortran/trans-array.cc | 17 ++++++++++++++---
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/gcc/fortran/symbol.cc b/gcc/fortran/symbol.cc
index f4536cb2fa9a..f79dac2597f8 100644
--- a/gcc/fortran/symbol.cc
+++ b/gcc/fortran/symbol.cc
@@ -5720,7 +5720,6 @@ gfc_dummy_requires_direct_arg (gfc_symbol *sym)
         && !sym->attr.pointer
         && !sym->attr.allocatable
         && sym->ts.type != BT_CLASS
-        && sym->ts.type != BT_ASSUMED
         && sym->as
         && (sym->as->type == AS_ASSUMED_SHAPE
             || sym->as->type == AS_ASSUMED_RANK);
diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index a4b151e5e370..d4ee95e5e321 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -8647,9 +8647,7 @@ gfc_conv_expr_descriptor (gfc_se *se, gfc_expr *expr)
          the offsets because all elements are within the array data.  */
 
       /* Set the dtype.  */
-      if (se->unlimited_polymorphic
-         || (se->direct_byref
-             && (se->class_container || se->class_vptr)))
+      if (se->unlimited_polymorphic)
        dtype = gfc_get_dtype (TREE_TYPE (desc), &loop.dimen);
       else if (expr->ts.type == BT_ASSUMED)
        {
@@ -8660,6 +8658,19 @@ gfc_conv_expr_descriptor (gfc_se *se, gfc_expr *expr)
            tmp2 = build_fold_indirect_ref_loc (input_location, tmp2);
          dtype = gfc_conv_descriptor_dtype_get (tmp2);
        }
+      /* If we are pointer-assigning to a polymorphic pointer, don't guess
+        the dtype from the lhs.  */
+      else if (se->direct_byref
+              && (se->class_container || se->class_vptr))
+       {
+         if (info && info->ref && info->ref->next)
+           {
+             tree t = gfc_typenode_for_spec (&expr->ts);
+             dtype = gfc_get_dtype_rank_type (loop.dimen, t);
+           }
+         else
+           dtype = gfc_get_dtype (TREE_TYPE (desc), &loop.dimen);
+       }
       else
        dtype = gfc_get_dtype (parmtype);
       gfc_conv_descriptor_dtype_set (&loop.pre, parm, dtype);

Reply via email to