[gcc(refs/users/mikael/heads/refactor_descriptor_v206.01)] fortran: array descriptor: Factor scalar descriptor init 1/2 [PR122521]

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

commit 6ba6a964b688b1a5bdf581e972a821f278743c96
Author: Mikael Morin <[email protected]>
Date:   Mon Aug 10 21:44:32 2026 +0200

    fortran: array descriptor: Factor scalar descriptor init 1/2 [PR122521]
    
    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, whereas only
    the latter has code to take the address if the scalar value isn't
    pointer-typed.  Add the missing address taking to
    gfc_set_descriptor_from_scalar and make gfc_set_descriptor_from_scalar_class
    call it.
    
            PR fortran/122521
    
    gcc/fortran/ChangeLog:
    
            * trans-descriptor.cc (gfc_set_descriptor_from_scalar): Take the
            address of the value if it's not a pointer.
            (gfc_set_descriptor_from_scalar_class): Replace inline code with a
            call to gfc_set_descriptor_from_scalar.

Diff:
---
 gcc/fortran/trans-descriptor.cc | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index 5c8cf4ee07f5..f12e4733c6fd 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -27,6 +27,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "trans-const.h"
 #include "trans-types.h"
 #include "trans-array.h"
+#include "trans-descriptor.h"
 
 
 /* Array descriptor low level access routines.
@@ -857,6 +858,8 @@ gfc_set_descriptor_from_scalar (stmtblock_t *block, tree descr,
   gfc_conv_descriptor_dtype_set (block, descr,
 				 gfc_get_dtype (type));
   gfc_copy_coarray_desc_part (block, descr, scalar);
+  if (!POINTER_TYPE_P (TREE_TYPE (scalar)))
+    scalar = gfc_build_addr_expr (NULL_TREE, scalar);
   if (cond_presence)
     scalar = build3_loc (input_location, COND_EXPR,
 			 TREE_TYPE (scalar),
@@ -888,16 +891,9 @@ void
 gfc_set_descriptor_from_scalar_class (stmtblock_t *block, tree descr,
 				      tree scalar, gfc_expr *scalar_expr)
 {
-  tree 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));
-
   tree tmp = gfc_class_data_get (scalar);
-  if (!POINTER_TYPE_P (TREE_TYPE (tmp)))
-    tmp = gfc_build_addr_expr (NULL_TREE, tmp);
-
-  gfc_conv_descriptor_data_set (block, descr, tmp);
+  gfc_set_descriptor_from_scalar (block, descr, tmp, scalar_expr, NULL_TREE,
+				  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.