[gcc r16-9349] a68: fix deduplication of in-MOIF modes

"Jose E. Marchesi via Gcc-cvs" <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:fabfa9c1b289519b73247884c7ea944344738108

commit r16-9349-gfabfa9c1b289519b73247884c7ea944344738108
Author: Jose E. Marchesi <[email protected]>
Date:   Tue Jun 16 22:52:14 2026 +0200

    a68: fix deduplication of in-MOIF modes
    
    Of course I got the in-MOIF deduplication of modes wrong due to a
    stupid thinko.  This patch fixes the thinko and also adds a little
    extra sanity check.
    
    Signed-off-by: Jose E. Marchesi <[email protected]>
    
    gcc/algol68/ChangeLog
    
            * a68-imports.cc (a68_replace_equivalent_mode): Get a moif and
            check extracts.
            (a68_open_packet): Fix deduplication of in-moif modes and move
            extract replacement code to a68_replace_equivalent_mode.
            * a68-low-moids.cc (a68_lower_moids): Check that all known modes
            have an associated ctype as part of the sanity checks.
    
    (cherry picked from commit 588986ae64697af0385922af9676f4dd33f76a0b)

Diff:
---
 gcc/algol68/a68-imports.cc   | 50 ++++++++++++++++++++++----------------------
 gcc/algol68/a68-low-moids.cc |  1 +
 2 files changed, 26 insertions(+), 25 deletions(-)

diff --git a/gcc/algol68/a68-imports.cc b/gcc/algol68/a68-imports.cc
index e7b5580eec5e..37b0b9a209fa 100644
--- a/gcc/algol68/a68-imports.cc
+++ b/gcc/algol68/a68-imports.cc
@@ -986,9 +986,11 @@ a68_replace_submode (MOID_T *t, MOID_T *m, MOID_T *r)
    The entry for M in MODES_LIST is set to NO_MOID.  */
 
 static void
-a68_replace_equivalent_mode (vec<MOID_T*,va_gc> *mode_list,
+a68_replace_equivalent_mode (MOIF_T *moif,
 			     MOID_T *m, MOID_T *r)
 {
+  /* Handle the mode to be replaced.  */
+  vec<MOID_T*,va_gc> *mode_list = MODES (moif);
   for (size_t i = 0; i < mode_list->length (); ++i)
     {
       if ((*mode_list)[i] == m)
@@ -996,6 +998,25 @@ a68_replace_equivalent_mode (vec<MOID_T*,va_gc> *mode_list,
       else if ((*mode_list)[i] != NO_MOID)
 	a68_replace_submode ((*mode_list)[i], m, r);
     }
+
+  /* Update extracts to reflect the replacement.  */
+  for (EXTRACT_T *e : INDICANTS (moif))
+    {
+      if (EXTRACT_MODE (e) == m)
+	EXTRACT_MODE (e) = r;
+    }
+
+  for (EXTRACT_T *e : IDENTIFIERS (moif))
+    {
+      if (EXTRACT_MODE (e) == m)
+	EXTRACT_MODE (e) = r;
+    }
+
+  for (EXTRACT_T *e : OPERATORS (moif))
+    {
+      if (EXTRACT_MODE (e) == m)
+	EXTRACT_MODE (e) = r;
+    }
 }
 
 /* Decode a modes table at DATA + POS.  */
@@ -1488,7 +1509,7 @@ a68_open_packet (const char *module, const char *basename)
 		{
 		  if (a68_prove_moid_equivalence (m, known_moids[i]))
 		    {
-		      r =  m;
+		      r = known_moids[i];
 		      break;
 		    }
 		}
@@ -1496,29 +1517,8 @@ a68_open_packet (const char *module, const char *basename)
 
 	  if (r == NO_MOID)
 	    known_moids.push_back (m);
-	  else
-	    {
-	      a68_replace_equivalent_mode (MODES (moif), m, r);
-
-	      /* Update extracts to reflect the replacement.  */
-	      for (EXTRACT_T *e : INDICANTS (moif))
-		{
-		  if (EXTRACT_MODE (e) == m)
-		    EXTRACT_MODE (e) = r;
-		}
-
-	      for (EXTRACT_T *e : IDENTIFIERS (moif))
-		{
-		  if (EXTRACT_MODE (e) == m)
-		    EXTRACT_MODE (e) = r;
-		}
-
-	      for (EXTRACT_T *e : OPERATORS (moif))
-		{
-		  if (EXTRACT_MODE (e) == m)
-		    EXTRACT_MODE (e) = r;
-		}
-	    }
+	  else if (r != m)
+	    a68_replace_equivalent_mode (moif, m, r);
 	}
     }
 
diff --git a/gcc/algol68/a68-low-moids.cc b/gcc/algol68/a68-low-moids.cc
index 5c1fda6d1c81..27b28173003f 100644
--- a/gcc/algol68/a68-low-moids.cc
+++ b/gcc/algol68/a68-low-moids.cc
@@ -723,6 +723,7 @@ a68_lower_moids (MOID_T *mode)
   /* Sanity check.  */
   for (MOID_T *m = mode; m != NO_MOID; FORWARD (m))
     {
+      gcc_assert (CTYPE (m) != NULL_TREE);
       gcc_assert (COMPLETE_TYPE_P (CTYPE (m)));
       if (IS_UNION (m))
 	{
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.