[COMMITTED] algol68: fix handling of bounds in gen_mode

Jose E. Marchesi jemarch@gnu.org
Sat Apr 12 10:55:22 GMT 2025


---
 gcc/algol68/a68-low-generator.cc              | 32 +++++++++++--------
 .../execute/assignation-multiple-1.a68        |  3 ++
 2 files changed, 22 insertions(+), 13 deletions(-)
 create mode 100644 gcc/testsuite/algol68/execute/assignation-multiple-1.a68

diff --git a/gcc/algol68/a68-low-generator.cc b/gcc/algol68/a68-low-generator.cc
index 2a9468525e4..51d31de456b 100644
--- a/gcc/algol68/a68-low-generator.cc
+++ b/gcc/algol68/a68-low-generator.cc
@@ -50,7 +50,7 @@ typedef tree (*allocator_t) (tree, tree);
    BUFFER.  */
 
 static tree
-fill_in_buffer (tree buffer, tree offset, tree_stmt_iterator bounds, MOID_T *m,
+fill_in_buffer (tree buffer, tree offset, tree_stmt_iterator *bounds, MOID_T *m,
 		allocator_t allocator)
 {
   tree filler = NULL_TREE;
@@ -135,10 +135,10 @@ fill_in_buffer (tree buffer, tree offset, tree_stmt_iterator bounds, MOID_T *m,
 	{
 	  /* Note we have to convert the bounds from CTYPE(M_INT) to
 	     ssizetype.  */
-	  lower_bounds[i] = fold_convert (ssizetype, save_expr (tsi_stmt (bounds)));
-	  tsi_next (&bounds);
-	  upper_bounds[i] = fold_convert (ssizetype, save_expr (tsi_stmt (bounds)));
-	  tsi_next (&bounds);
+	  lower_bounds[i] = fold_convert (ssizetype, save_expr (tsi_stmt (*bounds)));
+	  tsi_next (bounds);
+	  upper_bounds[i] = fold_convert (ssizetype, save_expr (tsi_stmt (*bounds)));
+	  tsi_next (bounds);
 
 	  tree dim_num_elems
 	    = fold_build2 (PLUS_EXPR, sizetype,
@@ -302,7 +302,7 @@ fill_in_buffer (tree buffer, tree offset, tree_stmt_iterator bounds, MOID_T *m,
 	= fold_build2 (POINTER_PLUS_EXPR, TREE_TYPE (buffer),
 		       buffer,
 		       fold_build2 (PLUS_EXPR, sizetype, offset, size_in_bytes (sizetype)));
-      
+
       tree value_field = TREE_CHAIN (TYPE_FIELDS (type));
       tree call = builtin_decl_explicit (BUILT_IN_MEMSET);
       call = build_call_expr_loc (UNKNOWN_LOCATION, call, 3,
@@ -325,7 +325,7 @@ fill_in_buffer (tree buffer, tree offset, tree_stmt_iterator bounds, MOID_T *m,
    from BOUNDS.  */
 
 static tree
-gen_mode (MOID_T *m, tree_stmt_iterator bounds, allocator_t allocator)
+gen_mode (MOID_T *m, tree_stmt_iterator *bounds, allocator_t allocator)
 {
   /* Allocate space for the value and fill it.  */
   tree buffer = (*allocator) (CTYPE (m), size_in_bytes (CTYPE (m)));
@@ -347,16 +347,22 @@ collect_bounds (NODE_T *p, LOW_CTX_T ctx)
 	collect_bounds (SUB (p), ctx);
       else if (IS (p, UNIT))
 	{
+	  /* First the lower bound.  */
+	  tree lower_bound;
 	  if (NEXT (p) != NO_NODE && IS (NEXT (p), COLON_SYMBOL))
 	    {
-	      a68_add_stmt (a68_lower_tree (p, ctx));
+	      lower_bound = a68_lower_tree (p, ctx);
 	      p = NEXT_NEXT (p);
 	    }
 	  else
 	    /* Default lower bound.  */
-	    a68_add_stmt (integer_one_node);
+	    lower_bound = integer_one_node;
+
+	  /* Now the upper bound.  */
+	  tree upper_bound = a68_lower_tree (p, ctx);
 
-	  a68_add_stmt (a68_lower_tree (p, ctx));
+	  a68_add_stmt (lower_bound);
+	  a68_add_stmt (upper_bound);
 	}
     }
 }
@@ -451,7 +457,7 @@ a68_low_generator (NODE_T *declarer,
       /* Allocate and initialize a memory buffer for a value of mode MODE with
 	 bounds in BOUNDS.  */
       tree_stmt_iterator bounds_iter = tsi_start (bounds);
-      tree gen = gen_mode (mode, bounds_iter, a68_lower_malloc);
+      tree gen = gen_mode (mode, &bounds_iter, a68_lower_malloc);
       a68_pop_function_range (gen);
       /* Avoid this generator function, which uses the global lexical
 	 environment, to be reused in other contexts.  */
@@ -469,7 +475,7 @@ a68_low_generator (NODE_T *declarer,
       /* Allocate and initialize a memory buffer for a value of mode MODE with
 	 bounds in BOUNDS.  */
       tree_stmt_iterator bounds_iter = tsi_start (bounds);
-      tree gen = gen_mode (mode, bounds_iter,
+      tree gen = gen_mode (mode, &bounds_iter,
 			   heap ? a68_lower_malloc : a68_lower_alloca);
       return gen;
     }
@@ -489,7 +495,7 @@ a68_low_gen (MOID_T *m, size_t nbounds, tree *bounds, bool use_heap)
   allocator_t allocator = use_heap ? a68_lower_malloc : a68_lower_alloca;
 
   tree_stmt_iterator q = tsi_start (bounds_list);
-  tree ret = gen_mode (m, q, allocator);
+  tree ret = gen_mode (m, &q, allocator);
   free_stmt_list (bounds_list);
   return ret;
 }
diff --git a/gcc/testsuite/algol68/execute/assignation-multiple-1.a68 b/gcc/testsuite/algol68/execute/assignation-multiple-1.a68
new file mode 100644
index 00000000000..9f76d59eb2d
--- /dev/null
+++ b/gcc/testsuite/algol68/execute/assignation-multiple-1.a68
@@ -0,0 +1,3 @@
+BEGIN STRUCT ([2:3]INT m, [1:5]REAL g) s;
+      g OF s:= (1.0, 2.0, 3.0, 4.0, 5.0)
+END
-- 
2.30.2



More information about the Algol68 mailing list