[gcc(refs/users/mikael/heads/refactor_descriptor_v291.01)] Refactor gfc_init_descriptor_variable

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

commit ce4cf381e8e212cb733cc4436f1401bbc343badd
Author: Mikael Morin <[email protected]>
Date:   Wed Aug 6 21:29:10 2025 +0200

    Refactor gfc_init_descriptor_variable

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

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index 23c74dded4f6..a703efdeab3d 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -908,13 +908,14 @@ gfc_init_static_descriptor (tree descr)
 
 
 void
-gfc_init_descriptor_variable (stmtblock_t *block, gfc_symbol *sym, tree descr)
+gfc_init_descriptor_variable (stmtblock_t *block, gfc_symbol *sym, gfc_expr *expr, tree descr)
 {
   symbol_attribute attr = gfc_symbol_attr (sym);
 
   /* NULLIFY the data pointer for non-saved allocatables, or for non-saved
      pointers when -fcheck=pointer is specified.  */
   if (attr.allocatable
+      || attr.optional
       || (attr.pointer && (gfc_option.rtcheck & GFC_RTCHECK_POINTER)))
     {
       gfc_conv_descriptor_data_set (block, descr, null_pointer_node);
@@ -928,8 +929,24 @@ gfc_init_descriptor_variable (stmtblock_t *block, gfc_symbol *sym, tree descr)
   else
     as = sym->as;
 
-  gcc_assert (as && as->rank >= 0);
+  int rank;
+  if (as == nullptr)
+    rank = 0;
+  else if (as->type != AS_ASSUMED_RANK)
+    rank = as->rank;
+  else if (expr)
+    rank = expr->rank;
+  else
+    rank = -1;
+
   tree etype = gfc_get_element_type (TREE_TYPE (descr));
   gfc_conv_descriptor_dtype_set (block, descr,
-				 gfc_get_dtype_rank_type (as->rank, etype));
+				 gfc_get_dtype_rank_type (rank, etype));
+}
+
+
+void
+gfc_init_descriptor_variable (stmtblock_t *block, gfc_symbol *sym, tree descr)
+{
+  return gfc_init_descriptor_variable (block, sym, nullptr, descr);
 }
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.