aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGaius Mulley <gaiusmod2@gmail.com>2025-05-05 18:16:20 +0100
committerGaius Mulley <gaiusmod2@gmail.com>2025-05-05 18:16:20 +0100
commitbb83283e5c5c55eab7493a58c5e415aa56f5940c (patch)
tree2afc824c6cb3661d78293134c795dede784209b9
parent7f285b7ad7cb89a9b29b52e0d25a7666dc9bd645 (diff)
downloadgcc-bb83283e5c5c55eab7493a58c5e415aa56f5940c.zip
gcc-bb83283e5c5c55eab7493a58c5e415aa56f5940c.tar.gz
gcc-bb83283e5c5c55eab7493a58c5e415aa56f5940c.tar.bz2
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 <gaiusmod2@gmail.com>
-rw-r--r--gcc/m2/gm2-compiler/M2GenGCC.mod3
-rw-r--r--gcc/m2/gm2-compiler/PCSymBuild.mod13
-rw-r--r--gcc/m2/gm2-compiler/SymbolTable.mod1
-rw-r--r--gcc/testsuite/gm2/pim/pass/highbit.mod13
-rw-r--r--gcc/testsuite/gm2/pim/pass/highbit2.mod13
5 files changed, 34 insertions, 9 deletions
diff --git a/gcc/m2/gm2-compiler/M2GenGCC.mod b/gcc/m2/gm2-compiler/M2GenGCC.mod
index a1e3c07..bc1d588 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 b124c3e..3bffe86 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 551bbec..ff661dc 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 0000000..c9c872a
--- /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 0000000..940556d
--- /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.