From: Gaius Mulley Date: Thu, 21 Mar 2024 18:30:23 +0000 (+0000) Subject: PR modula2/114418 missing import of TSIZE from system causes ICE X-Git-Tag: basepoints/gcc-15~541 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ba744d50ac0360f7992a42494db766f6548913e3;p=thirdparty%2Fgcc.git 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 --- diff --git a/gcc/m2/gm2-compiler/PCSymBuild.mod b/gcc/m2/gm2-compiler/PCSymBuild.mod index e21654087812..9a6e8c06e70c 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 000000000000..23ec055d7bee --- /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 000000000000..8e859445ab0a --- /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