PR modula2/109423 cc1gm2 ICE if an INCL or EXCL is performed on an unknown set
authorGaius Mulley <gaiusmod2@gmail.com>
Wed, 5 Apr 2023 22:07:46 +0000 (23:07 +0100)
committerGaius Mulley <gaiusmod2@gmail.com>
Wed, 5 Apr 2023 22:07:46 +0000 (23:07 +0100)
This patch fixes an ICE if attempting to INCL or EXCL on an unknown
set.  The fix was to correct an error format string.  Also included in
the patch are patches to remove unused variables.  The patch also
marks a variable as written in BuildAdr.

gcc/m2/ChangeLog:

PR modula2/109423
* gm2-compiler/M2Base.def (Unbounded): Remove.
* gm2-compiler/M2Error.def (ErrorAbort0): Add noreturn
attribute.
* gm2-compiler/M2Quads.mod (BuildInclProcedure): Correct
error format string.
(BuildExceptProcedure): Correct error format string.
(BuildAdrFunction): Call PutWriteQuad when taking the
address of a variable.
* gm2-libs-ch/SysExceptions.c (_M2_SysExceptions_init): Add
parameters.
* gm2-libs-ch/wrapc.c (_M2_wrapc_init): Add parameters.
* gm2-libs/DynamicStrings.mod (DumpStringInfo): Remove t.
(PopAllocationExemption): Remove f.
* gm2-libs/FIO.mod (BufferedWrite): Remove result.
* gm2-libs/FormatStrings.mod (Copy): Remove endpos and
afterperc.
(HandlePercent): Remove result.
* gm2-libs/Indexing.mod (RemoveIndiceFromIndex): Remove k.
* gm2-libs/M2Dependent.mod (CreateModule): Remove p0
and p1.
(DumpModuleData): Remove mptr.
(ConstructModules): Remove nulp.
* gm2-libs/RTExceptions.mod (PopHandler): Remove i.
* gm2-libs/RTint.mod (Listen): Remove b4s, b4m, afs
and afm.
* gm2-libs/SFIO.mod (ReadS): Remove c.
* gm2-libs/StringConvert.mod (doDecimalPlaces): Remove
whole and fraction.

gcc/testsuite/ChangeLog:

* gm2/pim/fail/setunknown.mod: New test.
PR modula2/109423
* gm2/pim/fail/setunknown2.mod: New test.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
16 files changed:
gcc/m2/gm2-compiler/M2Base.def
gcc/m2/gm2-compiler/M2Error.def
gcc/m2/gm2-compiler/M2Quads.mod
gcc/m2/gm2-libs-ch/SysExceptions.c
gcc/m2/gm2-libs-ch/wrapc.c
gcc/m2/gm2-libs/DynamicStrings.mod
gcc/m2/gm2-libs/FIO.mod
gcc/m2/gm2-libs/FormatStrings.mod
gcc/m2/gm2-libs/Indexing.mod
gcc/m2/gm2-libs/M2Dependent.mod
gcc/m2/gm2-libs/RTExceptions.mod
gcc/m2/gm2-libs/RTint.mod
gcc/m2/gm2-libs/SFIO.mod
gcc/m2/gm2-libs/StringConvert.mod
gcc/testsuite/gm2/pim/fail/setunknown.mod [new file with mode: 0644]
gcc/testsuite/gm2/pim/fail/setunknown2.mod [new file with mode: 0644]

index 3cc1155..14e79e7 100644 (file)
@@ -126,7 +126,6 @@ VAR
    LongReal, ShortReal,
    Complex, LongComplex,
    ShortComplex,
-   Unbounded,
    High, LengthS,
    Cap, Abs, Odd,
    Convert, Val,
index efb808e..8a9d4d1 100644 (file)
@@ -226,7 +226,7 @@ PROCEDURE FlushWarnings ;
    ErrorAbort0 - aborts compiling, it flushes all warnings and errors before aborting.
 *)
 
-PROCEDURE ErrorAbort0 (a: ARRAY OF CHAR) ;
+PROCEDURE ErrorAbort0 (a: ARRAY OF CHAR) <* noreturn *> ;
 
 
 (*
index a44c5c7..df3e23f 100644 (file)
@@ -7232,12 +7232,12 @@ BEGIN
             GenQuadO (proctok, InclOp, VarSym, NulSym, DerefSym, FALSE)
          ELSE
             MetaErrorT1 (proctok,
-                         'the first parameter to {%EkINCL} must be a set variable but is {%E1d}',
+                         'the first parameter to {%EkINCL} must be a set variable but is {%1Ed}',
                          VarSym)
          END
       ELSE
          MetaErrorT1 (proctok,
-                      'base procedure {%EkINCL} expects a variable as a parameter but is {%E1d}',
+                      'base procedure {%EkINCL} expects a variable as a parameter but is {%1Ed}',
                       VarSym)
       END
    ELSE
@@ -7298,12 +7298,12 @@ BEGIN
             GenQuadO (proctok, ExclOp, VarSym, NulSym, DerefSym, FALSE)
          ELSE
             MetaErrorT1 (proctok,
-                         'the first parameter to {%EkEXCL} must be a set variable but is {%E1d}',
+                         'the first parameter to {%EkEXCL} must be a set variable but is {%1Ed}',
                          VarSym)
          END
       ELSE
          MetaErrorT1 (proctok,
-                      'base procedure {%EkEXCL} expects a variable as a parameter but is {%E1d}',
+                      'base procedure {%EkEXCL} expects a variable as a parameter but is {%1Ed}',
                       VarSym)
       END
    ELSE
@@ -9996,6 +9996,7 @@ BEGIN
          ELSE
             GenQuadO (combinedTok, AddrOp, returnVar, NulSym, OperandT (1), FALSE)
          END ;
+         PutWriteQuad (OperandT (1), GetMode (OperandT (1)), NextQuad-1) ;
          rw := OperandMergeRW (1) ;
          Assert (IsLegal (rw))
       END ;
index b6befbb..5b92c4c 100644 (file)
@@ -230,7 +230,7 @@ SysExceptions_InitExceptionHandlers (void *indexf, void *range, void *casef,
 /* GNU Modula-2 linking fodder.  */
 
 void
-_M2_SysExceptions_init (void)
+_M2_SysExceptions_init (int argc, char *argv[], char *envp[])
 {
 }
 
index f24a472..51cbbf7 100644 (file)
@@ -228,7 +228,7 @@ wrapc_isfinitef (float x)
 /* init - init/finish functions for the module */
 
 void
-_M2_wrapc_init ()
+_M2_wrapc_init (int argc, char *argv[], char *envp[])
 {
 }
 
index 68e9320..37a7ed8 100644 (file)
@@ -129,8 +129,6 @@ END writeNspace ;
 *)
 
 PROCEDURE DumpStringInfo (s: String; i: CARDINAL) ;
-VAR
-   t: String ;
 BEGIN
    IF s # NIL
    THEN
@@ -164,7 +162,6 @@ END stop ;
 PROCEDURE PopAllocationExemption (halt: BOOLEAN; e: String) : String ;
 VAR
    s: String ;
-   f: frame ;
    b: BOOLEAN ;
 BEGIN
    Init ;
index 94a1833..1f3e22e 100644 (file)
@@ -667,7 +667,6 @@ END ReadNBytes ;
 PROCEDURE BufferedRead (f: File; nBytes: CARDINAL; a: ADDRESS) : INTEGER ;
 VAR
    t     : ADDRESS ;
-   result: INTEGER ;
    total,
    n     : INTEGER ;
    p     : POINTER TO BYTE ;
@@ -1236,7 +1235,6 @@ END WriteNBytes ;
 PROCEDURE BufferedWrite (f: File; nBytes: CARDINAL; a: ADDRESS) : INTEGER ;
 VAR
    t     : ADDRESS ;
-   result: INTEGER ;
    total,
    n     : INTEGER ;
    p     : POINTER TO BYTE ;
index 38e4d21..9c3a562 100644 (file)
@@ -301,8 +301,7 @@ VAR
    c,
    width,
    nextperc,
-   afterperc,
-   endpos   : INTEGER ;
+   afterperc: INTEGER ;
    leader,
    ch, ch2  : CHAR ;
    p        : String ;
@@ -444,7 +443,6 @@ END Copy ;
 PROCEDURE HandlePercent (fmt, s: String; startpos: INTEGER) : String ;
 VAR
    prevpos: INTEGER ;
-   result : String ;
 BEGIN
    IF (startpos = VAL (INTEGER, Length (fmt))) OR (startpos < 0)
    THEN
index e152158..65c293c 100644 (file)
@@ -261,9 +261,9 @@ END IsIndiceInIndex ;
 
 PROCEDURE RemoveIndiceFromIndex (i: Index; a: ADDRESS) ;
 VAR
-   j, k: CARDINAL ;
-   p   : PtrToAddress ;
-   b   : PtrToByte ;
+   j: CARDINAL ;
+   p: PtrToAddress ;
+   b: PtrToByte ;
 BEGIN
    WITH i^ DO
       j := Low ;
index d3d2c50..052d2ce 100644 (file)
@@ -85,8 +85,7 @@ PROCEDURE CreateModule (name, libname: ADDRESS;
                         init, fini:  ArgCVEnvP;
                         dependencies: PROC) : ModuleChain ;
 VAR
-   mptr  : ModuleChain ;
-   p0, p1: ADDRESS ;
+   mptr: ModuleChain ;
 BEGIN
    NEW (mptr) ;
    mptr^.name := name ;
@@ -595,8 +594,6 @@ END DisplayModuleInfo ;
 *)
 
 PROCEDURE DumpModuleData (flag: BOOLEAN) ;
-VAR
-   mptr: ModuleChain ;
 BEGIN
    IF flag
    THEN
@@ -767,7 +764,6 @@ PROCEDURE ConstructModules (applicationmodule, libname,
                             argc: INTEGER; argv, envp: ADDRESS) ;
 VAR
    mptr: ModuleChain ;
-   nulp: ArgCVEnvP ;
 BEGIN
    CheckInitialized ;
    DynamicInitialization := TRUE ;  (* This procedure is only called if we desire dynamic initialization.  *)
index f28e4d8..7f3445c 100644 (file)
@@ -531,7 +531,7 @@ END PushHandler ;
 
 PROCEDURE PopHandler (e: EHBlock; number: CARDINAL) ;
 VAR
-   h, i: Handler ;
+   h: Handler ;
 BEGIN
    h := findHandler(e, number) ;
    IF h#NIL
index aec5a82..b3b8737 100644 (file)
@@ -673,10 +673,6 @@ VAR
    vec    : Vector ;
    inSet,
    outSet : SetOfFd ;
-   b4s,
-   b4m,
-   afs,
-   afm,
    sec,
    micro  : CARDINAL ;
    maxFd  : INTEGER ;
index 3cc294e..5e26f0f 100644 (file)
@@ -128,7 +128,6 @@ END WriteS ;
 PROCEDURE ReadS (file: File) : String ;
 VAR
    s: String ;
-   c: CARDINAL ;
 BEGIN
    s := InitString ('') ;
    WHILE (NOT EOLN (file)) AND (NOT EOF (file)) AND IsNoError (file) DO
index 93e2ece..e2208ca 100644 (file)
@@ -1099,8 +1099,6 @@ VAR
    i, l,
    point    : INTEGER ;
    t,
-   whole,
-   fraction,
    tenths,
    hundreths: String ;
 BEGIN
diff --git a/gcc/testsuite/gm2/pim/fail/setunknown.mod b/gcc/testsuite/gm2/pim/fail/setunknown.mod
new file mode 100644 (file)
index 0000000..112ebac
--- /dev/null
@@ -0,0 +1,8 @@
+MODULE setunknown ;
+
+
+VAR
+   set: SET OF [0..7] ;
+BEGIN
+   INCL (set, unknownVariable)
+END setunknown.
diff --git a/gcc/testsuite/gm2/pim/fail/setunknown2.mod b/gcc/testsuite/gm2/pim/fail/setunknown2.mod
new file mode 100644 (file)
index 0000000..f08a1ae
--- /dev/null
@@ -0,0 +1,5 @@
+MODULE setunknown2 ;
+
+BEGIN
+   INCL (unknownSet, unknownVariable)
+END setunknown2.