]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR modula2/114418 missing import of TSIZE from system causes ICE
authorGaius Mulley <gaiusmod2@gmail.com>
Thu, 21 Mar 2024 18:30:23 +0000 (18:30 +0000)
committerGaius Mulley <gaiusmod2@gmail.com>
Thu, 21 Mar 2024 18:30:23 +0000 (18:30 +0000)
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 <gaiusmod2@gmail.com>
gcc/m2/gm2-compiler/PCSymBuild.mod
gcc/testsuite/gm2/pim/fail/missingtsize.mod [new file with mode: 0644]
gcc/testsuite/gm2/pim/fail/missingtsize2.mod [new file with mode: 0644]

index e21654087812f08377073f7ccc5c62a8aa6f7fd3..9a6e8c06e70cacebd5802414baa0406a9f5b5f13 100644 (file)
@@ -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 (file)
index 0000000..23ec055
--- /dev/null
@@ -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 (file)
index 0000000..8e85944
--- /dev/null
@@ -0,0 +1,8 @@
+MODULE missingtsize2 ;
+
+CONST
+   NoOfBytes = TSIZE (CARDINAL) * 4 ;
+
+BEGIN
+
+END missingtsize2.
\ No newline at end of file