[gcc r17-2520] Showing ALLOCATE typespecs and walking character lengths in code walker.

Thomas Koenig via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:637112b62a20d0354f58b2401e40453513389016

commit r17-2520-g637112b62a20d0354f58b2401e40453513389016
Author: Thomas Koenig <[email protected]>
Date:   Sun Jul 19 16:17:28 2026 +0200

    Showing ALLOCATE typespecs and walking character lengths in code walker.
    
    This dumps the typespec of an ALLOCATE statement and also walks the charlen
    of a character espression and an array if present.
    
    gcc/fortran/ChangeLog:
    
            * dump-parse-tree.cc (show_code_node): Show typespec for
            ALLOCATE if present.
            * frontend-passes.cc (gfc_expr_walker): Walk the character
            typespec length for array expressions.
            (gfc_code_walker): Walk the typespec for ALLOCATE if present.

Diff:
---
 gcc/fortran/dump-parse-tree.cc |  7 +++++++
 gcc/fortran/frontend-passes.cc | 13 ++++++++++++-
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/dump-parse-tree.cc b/gcc/fortran/dump-parse-tree.cc
index eaf6565d0e08..5f058cdc8300 100644
--- a/gcc/fortran/dump-parse-tree.cc
+++ b/gcc/fortran/dump-parse-tree.cc
@@ -3407,6 +3407,13 @@ show_code_node (int level, gfc_code *c)
 
     case EXEC_ALLOCATE:
       fputs ("ALLOCATE ", dumpfile);
+
+      if (c->ext.alloc.ts.type != BT_UNKNOWN)
+	{
+	  show_typespec (&c->ext.alloc.ts);
+	  fputs (":: ", dumpfile);
+	}
+
       if (c->expr1)
 	{
 	  fputs (" STAT=", dumpfile);
diff --git a/gcc/fortran/frontend-passes.cc b/gcc/fortran/frontend-passes.cc
index 87ac6e0a4e7d..92678310ffd3 100644
--- a/gcc/fortran/frontend-passes.cc
+++ b/gcc/fortran/frontend-passes.cc
@@ -5306,8 +5306,14 @@ gfc_expr_walker (gfc_expr **e, walk_expr_fn_t exprfn, void *data)
 	      WALK_SUBEXPR (a->expr);
 	    break;
 
-	  case EXPR_STRUCTURE:
 	  case EXPR_ARRAY:
+	    if ((*e)->ts.type == BT_CHARACTER)
+	      WALK_SUBEXPR ((*e)->ts.u.cl->length);
+
+	    gcc_fallthrough ();
+
+	  case EXPR_STRUCTURE:
+
 	    for (c = gfc_constructor_first ((*e)->value.constructor); c;
 		 c = gfc_constructor_next (c))
 	      {
@@ -5480,6 +5486,11 @@ gfc_code_walker (gfc_code **c, walk_code_fn_t codefn, walk_expr_fn_t exprfn,
 	      continue;
 
 	    case EXEC_ALLOCATE:
+	      if (co->ext.alloc.ts.type == BT_CHARACTER)
+		WALK_SUBEXPR (co->ext.alloc.ts.u.cl->length);
+
+	      gcc_fallthrough();
+
 	    case EXEC_DEALLOCATE:
 	      {
 		gfc_alloc *a;
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.