[gcc(refs/users/mikael/heads/refactor_descriptor_v206.01)] Extraction gfc_set_descriptor_from_scalar

Mikael Morin via Gcc-cvs <[email protected]> Thu, 6 Aug 2026 12:13:06 +0000 (GMT)
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:fd325c3880945fb05c49f827f5454da047f113f3

commit fd325c3880945fb05c49f827f5454da047f113f3
Author: Mikael Morin <[email protected]>
Date:   Thu Aug 6 11:52:49 2026 +0200

    Extraction gfc_set_descriptor_from_scalar
    
    Correction artefact conflit rebase
    
    Déplacement gfc_set_descriptor_from_scalar

Diff:
---
 gcc/fortran/trans-descriptor.cc | 21 +++++++++++++++++++++
 gcc/fortran/trans-descriptor.h  |  2 ++
 gcc/fortran/trans-expr.cc       | 17 ++---------------
 3 files changed, 25 insertions(+), 15 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index cca75b45ec0b..6996dbf63e90 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -1007,6 +1007,27 @@ gfc_grow_array (stmtblock_t * pblock, tree desc, tree extra)
 }
 
 
+void
+gfc_set_descriptor_from_scalar (stmtblock_t *block, tree descr,
+				tree scalar, gfc_expr *scalar_expr,
+				tree cond_presence)
+{
+  tree type;
+  type = gfc_get_scalar_to_descriptor_type (TREE_TYPE (scalar),
+					    gfc_expr_attr (scalar_expr));
+  gfc_conv_descriptor_dtype_set (block, descr,
+				 gfc_get_dtype (type));
+  gfc_copy_coarray_desc_part (block, descr, scalar);
+  if (cond_presence)
+    scalar = build3_loc (input_location, COND_EXPR,
+			 TREE_TYPE (scalar),
+			 cond_presence, scalar,
+			 fold_convert (TREE_TYPE (scalar),
+				       null_pointer_node));
+  gfc_conv_descriptor_data_set (block, descr, scalar);
+}
+
+
 void
 gfc_set_descriptor_from_scalar_class (stmtblock_t *block, tree descr,
 				      tree scalar, gfc_expr *scalar_expr)
diff --git a/gcc/fortran/trans-descriptor.h b/gcc/fortran/trans-descriptor.h
index fb16519acf5a..fb8b692ab09c 100644
--- a/gcc/fortran/trans-descriptor.h
+++ b/gcc/fortran/trans-descriptor.h
@@ -86,5 +86,7 @@ void gfc_grow_array (stmtblock_t *, tree, tree);
 void gfc_copy_coarray_desc_part (stmtblock_t *, tree, tree);
 
 void gfc_set_descriptor_from_scalar_class (stmtblock_t *, tree, tree, gfc_expr *);
+void gfc_set_descriptor_from_scalar (stmtblock_t *, tree, tree, gfc_expr *,
+				     tree);
 
 #endif /* GFC_TRANS_DESCRIPTOR_H */
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 0af85127e364..71e77fc08f83 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -897,21 +897,8 @@ gfc_conv_derived_to_class (gfc_se *parmse, gfc_expr *e, gfc_symbol *fsym,
 
 	  /* Scalar to an assumed-rank array.  */
 	  if (fsym->ts.u.derived->components->as)
-	    {
-	      tree type;
-	      type = gfc_get_scalar_to_descriptor_type (TREE_TYPE (parmse->expr),
-							gfc_expr_attr (e));
-	      gfc_conv_descriptor_dtype_set (&parmse->pre, ctree,
-					     gfc_get_dtype (type));
-	      gfc_copy_coarray_desc_part (&parmse->pre, ctree, parmse->expr);
-	      if (optional)
-		parmse->expr = build3_loc (input_location, COND_EXPR,
-					   TREE_TYPE (parmse->expr),
-					   cond_optional, parmse->expr,
-					   fold_convert (TREE_TYPE (parmse->expr),
-							 null_pointer_node));
-	      gfc_conv_descriptor_data_set (&parmse->pre, ctree, parmse->expr);
-	    }
+	    gfc_set_descriptor_from_scalar (&parmse->pre, ctree,
+					    parmse->expr, e, cond_optional);
           else
 	    {
 	      tmp = fold_convert (TREE_TYPE (ctree), parmse->expr);