[gcc(refs/users/mikael/heads/refactor_descriptor_v206.01)] fortran: array descriptor: Simplify scalar dtype initialization [PR122521]

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

commit f2ac211cfc5377b046f6eb84b8986941bd812be0
Author: Mikael Morin <[email protected]>
Date:   Mon Aug 10 22:20:43 2026 +0200

    fortran: array descriptor: Simplify scalar dtype initialization [PR122521]
    
    Fortran-tested on aarch64-unknown-linux-gnu.  OK for mainline?
    
    -- >8 --
    
    The function gfc_set_descriptor_from_scalar creates a new scalar descriptor
    type that is only used as argument to gfc_get_dtype, to get the dtype
    initialization value.  gfc_get_dtype extracts two pieces of information from
    that descriptor type: the rank, and the element type.  As the rank is known
    to be zero, and the element type was part of the input to create the
    descriptor type, we can avoid the roundtrip through the descriptor type
    creation, and use directly the zero rank and the element type.  This change
    does that.  It permits the removal of one argument from
    gfc_set_descriptor_from_scalar.
    
            PR fortran/122521
    
    gcc/fortran/ChangeLog:
    
            * trans-descriptor.h (gfc_set_descriptor_from_scalar,
            gfc_set_descriptor_from_scalar_class): Remove expression argument.
            * trans-descriptor.cc (gfc_set_descriptor_from_scalar_class):
            (gfc_set_descriptor_from_scalar): Ditto.
            Use gfc_get_dtype_rank_type instead of gfc_get_dtype.  Remove scalar
            descriptor type creation.
            * trans-expr.cc (gfc_conv_derived_to_class,
            gfc_conv_class_to_class): Update callers.

Diff:
---
 gcc/fortran/trans-descriptor.cc | 15 ++++++---------
 gcc/fortran/trans-descriptor.h  |  5 ++---
 gcc/fortran/trans-expr.cc       |  4 ++--
 3 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index f12e4733c6fd..6ec9593c3b7b 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -846,19 +846,17 @@ gfc_create_null_actual_descriptor (stmtblock_t *block, gfc_typespec *ts,
 
 
 void
-gfc_set_descriptor_from_scalar (stmtblock_t *block, tree descr,
-				tree scalar, gfc_expr *scalar_expr,
+gfc_set_descriptor_from_scalar (stmtblock_t *block, tree descr, tree scalar,
 				tree cond_presence, tree caf_token)
 {
   if (flag_coarray == GFC_FCOARRAY_LIB && caf_token)
     gfc_conv_descriptor_token_set (block, descr, caf_token);
 
-  tree type = gfc_get_scalar_to_descriptor_type (TREE_TYPE (scalar),
-						 gfc_expr_attr (scalar_expr));
+  tree scalar_type = TREE_TYPE (scalar);
   gfc_conv_descriptor_dtype_set (block, descr,
-				 gfc_get_dtype (type));
+				 gfc_get_dtype_rank_type (0, scalar_type));
   gfc_copy_coarray_desc_part (block, descr, scalar);
-  if (!POINTER_TYPE_P (TREE_TYPE (scalar)))
+  if (!POINTER_TYPE_P (scalar_type))
     scalar = gfc_build_addr_expr (NULL_TREE, scalar);
   if (cond_presence)
     scalar = build3_loc (input_location, COND_EXPR,
@@ -889,11 +887,10 @@ gfc_set_descriptor_from_scalar (stmtblock_t *block, tree descr, tree scalar)
 
 void
 gfc_set_descriptor_from_scalar_class (stmtblock_t *block, tree descr,
-				      tree scalar, gfc_expr *scalar_expr)
+				      tree scalar)
 {
   tree tmp = gfc_class_data_get (scalar);
-  gfc_set_descriptor_from_scalar (block, descr, tmp, scalar_expr, NULL_TREE,
-				  NULL_TREE);
+  gfc_set_descriptor_from_scalar (block, descr, tmp, NULL_TREE, NULL_TREE);
 }
 
 
diff --git a/gcc/fortran/trans-descriptor.h b/gcc/fortran/trans-descriptor.h
index 2154411602da..9ccae12e11c6 100644
--- a/gcc/fortran/trans-descriptor.h
+++ b/gcc/fortran/trans-descriptor.h
@@ -73,10 +73,9 @@ tree gfc_create_unallocated_library_result_descriptor (stmtblock_t *, tree,
 tree gfc_create_null_actual_descriptor (stmtblock_t *, gfc_typespec *,
 					symbol_attribute, int);
 
-void gfc_set_descriptor_from_scalar (stmtblock_t *, tree, tree, gfc_expr *,
-				     tree, tree);
+void gfc_set_descriptor_from_scalar (stmtblock_t *, tree, tree, tree, tree);
 void gfc_set_descriptor_from_scalar (stmtblock_t *, tree, tree);
-void gfc_set_descriptor_from_scalar_class (stmtblock_t *, tree, tree, gfc_expr *);
+void gfc_set_descriptor_from_scalar_class (stmtblock_t *, tree, tree);
 
 tree gfc_conv_descriptor_size (tree, int);
 tree gfc_conv_descriptor_cosize (tree, int, int);
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index f0dd56119bde..466303cb2d94 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -896,7 +896,7 @@ 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)
 	    gfc_set_descriptor_from_scalar (&parmse->pre, ctree, parmse->expr,
-					    e, cond_optional, caf_token);
+					    cond_optional, caf_token);
           else
 	    {
 	      tmp = fold_convert (TREE_TYPE (ctree), parmse->expr);
@@ -1324,7 +1324,7 @@ gfc_conv_class_to_class (gfc_se *parmse, gfc_expr *e, gfc_typespec class_ts,
       && e->rank != class_ts.u.derived->components->as->rank)
     {
       if (e->rank == 0)
-	gfc_set_descriptor_from_scalar_class (&block, ctree, parmse->expr, e);
+	gfc_set_descriptor_from_scalar_class (&block, ctree, parmse->expr);
       else
 	gfc_class_array_data_assign (&block, ctree, parmse->expr, false);
     }
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.