]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR modula2/120117: ICE when attempting to obtain the MAX of an aliased set type
authorGaius Mulley <gaiusmod2@gmail.com>
Mon, 5 May 2025 17:16:20 +0000 (18:16 +0100)
committerGaius Mulley <gaiusmod2@gmail.com>
Mon, 5 May 2025 17:16:20 +0000 (18:16 +0100)
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.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
gcc/m2/gm2-compiler/M2GenGCC.mod
gcc/m2/gm2-compiler/PCSymBuild.mod
gcc/m2/gm2-compiler/SymbolTable.mod
gcc/testsuite/gm2/pim/pass/highbit.mod [new file with mode: 0644]
gcc/testsuite/gm2/pim/pass/highbit2.mod [new file with mode: 0644]

index a1e3c07809aaefa1e71aaf13460c151a8fe0fe74..bc1d588fce6eac7491f8fa078a2038623f1af383 100644 (file)
@@ -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
index b124c3ea6729a0b57b7ca6b1fc0c83e693842db6..3bffe8674a4fdaae8bb5d64cb250fc170750e00b 100644 (file)
@@ -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
index 551bbecc788670ae8c92726ff7d3eb3f37933480..ff661dcf4e7e299e1e97ee841f93b239ffc957d1 100644 (file)
@@ -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 (file)
index 0000000..c9c872a
--- /dev/null
@@ -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 (file)
index 0000000..940556d
--- /dev/null
@@ -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.