[gcc(refs/users/mikael/heads/refactor_descriptor_v206.01)] Sauvegarde refactoring

Mikael Morin via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:73d11ee7960f3ed1496684b1de6d6f3494c62306

commit 73d11ee7960f3ed1496684b1de6d6f3494c62306
Author: Mikael Morin <[email protected]>
Date:   Thu Aug 20 20:36:40 2026 +0200

    Sauvegarde refactoring
    
    fortran: array descriptor: Factor scalar descriptor init 1/2 [PR122521]
    
    TODO: FAIL unlimited_polymorphic_{1,32}.f03, intent_out_19.f90, associate_66.f90
    
    -- >8 --
    
    The two functions gfc_set_descriptor_from_scalar and
    gfc_set_descriptor_from_scalar_class have very similar code, except only the
    former has support for coarrays and absent optional variables.  Make
    gfc_set_descriptor_from_scalar_class call it.
    
            PR fortran/122521
    
    gcc/fortran/ChangeLog:
    
            * trans-descriptor.cc (gfc_set_descriptor_from_scalar_class):
            Replace inline code with a call to gfc_set_descriptor_from_scalar.

Diff:
---
 gcc/fortran/trans-descriptor.cc | 33 ++++++++++++++++++++-------------
 1 file changed, 20 insertions(+), 13 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index 383322dbb8b2..743ed60dc8c9 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -847,6 +847,23 @@ gfc_create_null_actual_descriptor (stmtblock_t *block, gfc_typespec *ts,
 }
 
 
+void
+set_descriptor_from_scalar (stmtblock_t *block, tree descr, tree type,
+			    tree scalar, tree cond_presence)
+{
+  gfc_conv_descriptor_dtype_set (block, descr,
+				 gfc_get_dtype_rank_type (0, 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);
+}
+
+
 /* Add code to BLOCK initializing the scalar descriptor DESCR, so that it
    represents the same data as the middle-end scalar pointer expression SCALAR
    corresponding to the front-end scalar expression SCALAR_EXPR.  If
@@ -863,16 +880,7 @@ gfc_set_descriptor_from_scalar (stmtblock_t *block, tree descr,
   tree etype = POINTER_TYPE_P (scalar_type)
 	       ? TREE_TYPE (scalar_type)
 	       : scalar_type;
-  gfc_conv_descriptor_dtype_set (block, descr,
-				 gfc_get_dtype_rank_type (0, etype));
-  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);
+  set_descriptor_from_scalar (block, descr, etype, scalar, cond_presence);
 }
 
 
@@ -973,14 +981,13 @@ gfc_set_descriptor_from_scalar_class (stmtblock_t *block, tree descr,
   tree class_type;
   if (!is_polymorphic_scalar_expr (scalar, &class_type))
     gcc_unreachable ();
-  gfc_conv_descriptor_dtype_set (block, descr,
-				 gfc_get_dtype_rank_type (0, class_type));
+
   tree tmp = scalar;
   if (is_class_container_type (TREE_TYPE (tmp)))
     tmp = gfc_class_data_get (tmp);
   gcc_assert (POINTER_TYPE_P (TREE_TYPE (tmp)));
 
-  gfc_conv_descriptor_data_set (block, descr, tmp);
+  set_descriptor_from_scalar (block, descr, class_type, tmp, NULL_TREE);
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.