[gcc(refs/users/mikael/heads/refactor_descriptor_v291.01)] Suppression set_dtype_if_unallocated

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

commit 43693adb0142b9ce86ad54df82b50edadd9e4ead
Author: Mikael Morin <[email protected]>
Date:   Sun Aug 10 11:03:57 2025 +0200

    Suppression set_dtype_if_unallocated
    
    Extraction gfc_descriptor_set_dtype_if_unallocated
    
    Sauvegarde
    
    Revert partiel
    
    Sauvegarde
    
    Correction indentation
    
    Déplacement gfc_init_static_descriptor

Diff:
---
 gcc/fortran/trans-array.cc      |   2 +-
 gcc/fortran/trans-descriptor.cc |  44 +++++++++++++----
 gcc/fortran/trans-descriptor.h  |   2 +-
 gcc/fortran/trans-expr.cc       | 104 ++++++++++------------------------------
 4 files changed, 64 insertions(+), 88 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 46b5d70bbecf..3cf737e43fb8 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -655,7 +655,7 @@ void
 gfc_trans_static_array_pointer (gfc_symbol * sym)
 {
   gcc_assert (TREE_STATIC (sym->backend_decl));
-  gfc_init_static_descriptor (sym->backend_decl);
+  gfc_init_static_descriptor (sym);
 }
 
 
diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index 52cb8c0162bc..681570919002 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -704,6 +704,42 @@ gfc_build_null_descriptor (tree type)
 }
 
 
+void
+gfc_init_static_descriptor (gfc_symbol *sym)
+{
+  vec<constructor_elt, va_gc> *v = NULL;
+
+  tree descr = sym->backend_decl;
+  tree type = TREE_TYPE (descr);
+
+  gcc_assert (GFC_DESCRIPTOR_TYPE_P (type));
+  tree fields = TYPE_FIELDS (type);
+
+  tree data_field = gfc_advance_chain (fields, DATA_FIELD);
+  CONSTRUCTOR_APPEND_ELT (v, data_field,
+			  fold_convert (TREE_TYPE (data_field),
+					null_pointer_node));
+
+  gfc_array_spec *as;
+  if (sym->ts.type == BT_CLASS)
+    as = CLASS_DATA (sym)->as;
+  else
+    as = sym->as;
+
+  int rank = as ? as->rank : 0;
+  tree dtype_field = gfc_advance_chain (fields, DTYPE_FIELD);
+  tree dtype_value = gfc_get_dtype_rank_type (rank,
+					      gfc_get_element_type (type));
+  CONSTRUCTOR_APPEND_ELT (v, dtype_field,
+			  fold_convert (TREE_TYPE (dtype_field), dtype_value));
+
+  tree constr = build_constructor (type, v);
+  TREE_CONSTANT (constr) = 1;
+
+  DECL_INITIAL (descr) = constr;
+}
+
+
 /* Cleanup those #defines.  */
 
 #undef DATA_FIELD
@@ -961,14 +997,6 @@ gfc_init_absent_descriptor (stmtblock_t *block, tree descr)
 }
 
 
-void
-gfc_init_static_descriptor (tree descr)
-{
-  tree type = TREE_TYPE (descr);
-  DECL_INITIAL (descr) = gfc_build_null_descriptor (type);
-}
-
-
 void
 gfc_nullify_descriptor (stmtblock_t *block, gfc_symbol *sym, gfc_expr *expr,
 			tree descr, tree string_length)
diff --git a/gcc/fortran/trans-descriptor.h b/gcc/fortran/trans-descriptor.h
index a6d4a1a6efa9..03073ff649e3 100644
--- a/gcc/fortran/trans-descriptor.h
+++ b/gcc/fortran/trans-descriptor.h
@@ -70,7 +70,7 @@ void gfc_grow_array (stmtblock_t *, tree, tree);
 void gfc_nullify_descriptor (stmtblock_t *block, tree);
 void gfc_init_descriptor_result (stmtblock_t *block, tree descr);
 void gfc_init_absent_descriptor (stmtblock_t *block, tree descr);
-void gfc_init_static_descriptor (tree descr);
+void gfc_init_static_descriptor (gfc_symbol *);
 tree gfc_create_unallocated_library_result_descriptor (stmtblock_t *, tree,
 						       tree);
 tree gfc_create_null_actual_descriptor (stmtblock_t *, gfc_typespec *,
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 76a5c443c2a0..1bb8289e6f8d 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -5975,50 +5975,6 @@ expr_may_alias_variables (gfc_expr *e, bool array_may_alias)
 }
 
 
-/* A helper function to set the dtype for unallocated or unassociated
-   entities.  */
-
-static void
-set_dtype_for_unallocated (gfc_se *parmse, gfc_expr *e)
-{
-  tree tmp;
-  tree desc;
-  tree cond;
-  tree type;
-  stmtblock_t block;
-
-  /* TODO Figure out how to handle optional dummies.  */
-  if (e && e->expr_type == EXPR_VARIABLE
-      && e->symtree->n.sym->attr.optional)
-    return;
-
-  desc = parmse->expr;
-  if (desc == NULL_TREE)
-    return;
-
-  if (POINTER_TYPE_P (TREE_TYPE (desc)))
-    desc = build_fold_indirect_ref_loc (input_location, desc);
-  if (GFC_CLASS_TYPE_P (TREE_TYPE (desc)))
-    desc = gfc_class_data_get (desc);
-  if (!GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (desc)))
-    return;
-
-  gfc_init_block (&block);
-  tmp = gfc_conv_descriptor_data_get (desc);
-  cond = fold_build2_loc (input_location, EQ_EXPR,
-			  logical_type_node, tmp,
-			  build_int_cst (TREE_TYPE (tmp), 0));
-  type = gfc_get_element_type (TREE_TYPE (desc));
-  gfc_conv_descriptor_dtype_set (&block, desc,
-				 gfc_get_dtype_rank_type (e->rank, type));
-  cond = build3_v (COND_EXPR, cond,
-		   gfc_finish_block (&block),
-		   build_empty_stmt (input_location));
-  gfc_add_expr_to_block (&parmse->pre, cond);
-}
-
-
-
 /* Provide an interface between gfortran array descriptors and the F2018:18.4
    ISO_Fortran_binding array descriptors. */
 
@@ -7835,40 +7791,32 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym,
 	  && (fsym->ts.type == BT_CLASS
 	      ? (CLASS_DATA (fsym)->as
 		 && CLASS_DATA (fsym)->as->type == AS_ASSUMED_RANK)
-	      : (fsym->as && fsym->as->type == AS_ASSUMED_RANK)))
-	{
-	  if (fsym->ts.type == BT_CLASS
-	      ? (CLASS_DATA (fsym)->attr.class_pointer
-		 || CLASS_DATA (fsym)->attr.allocatable)
-	      : (fsym->attr.pointer || fsym->attr.allocatable))
-	    {
-	      /* Unallocated allocatable arrays and unassociated pointer
-		 arrays need their dtype setting if they are argument
-		 associated with assumed rank dummies to set the rank.  */
-	      set_dtype_for_unallocated (&parmse, e);
-	    }
-	  else if (e->expr_type == EXPR_VARIABLE
-		   && e->symtree->n.sym->attr.dummy
-		   && (e->ts.type == BT_CLASS
-		       ? (e->ref && e->ref->next
-			  && e->ref->next->type == REF_ARRAY
-			  && e->ref->next->u.ar.type == AR_FULL
-			  && e->ref->next->u.ar.as->type == AS_ASSUMED_SIZE)
-		       : (e->ref && e->ref->type == REF_ARRAY
-			  && e->ref->u.ar.type == AR_FULL
-			  && e->ref->u.ar.as->type == AS_ASSUMED_SIZE)))
-	    {
-	      /* Assumed-size actual to assumed-rank dummy requires
-		 dim[rank-1].ubound = -1. */
-	      tree minus_one;
-	      tmp = build_fold_indirect_ref_loc (input_location, parmse.expr);
-	      if (fsym->ts.type == BT_CLASS)
-		tmp = gfc_class_data_get (tmp);
-	      minus_one = build_int_cst (gfc_array_index_type, -1);
-	      gfc_conv_descriptor_ubound_set (&parmse.pre, tmp,
-					      gfc_rank_cst[e->rank - 1],
-					      minus_one);
-	    }
+	      : (fsym->as && fsym->as->type == AS_ASSUMED_RANK))
+	  && !(fsym->ts.type == BT_CLASS
+	       ? (CLASS_DATA (fsym)->attr.class_pointer
+		  || CLASS_DATA (fsym)->attr.allocatable)
+	       : (fsym->attr.pointer || fsym->attr.allocatable))
+	  && e->expr_type == EXPR_VARIABLE
+	  && e->symtree->n.sym->attr.dummy
+	  && (e->ts.type == BT_CLASS
+	      ? (e->ref && e->ref->next
+		 && e->ref->next->type == REF_ARRAY
+		 && e->ref->next->u.ar.type == AR_FULL
+		 && e->ref->next->u.ar.as->type == AS_ASSUMED_SIZE)
+	      : (e->ref && e->ref->type == REF_ARRAY
+		 && e->ref->u.ar.type == AR_FULL
+		 && e->ref->u.ar.as->type == AS_ASSUMED_SIZE)))
+	{
+	  /* Assumed-size actual to assumed-rank dummy requires
+	     dim[rank-1].ubound = -1. */
+	  tree minus_one;
+	  tmp = build_fold_indirect_ref_loc (input_location, parmse.expr);
+	  if (fsym->ts.type == BT_CLASS)
+	    tmp = gfc_class_data_get (tmp);
+	  minus_one = build_int_cst (gfc_array_index_type, -1);
+	  gfc_conv_descriptor_ubound_set (&parmse.pre, tmp,
+					  gfc_rank_cst[e->rank - 1],
+					  minus_one);
 	}
 
       /* The case with fsym->attr.optional is that of a user subroutine
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.