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 <[email protected]>

gcc/algol68/ChangeLog

        * a68-moids-sorting.cc (packs_ordering): Do not rely on pointer
        comparison when comparing pack element names.

(cherry picked from commit 3ed55c5ee90e0cdb2e2edc7aa4976f5cea7bd5ec)
---
 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

Reply via email to