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

commit cb010cf8300d1cec95ba0a49c5192afb4d8b6838
Author: Mikael Morin <[email protected]>
Date:   Thu Nov 19 20:43:11 2026 +0100

    Sauvegarde modifs
    
    Correction erreur compil'

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

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index fb39df19ce28..8968ebecb139 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -8151,6 +8151,32 @@ is_explicit_coarray (gfc_expr *expr)
   return cas && cas->cotype == AS_EXPLICIT;
 }
 
+
+tree
+get_array_descriptor_ref (tree expr)
+{
+  if (expr == NULL_TREE)
+    return NULL_TREE;
+
+  if (POINTER_TYPE_P (TREE_TYPE (expr)))
+    expr = build_fold_indirect_ref_loc (input_location, expr);
+
+  if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (expr)))
+    return expr;
+
+  if (GFC_CLASS_TYPE_P (TREE_TYPE (expr)))
+    return get_array_descriptor_ref (gfc_class_data_get (expr));
+
+  tree decl = get_main_decl (expr);
+  if (decl
+      && DECL_P (decl)
+      && DECL_LANG_SPECIFIC (decl))
+    return get_array_descriptor_ref (GFC_DECL_SAVED_DESCRIPTOR (decl));
+
+  return NULL_TREE;
+}
+
+
 /* Convert an array for passing as an actual argument.  Expressions and
    vector subscripts are evaluated and stored in a temporary, which is then
    passed.  For whole arrays the descriptor is passed.  For array sections
@@ -8732,25 +8758,14 @@ gfc_conv_expr_descriptor (gfc_se *se, gfc_expr *expr)
        dtype = gfc_get_dtype (parmtype);
       gfc_conv_descriptor_dtype_set (&loop.pre, parm, dtype);
 
+      /* For polymorphic references, try to copy the element length from the
+         original descriptor if we find it.  */
       if (expr->ts.type == BT_CLASS)
-       {
-         /* Try to copy the element length from the original descriptor if we
-            find it.  */
-         tree orig_desc = desc;
-         if (!GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (orig_desc)))
-           {
-             tree decl = get_main_decl (orig_desc);
-             if (decl
-                 && DECL_P (decl)
-                 && DECL_LANG_SPECIFIC (decl))
-               orig_desc = GFC_DECL_SAVED_DESCRIPTOR (decl);
-           }
-         if (orig_desc && GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (orig_desc)))
-           {
-             tree elem_len = gfc_conv_descriptor_elem_len_get (orig_desc);
-             gfc_conv_descriptor_elem_len_set (&loop.pre, parm, elem_len);
-           }
-       }
+       if (tree orig_desc = get_array_descriptor_ref (desc))
+         {
+           tree elem_len = gfc_conv_descriptor_elem_len_get (orig_desc);
+           gfc_conv_descriptor_elem_len_set (&loop.pre, parm, elem_len);
+         }
 
       /* The 1st element in the section.  */
       base = gfc_index_zero_node;

Reply via email to