https://gcc.gnu.org/g:61fada934e894c7fb4a1f1626ea0d0f1f1f1d2f4

commit r15-9677-g61fada934e894c7fb4a1f1626ea0d0f1f1f1d2f4
Author: Gaius Mulley <gaiusm...@gmail.com>
Date:   Tue May 13 19:42:39 2025 +0100

    [PATCH] PR modula2/120117: ICE when attempting to obtain the MAX of an 
aliased set type
    
    The ICE occurred because of a bug in M2GenGCC.mod:FoldBecomes which
    attempted to remove the same quadruple twice.  Thereafter cc1gm2
    generated an erroneous error type error as PCSymBuild did not skip
    an aliased set type.  The type of the const was set incorrectly
    (as a set type) rather than the type of the set element.
    
    gcc/m2/ChangeLog:
    
            PR modula2/120117
            * gm2-compiler/M2GenGCC.mod (FoldBecomes): Remove the call to
            RemoveQuad since this is performed by TypeCheckBecomes.
            * gm2-compiler/PCSymBuild.mod (buildConstFunction): Rewrite
            header comment.
            Check for a set or a type aliased set and appropriately
            skip type equivalences and obtain the element type.
            * gm2-compiler/SymbolTable.mod (PutConst): Add call to
            CheckBreak.
    
    gcc/testsuite/ChangeLog:
    
            PR modula2/120117
            * gm2/pim/pass/highbit.mod: New test.
            * gm2/pim/pass/highbit2.mod: New test.
    
    (cherry picked from commit bb83283e5c5c55eab7493a58c5e415aa56f5940c)
    
    Signed-off-by: Gaius Mulley <gaiusm...@gmail.com>

Diff:
---
 gcc/m2/gm2-compiler/M2GenGCC.mod        |  3 ---
 gcc/m2/gm2-compiler/PCSymBuild.mod      | 13 +++++++------
 gcc/m2/gm2-compiler/SymbolTable.mod     |  1 +
 gcc/testsuite/gm2/pim/pass/highbit.mod  | 13 +++++++++++++
 gcc/testsuite/gm2/pim/pass/highbit2.mod | 13 +++++++++++++
 5 files changed, 34 insertions(+), 9 deletions(-)

diff --git a/gcc/m2/gm2-compiler/M2GenGCC.mod b/gcc/m2/gm2-compiler/M2GenGCC.mod
index a1e3c07809aa..bc1d588fce6e 100644
--- a/gcc/m2/gm2-compiler/M2GenGCC.mod
+++ b/gcc/m2/gm2-compiler/M2GenGCC.mod
@@ -2914,9 +2914,6 @@ BEGIN
          IF TypeCheckBecomes (p, quad)
          THEN
             PerformFoldBecomes (p, quad)
-         ELSE
-            GetQuad (quad, op, des, op2, expr) ;
-            RemoveQuad (p, des, quad)
          END
       END
    END
diff --git a/gcc/m2/gm2-compiler/PCSymBuild.mod 
b/gcc/m2/gm2-compiler/PCSymBuild.mod
index b124c3ea6729..3bffe8674a4f 100644
--- a/gcc/m2/gm2-compiler/PCSymBuild.mod
+++ b/gcc/m2/gm2-compiler/PCSymBuild.mod
@@ -64,7 +64,7 @@ FROM SymbolTable IMPORT NulSym, ModeOfAddr, ProcedureKind,
                         GetFromOuterModule,
                         CheckForEnumerationInCurrentModule,
                         GetMode, PutVariableAtAddress, ModeOfAddr, SkipType,
-                        IsSet, PutConstSet,
+                        IsSet, PutConstSet, IsType,
                         IsConst, IsConstructor, PutConst, PutConstructor,
                         PopValue, PushValue,
                         MakeTemporary, PutVar,
@@ -1408,9 +1408,10 @@ END TypeToMeta ;
 
 
 (*
-   buildConstFunction - we are only concerned about resolving the return type o
+   buildConstFunction - we are only concerned about resolving the return type 
of
                         a function, so we can ignore all parameters - except
-                        the first one in the case of VAL(type, foo).
+                        the first one in the case of VAL(type, foo)
+                        and the type of bar in MIN (bar) and MAX (bar).
                         buildConstFunction uses a unary exprNode to represent
                         a function.
 *)
@@ -1866,11 +1867,11 @@ BEGIN
             THEN
                IF (func=Min) OR (func=Max)
                THEN
-                  IF IsSet (sym)
+                  IF IsSet (sym) OR (IsType (sym) AND IsSet (SkipType (sym)))
                   THEN
-                     type := SkipType(GetType(sym))
+                     type := GetType (SkipType (sym))
                   ELSE
-                     (* sym is the type required for MAX, MIN and VAL *)
+                     (* sym is the type required for MAX, MIN and VAL.  *)
                      type := sym
                   END
                ELSE
diff --git a/gcc/m2/gm2-compiler/SymbolTable.mod 
b/gcc/m2/gm2-compiler/SymbolTable.mod
index 551bbecc7886..ff661dcf4e7e 100644
--- a/gcc/m2/gm2-compiler/SymbolTable.mod
+++ b/gcc/m2/gm2-compiler/SymbolTable.mod
@@ -7265,6 +7265,7 @@ VAR
    pSym: PtrToSymbol ;
 BEGIN
    pSym := GetPsym(Sym) ;
+   CheckBreak (Sym) ;
    WITH pSym^ DO
       CASE SymbolType OF
 
diff --git a/gcc/testsuite/gm2/pim/pass/highbit.mod 
b/gcc/testsuite/gm2/pim/pass/highbit.mod
new file mode 100644
index 000000000000..c9c872a62f31
--- /dev/null
+++ b/gcc/testsuite/gm2/pim/pass/highbit.mod
@@ -0,0 +1,13 @@
+MODULE highbit ;
+
+FROM libc IMPORT printf ;
+
+TYPE
+   set = BITSET ;
+
+CONST
+   HighBit = MAX (set) ;
+
+BEGIN
+   printf ("the MAX (set) = %d\n", HighBit)
+END highbit.
diff --git a/gcc/testsuite/gm2/pim/pass/highbit2.mod 
b/gcc/testsuite/gm2/pim/pass/highbit2.mod
new file mode 100644
index 000000000000..940556da5fe9
--- /dev/null
+++ b/gcc/testsuite/gm2/pim/pass/highbit2.mod
@@ -0,0 +1,13 @@
+MODULE highbit2 ;
+
+FROM libc IMPORT printf ;
+
+TYPE
+   set = BITSET ;
+
+CONST
+   HighBit = MAX (BITSET) ;
+
+BEGIN
+   printf ("the MAX (BITSET) = %d\n", HighBit)
+END highbit2.

Reply via email to