https://gcc.gnu.org/g:94c59e9e6bd1f0219a9935e555aca5e60925e6ae

commit 94c59e9e6bd1f0219a9935e555aca5e60925e6ae
Author: Mikael Morin <mik...@gcc.gnu.org>
Date:   Sun May 18 15:37:02 2025 +0200

    Correction régression allocate_with_source_11

Diff:
---
 gcc/fortran/trans-expr.cc | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 640b9ccc2227..323bec17093c 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -1318,10 +1318,23 @@ gfc_conv_class_to_class (gfc_se *parmse, gfc_expr *e, 
gfc_typespec class_ts,
     }
   else
     {
-      if (TREE_TYPE (parmse->expr) != TREE_TYPE (ctree))
-       parmse->expr = fold_build1_loc (input_location, VIEW_CONVERT_EXPR,
-                                       TREE_TYPE (ctree), parmse->expr);
-      gfc_add_modify (&block, ctree, parmse->expr);
+      tree val = parmse->expr;
+
+      if (TREE_CODE (TREE_TYPE (val)) == POINTER_TYPE)
+       val = build_fold_indirect_ref_loc (input_location, val);
+
+      if (GFC_CLASS_TYPE_P (TREE_TYPE (val)))
+       val = gfc_class_data_get (val);
+
+      if (TREE_CODE (TREE_TYPE (ctree)) == POINTER_TYPE
+         && TREE_CODE (TREE_TYPE (val)) != POINTER_TYPE)
+       val = gfc_build_addr_expr (NULL_TREE, val);
+
+      if (TREE_TYPE (val) != TREE_TYPE (ctree))
+       val = fold_build1_loc (input_location, VIEW_CONVERT_EXPR,
+                              TREE_TYPE (ctree), val);
+
+      gfc_add_modify (&block, ctree, val);
     }
 
   /* Return the data component, except in the case of scalarized array

Reply via email to