[COMMITTED] a68: make a68_module_definition_decls a global root for GC

Jose E. Marchesi jemarch@gnu.org
Sat Nov 22 16:38:33 GMT 2025


---
 gcc/algol68/a68-low-decls.cc |  8 ++++----
 gcc/algol68/a68-low-units.cc |  2 +-
 gcc/algol68/a68-low.cc       | 13 ++++++++++---
 gcc/algol68/a68-types.h      |  2 --
 gcc/algol68/a68.h            |  2 ++
 5 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/gcc/algol68/a68-low-decls.cc b/gcc/algol68/a68-low-decls.cc
index 6c35d455612..8ae1b7007bc 100644
--- a/gcc/algol68/a68-low-decls.cc
+++ b/gcc/algol68/a68-low-decls.cc
@@ -181,7 +181,7 @@ a68_lower_variable_declaration (NODE_T *p, LOW_CTX_T ctx)
      to the publicized declarations list.  Otherwise chain the declaration in
      the proper block and bind it.  */
   if (PUBLIC_RANGE (TABLE (TAX (defining_identifier))))
-    ctx.module_definition_decls.safe_push (var_decl);
+    vec_safe_push (a68_module_definition_decls, var_decl);
   else
     a68_add_decl (var_decl);
 
@@ -334,7 +334,7 @@ a68_lower_identity_declaration (NODE_T *p, LOW_CTX_T ctx)
      to the publicized declarations list.  Otherwise chain the declaration in
      the proper block and bind it.  */
   if (PUBLIC_RANGE (TABLE (TAX (defining_identifier))))
-    ctx.module_definition_decls.safe_push (id_decl);
+    vec_safe_push (a68_module_definition_decls, id_decl);
   else
     a68_add_decl (id_decl);
 
@@ -538,7 +538,7 @@ a68_lower_procedure_variable_declaration (NODE_T *p, LOW_CTX_T ctx)
      to the publicized declarations list.  Otherwise chain the declaration in
      the proper block and bind it.  */
   if (PUBLIC_RANGE (TABLE (TAX (defining_identifier))))
-    ctx.module_definition_decls.safe_push (decl);
+    vec_safe_push (a68_module_definition_decls, decl);
   else
     a68_add_decl (decl);
 
@@ -666,7 +666,7 @@ a68_lower_operator_declaration (NODE_T *p, LOW_CTX_T ctx)
      to the publicized declarations list.  Otherwise chain the declaration in
      the proper block and bind it.  */
   if (PUBLIC_RANGE (TABLE (TAX (defining_operator))))
-    ctx.module_definition_decls.safe_push (op_decl);
+    vec_safe_push (a68_module_definition_decls, op_decl);
   else
     a68_add_decl (op_decl);
 
diff --git a/gcc/algol68/a68-low-units.cc b/gcc/algol68/a68-low-units.cc
index f65c8f7f7ba..00e3f641215 100644
--- a/gcc/algol68/a68-low-units.cc
+++ b/gcc/algol68/a68-low-units.cc
@@ -1179,7 +1179,7 @@ a68_lower_routine_text (NODE_T *p, LOW_CTX_T ctx)
 	 declaration to the publicized declarations list.  Otherwise chain the
 	 declaration in the proper block and bind it.  */
       if (PUBLIC_RANGE (TABLE (TAX (defining_identifier))))
-	ctx.module_definition_decls.safe_push (func_decl);
+	vec_safe_push (a68_module_definition_decls, func_decl);
       else
 	a68_add_decl (func_decl);
     }
diff --git a/gcc/algol68/a68-low.cc b/gcc/algol68/a68-low.cc
index 468cc474f1e..1b35241d87d 100644
--- a/gcc/algol68/a68-low.cc
+++ b/gcc/algol68/a68-low.cc
@@ -1375,9 +1375,10 @@ lower_module_declaration (NODE_T *p, LOW_CTX_T ctx)
       if (IS (p, DEFINING_MODULE_INDICANT))
 	{
 	  ctx.module_definition_name = NSYMBOL (p);
-	  ctx.module_definition_decls.truncate (0);
+	  a68_module_definition_decls->truncate (0);
+	  vec_alloc (a68_module_definition_decls, 16);
 	  lower_module_text (NEXT (NEXT (p)), ctx);
-	  for (tree d : ctx.module_definition_decls)
+	  for (tree d : a68_module_definition_decls)
 	    {
 	      if (TREE_CODE (d) == FUNCTION_DECL)
 		cgraph_node::finalize_function (d, true);
@@ -1682,6 +1683,12 @@ a68_lower_tree (NODE_T *p, LOW_CTX_T ctx)
   return res;
 }
 
+/* Global list of the tree decls corresponding to the module definition being
+   compiled.  Note that currently we only allow top-level modules, so there is
+   no nesting.  */
+
+vec<tree,va_gc> *a68_module_definition_decls;
+
 /* Lower an Algol 68 complete parse tree to a GENERIC tree.  */
 
 tree
@@ -1694,6 +1701,6 @@ a68_lower_top_tree (NODE_T *p)
   top_ctx.proc_decl_operator = false;
   top_ctx.level = 0;
   top_ctx.module_definition_name = NULL;
-  top_ctx.module_definition_decls.create (16);
+  vec_alloc (a68_module_definition_decls, 16);
   return a68_lower_tree (p, top_ctx);
 }
diff --git a/gcc/algol68/a68-types.h b/gcc/algol68/a68-types.h
index fd9d90c9b3e..b97b83f8d91 100644
--- a/gcc/algol68/a68-types.h
+++ b/gcc/algol68/a68-types.h
@@ -140,8 +140,6 @@ struct LOW_CTX_T
   bool proc_decl_operator;
   /* Name of current module definition, or NULL.  */
   const char *module_definition_name;
-  /* Vector where to add declarations in module preludes.  */
-  vec<tree> module_definition_decls;
   /* For debugging purposes.  */
   int level;
 };
diff --git a/gcc/algol68/a68.h b/gcc/algol68/a68.h
index 15cbe5c3ee0..c6a62e1aa70 100644
--- a/gcc/algol68/a68.h
+++ b/gcc/algol68/a68.h
@@ -287,6 +287,8 @@ extern GTY(()) tree a68_global_trees[ATI_MAX];
 #define a68_long_real_type          a68_global_trees[ATI_LONG_REAL_TYPE]
 #define a68_long_long_real_type     a68_global_trees[ATI_LONG_LONG_REAL_TYPE]
 
+extern GTY(()) vec<tree,va_gc> *a68_module_definition_decls;
+
 struct lang_type *a68_build_lang_type (MOID_T *moid);
 struct lang_decl *a68_build_lang_decl (NODE_T *node);
 MOID_T *a68_type_moid (tree type);
-- 
2.30.2



More information about the Algol68 mailing list