[COMMITTED] a68: fix a68_determine_unique_mode for series containing a single union

Jose E. Marchesi jemarch@gnu.org
Wed Sep 17 16:37:03 GMT 2025


---
 gcc/algol68/a68-moids-misc.cc                 | 9 +++++++++
 gcc/testsuite/algol68/compile/balancing-1.a68 | 7 +++++++
 2 files changed, 16 insertions(+)
 create mode 100644 gcc/testsuite/algol68/compile/balancing-1.a68

diff --git a/gcc/algol68/a68-moids-misc.cc b/gcc/algol68/a68-moids-misc.cc
index 36f09d8cc2e..9712c8b2a77 100644
--- a/gcc/algol68/a68-moids-misc.cc
+++ b/gcc/algol68/a68-moids-misc.cc
@@ -1146,6 +1146,15 @@ a68_determine_unique_mode (SOID_T *z, int deflex)
       if (a68_is_mode_isnt_well (x))
 	return M_ERROR;
 
+      /* If X is a series containing one union, a68_make_united_mode will
+	 return that union (because 'union (union (...))' is the same than
+	 'union (...)') and then a68_get_balanced_mode below will try to
+	 balance the modes in that union.  Not what we want.  */
+      if (ATTRIBUTE (x) == SERIES_MODE
+	  && DIM (x) == 1
+	  && IS (MOID (PACK (x)), UNION_SYMBOL))
+	return MOID (PACK (x));
+
       x = a68_make_united_mode (x);
       if (a68_clause_allows_balancing (ATTRIBUTE (z)))
 	return a68_get_balanced_mode (x, STRONG, A68_NO_DEPREF, deflex);
diff --git a/gcc/testsuite/algol68/compile/balancing-1.a68 b/gcc/testsuite/algol68/compile/balancing-1.a68
new file mode 100644
index 00000000000..62d1221f675
--- /dev/null
+++ b/gcc/testsuite/algol68/compile/balancing-1.a68
@@ -0,0 +1,7 @@
+mode Word = union (void,real),
+     Rules = union (void,string);
+
+op LEN = (Word w) int: skip,
+LEN = (Rules r) int: skip;
+
+skip
-- 
2.30.2




More information about the Algol68 mailing list