From: Gaius Mulley Date: Mon, 5 May 2025 17:16:20 +0000 (+0100) Subject: PR modula2/120117: ICE when attempting to obtain the MAX of an aliased set type X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bb83283e5c5c55eab7493a58c5e415aa56f5940c;p=thirdparty%2Fgcc.git 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. Signed-off-by: Gaius Mulley --- diff --git a/gcc/m2/gm2-compiler/M2GenGCC.mod b/gcc/m2/gm2-compiler/M2GenGCC.mod index a1e3c07809a..bc1d588fce6 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 b124c3ea672..3bffe8674a4 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 551bbecc788..ff661dcf4e7 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 00000000000..c9c872a62f3 --- /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 00000000000..940556da5fe --- /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.