https://gcc.gnu.org/g:092179f9bfbc2dcb2656b7e62e8ca344154d4cbd

commit r17-4534-g092179f9bfbc2dcb2656b7e62e8ca344154d4cbd
Author: Jose E. Marchesi <[email protected]>
Date:   Mon Sep 21 16:17:48 2026 +0200

    a68: resolve mode equivalences when importing publicized identifiers
    
    Imported modes resulting from the extract of a revelation will not be
    reachable from any node in the parse tree.  Instead, dummy nodes gets
    synthesized for what would have been the declaration of the
    identifiers having these modes, and installed in the symtab.  The
    consequence of that is that compute_derived_modes will not process
    these mode references.
    
    When the imported mode is a standard mode that has an equivalent
    mode (such as SIZETY compl for example) then there is trouble because
    the mode equivalence code compares STANDARD modes by pointer.
    
    This patch fixes the problem by resolving equivalences in the imported
    modes.
    
    Signed-off-by: Jose E. Marchesi <[email protected]>
    
    gcc/algol68/ChangeLog
    
            * a68-parser-modes.cc (a68_resolve_equivalent): Rename from
            resolve_equivalent and made global.
            (resolve_eq_members): Adapt calls to resolve_equivalent
            accordingly.
            (resolve_eq_tags): Likewise.
            (bind_modes): Likewise.
            (compute_derived_modes): Likewise.
            * a68.h: Add prototype for a68_resolve_equivalent.
            * a68-parser-extract.cc (a68_extract_revelation): Resolve
            equivalences in imported modes.
    
    gcc/testsuite/ChangeLog
    
            * algol68/execute/modules/program-28.a68: New test.
            * algol68/execute/modules/module28.a68: New file.

Diff:
---
 gcc/algol68/a68-parser-extract.cc                  |  7 +++++
 gcc/algol68/a68-parser-modes.cc                    | 36 +++++++++++-----------
 gcc/algol68/a68.h                                  |  2 +-
 gcc/testsuite/algol68/execute/modules/module28.a68 |  7 +++++
 .../algol68/execute/modules/program-28.a68         |  8 +++++
 5 files changed, 41 insertions(+), 19 deletions(-)

diff --git a/gcc/algol68/a68-parser-extract.cc 
b/gcc/algol68/a68-parser-extract.cc
index fc1f318eaaf1..8d026fd569ac 100644
--- a/gcc/algol68/a68-parser-extract.cc
+++ b/gcc/algol68/a68-parser-extract.cc
@@ -341,9 +341,16 @@ a68_extract_revelation (NODE_T *q, const char *module, 
const char *filename,
       NCHAR_IN_LINE (n) = STRING (LINE (INFO (n)));
       TABLE (n) = TABLE (q);
 
+      /* It is necessary to resolve equivalences because the dummy declarer is
+        not in the parse tree and therefore it is not handled by the call to
+        computed_derived_modes in a68_make_moid_list.  */
+      a68_resolve_equivalent (&EXTRACT_MODE (e));
+
+      MOID (n) = EXTRACT_MODE (e);
       TAG_T *tag = a68_add_tag (TABLE (q), IDENTIFIER,
                                n, EXTRACT_MODE (e), NORMAL_IDENTIFIER);
       gcc_assert (tag != NO_TAG);
+
       EXTERN_SYMBOL (tag) = ggc_strdup (EXTRACT_SYMBOL (e));
       VARIABLE (tag) = VARIABLE (e);
       IN_PROC (tag) = IN_PROC (e);
diff --git a/gcc/algol68/a68-parser-modes.cc b/gcc/algol68/a68-parser-modes.cc
index 9cbf4f962e41..19f8e7f5cbc8 100644
--- a/gcc/algol68/a68-parser-modes.cc
+++ b/gcc/algol68/a68-parser-modes.cc
@@ -87,8 +87,8 @@ a68_count_pack_members (PACK_T *u)
 
 /* Replace a mode by its equivalent mode.  */
 
-static void
-resolve_equivalent (MOID_T **m)
+void
+a68_resolve_equivalent (MOID_T **m)
 {
   while ((*m) != NO_MOID
         && EQUIVALENT ((*m)) != NO_MOID
@@ -888,15 +888,15 @@ is_well_formed (MOID_T *def, MOID_T *z, bool yin, bool 
yang, int video)
 static void
 resolve_eq_members (MOID_T *q)
 {
-  resolve_equivalent (&SUB (q));
-  resolve_equivalent (&DEFLEXED (q));
-  resolve_equivalent (&MULTIPLE (q));
-  resolve_equivalent (&NAME (q));
-  resolve_equivalent (&SLICE (q));
-  resolve_equivalent (&TRIM (q));
-  resolve_equivalent (&ROWED (q));
+  a68_resolve_equivalent (&SUB (q));
+  a68_resolve_equivalent (&DEFLEXED (q));
+  a68_resolve_equivalent (&MULTIPLE (q));
+  a68_resolve_equivalent (&NAME (q));
+  a68_resolve_equivalent (&SLICE (q));
+  a68_resolve_equivalent (&TRIM (q));
+  a68_resolve_equivalent (&ROWED (q));
   for (PACK_T *p = PACK (q); p != NO_PACK; FORWARD (p))
-    resolve_equivalent (&MOID (p));
+    a68_resolve_equivalent (&MOID (p));
 }
 
 /* Track equivalent tags.  */
@@ -907,7 +907,7 @@ resolve_eq_tags (TAG_T *z)
   for (; z != NO_TAG; FORWARD (z))
     {
       if (MOID (z) != NO_MOID)
-       resolve_equivalent (&MOID (z));
+       a68_resolve_equivalent (&MOID (z));
     }
 }
 
@@ -918,7 +918,7 @@ bind_modes (NODE_T *p)
 {
   for (; p != NO_NODE; FORWARD (p))
     {
-      resolve_equivalent (&MOID (p));
+      a68_resolve_equivalent (&MOID (p));
 
       if (SUB (p) != NO_NODE && a68_is_new_lexical_level (p))
        {
@@ -927,7 +927,7 @@ bind_modes (NODE_T *p)
            {
              if (NODE (z) != NO_NODE)
                {
-                 resolve_equivalent (&MOID (NEXT_NEXT (NODE (z))));
+                 a68_resolve_equivalent (&MOID (NEXT_NEXT (NODE (z))));
                  MOID (z) = MOID (NEXT_NEXT (NODE (z)));
                  MOID (NODE (z)) = MOID (z);
                }
@@ -1181,11 +1181,11 @@ compute_derived_modes (MODULE_T *mod)
       resolve_eq_tags (INDICANTS (A68_STANDENV));
       resolve_eq_tags (IDENTIFIERS (A68_STANDENV));
       resolve_eq_tags (OPERATORS (A68_STANDENV));
-      resolve_equivalent (&M_STRING);
-      resolve_equivalent (&M_COMPLEX);
-      resolve_equivalent (&M_LONG_COMPLEX);
-      resolve_equivalent (&M_LONG_LONG_COMPLEX);
-      resolve_equivalent (&M_SEMA);
+      a68_resolve_equivalent (&M_STRING);
+      a68_resolve_equivalent (&M_COMPLEX);
+      a68_resolve_equivalent (&M_LONG_COMPLEX);
+      a68_resolve_equivalent (&M_LONG_LONG_COMPLEX);
+      a68_resolve_equivalent (&M_SEMA);
       /* UNION members could be resolved.  */
       absorb_unions (TOP_MOID (mod));
       contract_unions (TOP_MOID (mod));
diff --git a/gcc/algol68/a68.h b/gcc/algol68/a68.h
index 16642c6e0bda..00b99075f272 100644
--- a/gcc/algol68/a68.h
+++ b/gcc/algol68/a68.h
@@ -440,8 +440,8 @@ PACK_T *a68_absorb_union_pack (PACK_T * u);
 void a68_add_mode_to_pack (PACK_T **p, MOID_T *m, const char *text, NODE_T 
*node);
 void a68_add_mode_to_pack_end (PACK_T **p, MOID_T *m, const char *text, NODE_T 
*node);
 void a68_make_moid_list (MODULE_T *mod);
-
 void a68_renumber_moids (MOID_T *p, int n);
+void a68_resolve_equivalent (MOID_T **m);
 
 /* a68-moids-to-string.cc  */
 
diff --git a/gcc/testsuite/algol68/execute/modules/module28.a68 
b/gcc/testsuite/algol68/execute/modules/module28.a68
new file mode 100644
index 000000000000..7c6644abb525
--- /dev/null
+++ b/gcc/testsuite/algol68/execute/modules/module28.a68
@@ -0,0 +1,7 @@
+module Module28 =
+def
+    pub compl c = 10.0;
+    pub long compl lc = long 20.0;
+    pub long long compl llc = long long 30.0;
+    skip
+fed
diff --git a/gcc/testsuite/algol68/execute/modules/program-28.a68 
b/gcc/testsuite/algol68/execute/modules/program-28.a68
new file mode 100644
index 000000000000..e43eeedc1c8f
--- /dev/null
+++ b/gcc/testsuite/algol68/execute/modules/program-28.a68
@@ -0,0 +1,8 @@
+{ dg-modules "module28" }
+
+access Module28
+begin assert (IM c < 100.0 AND RE c > 0.0);
+      assert (IM lc < long 100.0 AND RE lc > long 0.0);
+      assert (IM llc < long long 100.0 AND RE llc > long long 0.0);
+      skip
+end

Reply via email to