[COMMITTED] algol68: handle ultra-flat multiples in ELEMS
Jose E. Marchesi
jemarch@gnu.org
Sat Apr 12 11:18:09 GMT 2025
---
gcc/algol68/a68-low-prelude.cc | 23 +++++++++++++++--------
gcc/testsuite/algol68/execute/elems-2.a68 | 6 ++++++
2 files changed, 21 insertions(+), 8 deletions(-)
create mode 100644 gcc/testsuite/algol68/execute/elems-2.a68
diff --git a/gcc/algol68/a68-low-prelude.cc b/gcc/algol68/a68-low-prelude.cc
index 506817607cd..4dccdc4fb47 100644
--- a/gcc/algol68/a68-low-prelude.cc
+++ b/gcc/algol68/a68-low-prelude.cc
@@ -684,8 +684,6 @@ elems (tree boundable, tree dim)
/* BOUNDABLE can be a multiple or a ROWS. */
tree type = TREE_TYPE (boundable);
- /* XXX handle flat dimensions other than 1:0 and return zero for them. */
-
/* Make DIM zero-based. */
dim = fold_build2 (MINUS_EXPR, TREE_TYPE (dim), dim, size_one_node);
@@ -707,12 +705,21 @@ elems (tree boundable, tree dim)
else
gcc_unreachable ();
- return fold_build2 (PLUS_EXPR,
- sizetype,
- fold_convert (sizetype,
- fold_build2 (MINUS_EXPR, ssizetype,
- upper_bound, lower_bound)),
- size_one_node);
+ upper_bound = save_expr (upper_bound);
+ lower_bound = save_expr (lower_bound);
+
+ tree non_flat = fold_build2 (PLUS_EXPR,
+ sizetype,
+ fold_convert (sizetype,
+ fold_build2 (MINUS_EXPR, ssizetype,
+ upper_bound, lower_bound)),
+ size_one_node);
+
+ return fold_build3 (COND_EXPR, sizetype,
+ fold_build2 (LT_EXPR, boolean_type_node,
+ upper_bound, lower_bound),
+ size_zero_node,
+ non_flat);
}
tree
diff --git a/gcc/testsuite/algol68/execute/elems-2.a68 b/gcc/testsuite/algol68/execute/elems-2.a68
new file mode 100644
index 00000000000..e2f6d7d882c
--- /dev/null
+++ b/gcc/testsuite/algol68/execute/elems-2.a68
@@ -0,0 +1,6 @@
+# Flat and ultra-flat multiples. #
+BEGIN [3][10:3]INT arr;
+ ASSERT (2 ELEMS arr = 0);
+ [1:0]INT arr2;
+ ASSERT (ELEMS arr2 = 0)
+END
--
2.30.2
More information about the Algol68
mailing list