]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR modula2/114807 badpointer3.mod causes an ICE
authorGaius Mulley <gaiusmod2@gmail.com>
Mon, 22 Apr 2024 17:19:32 +0000 (18:19 +0100)
committerGaius Mulley <gaiusmod2@gmail.com>
Mon, 22 Apr 2024 17:19:32 +0000 (18:19 +0100)
This patch fixes an ICE caused when a constant string
is built and attempted to be passed into a procedure with
an opaque type.

gcc/m2/ChangeLog:

PR modula2/114807
* gm2-compiler/M2Check.mod (checkUnbounded): Remove unused
local variables.
(constCheckMeta): Include check for IsReallyPointer in the
failure case.
* gm2-compiler/M2Quads.mod (MoveWithMode): Remove CopyConstString.
* gm2-compiler/SymbolTable.def (IsHiddenReallyPointer): Export.
* gm2-compiler/SymbolTable.mod (SkipHiddenType): Remove.
(IsReallyPointer): Include IsHiddenReallyPointer test.

gcc/testsuite/ChangeLog:

PR modula2/114807
* gm2/pim/fail/badproctype.mod: Change MYSHORTREAL
to SHORTREAL.
* gm2/pim/fail/badprocbool.mod: New test.
* gm2/pim/fail/badproccard.mod: New test.
* gm2/pim/fail/badprocint.mod: New test.
* gm2/pim/fail/badprocint2.mod: New test.
* gm2/pim/pass/goodproccard2.mod: New test.
* gm2/pim/pass/goodprocint.mod: New test.
* gm2/pim/pass/goodprocint3.mod: New test.
* gm2/pim/run/pass/genconststr.mod: New test.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
13 files changed:
gcc/m2/gm2-compiler/M2Check.mod
gcc/m2/gm2-compiler/M2Quads.mod
gcc/m2/gm2-compiler/SymbolTable.def
gcc/m2/gm2-compiler/SymbolTable.mod
gcc/testsuite/gm2/pim/fail/badprocbool.mod [new file with mode: 0644]
gcc/testsuite/gm2/pim/fail/badproccard.mod [new file with mode: 0644]
gcc/testsuite/gm2/pim/fail/badprocint.mod [new file with mode: 0644]
gcc/testsuite/gm2/pim/fail/badprocint2.mod [new file with mode: 0644]
gcc/testsuite/gm2/pim/fail/badproctype.mod
gcc/testsuite/gm2/pim/pass/goodproccard2.mod [new file with mode: 0644]
gcc/testsuite/gm2/pim/pass/goodprocint.mod [new file with mode: 0644]
gcc/testsuite/gm2/pim/pass/goodprocint3.mod [new file with mode: 0644]
gcc/testsuite/gm2/pim/run/pass/genconststr.mod [new file with mode: 0644]

index a4451938b88480cbb6c4c2046be12b19dab7d90a..1750fe07ecf1fa476f0085bcfe7802ac80550e1d 100644 (file)
@@ -47,7 +47,8 @@ FROM SymbolTable IMPORT NulSym, IsRecord, IsSet, GetDType, GetSType, IsType,
                         IsReallyPointer, IsPointer, IsParameter, ModeOfAddr,
                         GetMode, GetType, IsUnbounded, IsComposite, IsConstructor,
                         IsParameter, IsConstString, IsConstLitInternal, IsConstLit,
-                        GetStringLength, GetProcedureProcType ;
+                        GetStringLength, GetProcedureProcType, IsHiddenType,
+                        IsHiddenReallyPointer ;
 
 FROM M2GCCDeclare IMPORT GetTypeMin, GetTypeMax ;
 FROM M2System IMPORT Address ;
@@ -264,9 +265,6 @@ END checkSubrange ;
 *)
 
 PROCEDURE checkUnbounded (result: status; tinfo: tInfo; unbounded, right: CARDINAL) : status ;
-VAR
-   lLow,  rLow,
-   lHigh, rHigh: CARDINAL ;
 BEGIN
    (* Firstly check to see if we have resolved this as false.  *)
    IF isFalse (result)
@@ -683,7 +681,8 @@ BEGIN
          THEN
             RETURN result
          ELSIF IsSet (typeRight) OR IsEnumeration (typeRight) OR
-               IsProcedure (typeRight) OR IsRecord (typeRight)
+               IsProcedure (typeRight) OR IsRecord (typeRight) OR
+               IsReallyPointer (typeRight)
          THEN
             RETURN false
          ELSIF IsArray (typeRight)
index 68b91201702e5ea51dac1f2c838ce631f7ee7624..8a9a23013b253191aef8d3d3c7595fa5723175a8 100644 (file)
@@ -73,7 +73,7 @@ FROM SymbolTable IMPORT ModeOfAddr, GetMode, PutMode, GetSymName, IsUnknown,
                         GetModuleQuads, GetProcedureQuads,
                         GetModuleCtors,
                         MakeProcedure,
-                        CopyConstString, PutConstStringKnown,
+                        PutConstStringKnown,
                         PutModuleStartQuad, PutModuleEndQuad,
                         PutModuleFinallyStartQuad, PutModuleFinallyEndQuad,
                         PutProcedureStartQuad, PutProcedureEndQuad,
@@ -3454,7 +3454,6 @@ BEGIN
    THEN
       GenQuadOtok (tokno, BecomesOp, Des, NulSym, Exp, TRUE,
                    destok, UnknownTokenNo, exptok) ;
-      CopyConstString (tokno, Des, Exp)
    ELSE
       IF GetMode(Des)=RightValue
       THEN
index d7f0f8d943c5cadcee83a4dcdef2ffb97e311e0c..06f8a22756327f7533c062cd78df8caa4b8609e4 100644 (file)
@@ -3036,6 +3036,14 @@ PROCEDURE PutHiddenTypeDeclared ;
 PROCEDURE IsHiddenTypeDeclared (Sym: CARDINAL) : BOOLEAN ;
 
 
+(*
+   IsHiddenReallyPointer - returns TRUE is sym is a pointer, address or a
+                           type declared as a pointer or address.
+*)
+
+PROCEDURE IsHiddenReallyPointer (Sym: CARDINAL) : BOOLEAN ;
+
+
 (*
    DisplayTrees - displays the SymbolTrees for Module symbol, ModSym.
 *)
index 7543bb52749725d12f4e6b535774b58ba806f20a..f5890ec684fe1c45c662f8aa00746119b4285341 100644 (file)
@@ -8014,36 +8014,15 @@ END CheckForHiddenType ;
 
 PROCEDURE IsReallyPointer (Sym: CARDINAL) : BOOLEAN ;
 BEGIN
-   IF IsVar(Sym)
+   IF IsVar (Sym)
    THEN
-      Sym := GetType(Sym)
+      Sym := GetType (Sym)
    END ;
-   Sym := SkipType(Sym) ;
-   RETURN( IsPointer(Sym) OR (Sym=Address) )
+   Sym := SkipType (Sym) ;
+   RETURN IsPointer (Sym) OR (Sym = Address) OR IsHiddenReallyPointer (Sym)
 END IsReallyPointer ;
 
 
-(*
-   SkipHiddenType - if sym is a TYPE foo = bar
-                    then call SkipType(bar)
-                    else return sym
-
-                    it does skip over hidden type.
-*)
-
-(*
-PROCEDURE SkipHiddenType (Sym: CARDINAL) : CARDINAL ;
-BEGIN
-   IF (Sym#NulSym) AND IsType(Sym) AND (GetType(Sym)#NulSym)
-   THEN
-      RETURN( SkipType(GetType(Sym)) )
-   ELSE
-      RETURN( Sym )
-   END
-END SkipHiddenType ;
-*)
-
-
 (*
    IsHiddenReallyPointer - returns TRUE is sym is a pointer, address or a
                            type declared as a pointer or address.
diff --git a/gcc/testsuite/gm2/pim/fail/badprocbool.mod b/gcc/testsuite/gm2/pim/fail/badprocbool.mod
new file mode 100644 (file)
index 0000000..63bb034
--- /dev/null
@@ -0,0 +1,13 @@
+MODULE badprocbool ;
+
+FROM NumberIO IMPORT WriteCard ;
+FROM StrIO IMPORT WriteString, WriteLn ;
+
+PROCEDURE Func () : BOOLEAN ;
+BEGIN
+   RETURN TRUE
+END Func ;
+
+BEGIN
+   WriteString ('the value is: ') ; WriteCard (Func (), 5) ; WriteLn
+END badprocbool.
diff --git a/gcc/testsuite/gm2/pim/fail/badproccard.mod b/gcc/testsuite/gm2/pim/fail/badproccard.mod
new file mode 100644 (file)
index 0000000..3a6b8e5
--- /dev/null
@@ -0,0 +1,13 @@
+MODULE badproccard ;
+
+FROM NumberIO IMPORT WriteCard ;
+FROM StrIO IMPORT WriteString, WriteLn ;
+
+PROCEDURE func () : CARDINAL ;
+BEGIN
+   RETURN 42
+END func ;
+
+BEGIN
+   WriteString ('the value is: ') ; WriteCard (func, 5) ; WriteLn
+END badproccard.
diff --git a/gcc/testsuite/gm2/pim/fail/badprocint.mod b/gcc/testsuite/gm2/pim/fail/badprocint.mod
new file mode 100644 (file)
index 0000000..c06241b
--- /dev/null
@@ -0,0 +1,17 @@
+MODULE badprocint ;
+
+FROM StrIO IMPORT WriteString, WriteLn ;
+
+PROCEDURE func () : INTEGER ;
+BEGIN
+   RETURN 42
+END func ;
+
+PROCEDURE PassRef (VAR x: CARDINAL) ;
+BEGIN
+END PassRef ;
+
+
+BEGIN
+   WriteString ('the value is: ') ; PassRef (func ()) ; WriteLn
+END badprocint.
diff --git a/gcc/testsuite/gm2/pim/fail/badprocint2.mod b/gcc/testsuite/gm2/pim/fail/badprocint2.mod
new file mode 100644 (file)
index 0000000..4d2901e
--- /dev/null
@@ -0,0 +1,14 @@
+MODULE badprocint2 ;
+
+FROM StrIO IMPORT WriteString, WriteLn ;
+
+PROCEDURE PassRef (VAR x: CARDINAL) ;
+BEGIN
+END PassRef ;
+
+VAR
+   i: INTEGER ;
+BEGIN
+   i := 42 ;
+   WriteString ('the value is: ') ; PassRef (i) ; WriteLn
+END badprocint2.
index 1921a8e2785cfa1c600da6faf8b5dddb6bfb15f9..cff3a31db8e2571085813cd4cf2717f7842a52b2 100644 (file)
@@ -1,22 +1,19 @@
 MODULE badproctype ;
 
-TYPE
-   MYSHORTREAL = REAL;
-
 TYPE
    PROCA = PROCEDURE (VAR ARRAY OF REAL);
-   PROCB = PROCEDURE (VAR ARRAY OF MYSHORTREAL);
+   PROCB = PROCEDURE (VAR ARRAY OF SHORTREAL);
 
 VAR
    pa: PROCA; pb: PROCB;
    x: ARRAY [0..1] OF REAL;
-   y: ARRAY [0..1] OF MYSHORTREAL;
+   y: ARRAY [0..1] OF SHORTREAL;
 
 PROCEDURE ProcA(VAR z: ARRAY OF REAL);
 BEGIN
 END ProcA ;
 
-PROCEDURE ProcB(VAR z: ARRAY OF MYSHORTREAL);
+PROCEDURE ProcB(VAR z: ARRAY OF SHORTREAL);
 BEGIN
 END ProcB ;
 
diff --git a/gcc/testsuite/gm2/pim/pass/goodproccard2.mod b/gcc/testsuite/gm2/pim/pass/goodproccard2.mod
new file mode 100644 (file)
index 0000000..f2f5c6e
--- /dev/null
@@ -0,0 +1,16 @@
+MODULE badproccard2 ;
+
+FROM StrIO IMPORT WriteString, WriteLn ;
+
+PROCEDURE func () : INTEGER ;
+BEGIN
+   RETURN 42
+END func ;
+
+PROCEDURE PassValue (x: CARDINAL) ;
+BEGIN
+END PassValue ;
+
+BEGIN
+   WriteString ('the value is: ') ; PassValue (func ()) ; WriteLn
+END badproccard2.
diff --git a/gcc/testsuite/gm2/pim/pass/goodprocint.mod b/gcc/testsuite/gm2/pim/pass/goodprocint.mod
new file mode 100644 (file)
index 0000000..2ace578
--- /dev/null
@@ -0,0 +1,13 @@
+MODULE goodprocint ;
+
+FROM NumberIO IMPORT WriteCard ;
+FROM StrIO IMPORT WriteString, WriteLn ;
+
+PROCEDURE func () : INTEGER ;
+BEGIN
+   RETURN 42
+END func ;
+
+BEGIN
+   WriteString ('the value is: ') ; WriteCard (func (), 5) ; WriteLn
+END goodprocint.
diff --git a/gcc/testsuite/gm2/pim/pass/goodprocint3.mod b/gcc/testsuite/gm2/pim/pass/goodprocint3.mod
new file mode 100644 (file)
index 0000000..fcc1e73
--- /dev/null
@@ -0,0 +1,14 @@
+MODULE goodprocint3 ;
+
+FROM StrIO IMPORT WriteString, WriteLn ;
+
+PROCEDURE PassValue (x: CARDINAL) ;
+BEGIN
+END PassValue ;
+
+VAR
+   i: INTEGER ;
+BEGIN
+   i := 42 ;
+   WriteString ('the value is: ') ; PassValue (i) ; WriteLn
+END goodprocint3.
diff --git a/gcc/testsuite/gm2/pim/run/pass/genconststr.mod b/gcc/testsuite/gm2/pim/run/pass/genconststr.mod
new file mode 100644 (file)
index 0000000..d8fa842
--- /dev/null
@@ -0,0 +1,23 @@
+MODULE genconststr ;
+
+FROM libc IMPORT printf, exit ;
+FROM StrLib IMPORT StrEqual ;
+
+CONST
+   foo = hello + space + world ;
+   hello = "hello" ;
+   space = " " ;
+   world = "world" ;
+
+PROCEDURE test (a: ARRAY OF CHAR) ;
+BEGIN
+   IF NOT StrEqual (a, "hello world")
+   THEN
+      printf ("const string failed\n");
+      exit (1)
+   END
+END test ;
+
+BEGIN
+   test (foo)
+END genconststr.