[COMMITTED 2/2] a68: fix comparison of pack element names in packs_ordering

Jose E. Marchesi jemarch@gnu.org
Wed Jun 24 22:48:48 GMT 2026


Entry names of packs (struct fields, union alternatives, procedure
parameter list) cannot be compared purely by pointer value.  This
patch fixes the union alternative sorting code to not rely on this
false assumption.

Signed-off-by: Jose E. Marchesi <jemarch@gnu.org>

gcc/algol68/ChangeLog

	* a68-moids-sorting.cc (packs_ordering): Do not rely on pointer
	comparison when comparing pack element names.
---
 gcc/algol68/a68-moids-sorting.cc | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gcc/algol68/a68-moids-sorting.cc b/gcc/algol68/a68-moids-sorting.cc
index 6579fbd2cc1..53c3487fb28 100644
--- a/gcc/algol68/a68-moids-sorting.cc
+++ b/gcc/algol68/a68-moids-sorting.cc
@@ -52,7 +52,10 @@ packs_ordering (PACK_T *a, PACK_T *b, bool compare_names = true)
 		return 1;
 	      if (TEXT (b) == NO_TEXT)
 		return -1;
-	      return -strcmp (TEXT (a), TEXT (b));
+
+	      int cmp = strcmp (TEXT (a), TEXT (b));
+	      if (cmp != 0)
+		return -cmp;
 	    }
 	}
     }
-- 
2.39.5



More information about the Algol68 mailing list