[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Refactoring gfc_get_scalar_to_descriptor_type

Mikael Morin mikael@gcc.gnu.org
Fri Sep 19 20:00:27 GMT 2025


https://gcc.gnu.org/g:8054bf4b9e6d86cfc82a23266fb8380894186b47

commit 8054bf4b9e6d86cfc82a23266fb8380894186b47
Author: Mikael Morin <mikael@gcc.gnu.org>
Date:   Thu Aug 7 14:10:54 2025 +0200

    Refactoring gfc_get_scalar_to_descriptor_type

Diff:
---
 gcc/fortran/trans-expr.cc  | 31 +++++--------------------------
 gcc/fortran/trans-types.cc | 22 ++++++++++++++++++++++
 gcc/fortran/trans-types.h  |  1 +
 3 files changed, 28 insertions(+), 26 deletions(-)

diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index aa702a364d1b..7b25c534cc1d 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -91,33 +91,12 @@ gfc_get_character_len_in_bytes (tree type)
 }
 
 
-/* Convert a scalar to an array descriptor. To be used for assumed-rank
-   arrays.  */
-
-static tree
-get_scalar_to_descriptor_type (tree scalar, symbol_attribute attr)
-{
-  enum gfc_array_kind akind;
-
-  if (attr.pointer)
-    akind = GFC_ARRAY_POINTER_CONT;
-  else if (attr.allocatable)
-    akind = GFC_ARRAY_ALLOCATABLE;
-  else
-    akind = GFC_ARRAY_ASSUMED_SHAPE_CONT;
-
-  if (POINTER_TYPE_P (TREE_TYPE (scalar)))
-    scalar = TREE_TYPE (scalar);
-  return gfc_get_array_type_bounds (TREE_TYPE (scalar), 0, 0, NULL, NULL, 1,
-				    akind, !(attr.pointer || attr.target));
-}
-
 tree
 gfc_conv_scalar_to_descriptor (gfc_se *se, tree scalar, symbol_attribute attr)
 {
   tree desc, type, etype;
 
-  type = get_scalar_to_descriptor_type (scalar, attr);
+  type = gfc_get_scalar_to_descriptor_type (scalar, attr);
   etype = TREE_TYPE (scalar);
   desc = gfc_create_var (type, "desc");
   DECL_ARTIFICIAL (desc) = 1;
@@ -924,8 +903,8 @@ gfc_conv_derived_to_class (gfc_se *parmse, gfc_expr *e, gfc_symbol *fsym,
 	  if (fsym->ts.u.derived->components->as)
 	    {
 	      tree type;
-	      type = get_scalar_to_descriptor_type (parmse->expr,
-						    gfc_expr_attr (e));
+	      type = gfc_get_scalar_to_descriptor_type (parmse->expr,
+							gfc_expr_attr (e));
 	      gfc_conv_descriptor_dtype_set (&parmse->pre, ctree,
 					     gfc_get_dtype (type));
 	      if (optional)
@@ -1333,8 +1312,8 @@ gfc_conv_class_to_class (gfc_se *parmse, gfc_expr *e, gfc_typespec class_ts,
     {
       if (e->rank == 0)
 	{
-	  tree type = get_scalar_to_descriptor_type (parmse->expr,
-						     gfc_expr_attr (e));
+	  tree type = gfc_get_scalar_to_descriptor_type (parmse->expr,
+							 gfc_expr_attr (e));
 	  gfc_conv_descriptor_dtype_set (&block, ctree,
 					 gfc_get_dtype (type));
 
diff --git a/gcc/fortran/trans-types.cc b/gcc/fortran/trans-types.cc
index 6b85fe3da67d..e0eed7da7fe3 100644
--- a/gcc/fortran/trans-types.cc
+++ b/gcc/fortran/trans-types.cc
@@ -2163,6 +2163,28 @@ gfc_get_array_type_bounds (tree etype, int dimen, int codimen, tree * lbound,
   return fat_type;
 }
 
+/* Convert a scalar to an array descriptor. To be used for assumed-rank
+   arrays.  */
+
+tree
+gfc_get_scalar_to_descriptor_type (tree scalar, symbol_attribute attr)
+{
+  enum gfc_array_kind akind;
+
+  if (attr.pointer)
+    akind = GFC_ARRAY_POINTER_CONT;
+  else if (attr.allocatable)
+    akind = GFC_ARRAY_ALLOCATABLE;
+  else
+    akind = GFC_ARRAY_ASSUMED_SHAPE_CONT;
+
+  if (POINTER_TYPE_P (TREE_TYPE (scalar)))
+    scalar = TREE_TYPE (scalar);
+  return gfc_get_array_type_bounds (TREE_TYPE (scalar), 0, 0, NULL, NULL, 1,
+				    akind, !(attr.pointer || attr.target));
+}
+
+
 /* Build a pointer type. This function is called from gfc_sym_type().  */
 
 static tree
diff --git a/gcc/fortran/trans-types.h b/gcc/fortran/trans-types.h
index dc75cd82a841..c9090e5a625c 100644
--- a/gcc/fortran/trans-types.h
+++ b/gcc/fortran/trans-types.h
@@ -102,6 +102,7 @@ tree gfc_get_element_type (tree);
 tree gfc_get_array_type_bounds (tree, int, int, tree *, tree *, int,
 				enum gfc_array_kind, bool);
 tree gfc_get_nodesc_array_type (tree, gfc_array_spec *, gfc_packed, bool);
+tree gfc_get_scalar_to_descriptor_type (tree, symbol_attribute);
 
 /* Add a field of given name and type to a UNION_TYPE or RECORD_TYPE.  */
 tree gfc_add_field_to_struct (tree, tree, tree, tree **);


More information about the Gcc-cvs mailing list