https://gcc.gnu.org/g:ba744d50ac0360f7992a42494db766f6548913e3

commit r14-9598-gba744d50ac0360f7992a42494db766f6548913e3
Author: Gaius Mulley <gaiusm...@gmail.com>
Date:   Thu Mar 21 18:30:23 2024 +0000

    PR modula2/114418 missing import of TSIZE from system causes ICE
    
    This patch detects whether the symbol func is NulSym before generating
    an error and if so just uses the token location and fixed string to
    generate an error message.
    
    gcc/m2/ChangeLog:
    
            PR modula2/114418
            * gm2-compiler/PCSymBuild.mod (PushConstFunctionType): Check
            func against NulSym and issue an error.
    
    gcc/testsuite/ChangeLog:
    
            PR modula2/114418
            * gm2/pim/fail/missingtsize.mod: New test.
            * gm2/pim/fail/missingtsize2.mod: New test.
    
    Signed-off-by: Gaius Mulley <gaiusm...@gmail.com>

Diff:
---
 gcc/m2/gm2-compiler/PCSymBuild.mod           | 48 +++++++++++++++++++++-------
 gcc/testsuite/gm2/pim/fail/missingtsize.mod  |  8 +++++
 gcc/testsuite/gm2/pim/fail/missingtsize2.mod |  8 +++++
 3 files changed, 53 insertions(+), 11 deletions(-)

diff --git a/gcc/m2/gm2-compiler/PCSymBuild.mod 
b/gcc/m2/gm2-compiler/PCSymBuild.mod
index e2165408781..9a6e8c06e70 100644
--- a/gcc/m2/gm2-compiler/PCSymBuild.mod
+++ b/gcc/m2/gm2-compiler/PCSymBuild.mod
@@ -1412,6 +1412,38 @@ BEGIN
 END buildConstFunction ;
 
 
+(*
+   ErrorConstFunction - generate an error message at functok using func in the
+                        error message providing it is not NulSym.
+*)
+
+PROCEDURE ErrorConstFunction (func: CARDINAL; functok: CARDINAL) ;
+BEGIN
+   IF func = NulSym
+   THEN
+      IF Iso
+      THEN
+         ErrorFormat0 (NewError (functok),
+                       'the only functions permissible in a constant 
expression are: CAP, CHR, CMPLX, FLOAT, HIGH, IM, LENGTH, MAX, MIN, ODD, ORD, 
RE, SIZE, TSIZE, TRUNC, VAL and gcc builtins')
+      ELSE
+         ErrorFormat0 (NewError (functok),
+                       'the only functions permissible in a constant 
expression are: CAP, CHR, FLOAT, HIGH, MAX, MIN, ODD, ORD, SIZE, TSIZE, TRUNC, 
VAL and gcc builtins')
+      END
+   ELSE
+      IF Iso
+      THEN
+         MetaErrorT1 (functok,
+                      'the only functions permissible in a constant expression 
are: CAP, CHR, CMPLX, FLOAT, HIGH, IM, LENGTH, MAX, MIN, ODD, ORD, RE, SIZE, 
TSIZE, TRUNC, VAL and gcc builtins, but not {%1Ead}',
+                      func)
+      ELSE
+         MetaErrorT1 (functok,
+                      'the only functions permissible in a constant expression 
are: CAP, CHR, FLOAT, HIGH, MAX, MIN, ODD, ORD, SIZE, TSIZE, TRUNC, VAL and gcc 
builtins, but not {%1Ead}',
+                      func)
+      END
+   END
+END ErrorConstFunction ;
+
+
 (*
    PushConstFunctionType -
 *)
@@ -1426,7 +1458,10 @@ BEGIN
    PopTtok (func, functok) ;
    IF inDesignator
    THEN
-      IF (func#Convert) AND
+      IF func = NulSym
+      THEN
+         ErrorConstFunction (func, functok)
+      ELSIF (func#Convert) AND
          (IsPseudoBaseFunction(func) OR
           IsPseudoSystemFunctionConstExpression(func) OR
           (IsProcedure(func) AND IsProcedureBuiltin(func)))
@@ -1442,16 +1477,7 @@ BEGIN
             WriteFormat0('a constant type conversion can only have one 
argument')
          END
       ELSE
-         IF Iso
-         THEN
-            MetaErrorT1 (functok,
-                         'the only functions permissible in a constant 
expression are: CAP, CHR, CMPLX, FLOAT, HIGH, IM, LENGTH, MAX, MIN, ODD, ORD, 
RE, SIZE, TSIZE, TRUNC, VAL and gcc builtins, but not {%1Ead}',
-                        func)
-         ELSE
-            MetaErrorT1 (functok,
-                         'the only functions permissible in a constant 
expression are: CAP, CHR, FLOAT, HIGH, MAX, MIN, ODD, ORD, SIZE, TSIZE, TRUNC, 
VAL and gcc builtins, but not {%1Ead}',
-                        func)
-         END
+         ErrorConstFunction (func, functok)
       END
    END ;
    PushTtok (func, functok)
diff --git a/gcc/testsuite/gm2/pim/fail/missingtsize.mod 
b/gcc/testsuite/gm2/pim/fail/missingtsize.mod
new file mode 100644
index 00000000000..23ec055d7be
--- /dev/null
+++ b/gcc/testsuite/gm2/pim/fail/missingtsize.mod
@@ -0,0 +1,8 @@
+MODULE missingtsize ;
+
+CONST
+   NoOfBytes = TSIZE (CARDINAL) ;
+
+BEGIN
+
+END missingtsize.
diff --git a/gcc/testsuite/gm2/pim/fail/missingtsize2.mod 
b/gcc/testsuite/gm2/pim/fail/missingtsize2.mod
new file mode 100644
index 00000000000..8e859445ab0
--- /dev/null
+++ b/gcc/testsuite/gm2/pim/fail/missingtsize2.mod
@@ -0,0 +1,8 @@
+MODULE missingtsize2 ;
+
+CONST
+   NoOfBytes = TSIZE (CARDINAL) * 4 ;
+
+BEGIN
+
+END missingtsize2.
\ No newline at end of file

Reply via email to