]> git.ipfire.org Git - thirdparty/gcc.git/commit
PR modula2/116048 ICE when encountering wrong kind of qualident
authorGaius Mulley <gaiusmod2@gmail.com>
Tue, 23 Jul 2024 14:54:16 +0000 (15:54 +0100)
committerGaius Mulley <gaiusmod2@gmail.com>
Tue, 23 Jul 2024 14:54:16 +0000 (15:54 +0100)
commit7f8064ff0e2ac90c5bb6c30cc61acc5a28ebbe4c
tree6d9caf1a7bb5f61b74a1bed221835fe3abc03f76
parent826134760c49518d97769c8bb7ecbc264b78cac9
PR modula2/116048 ICE when encountering wrong kind of qualident

Following on from PR-115957 further ICEs can be generated by using the
wrong kind of qualident symbol.  For example using a variable instead of
a type or using a type instead of a const.  This fix tracks the expected
qualident kind state when parsing const, type and variable declarations.
If the error is unrecoverable then a detailed message explaining the
context of the qualident (and why the seen qualident is wrong) is
generated.

gcc/m2/ChangeLog:

PR modula2/116048
* Make-lang.in (GM2-COMP-BOOT-DEFS): Add M2StateCheck.def.
(GM2-COMP-BOOT-MODS): Add M2StateCheck.mod.
(GM2-COMP-DEFS): Add M2StateCheck.def.
(GM2-COMP-MODS): Add M2StateCheck.mod.
* gm2-compiler/M2Quads.mod (StartBuildWith): Generate
unrecoverable error is the qualident type is NulSym.
Replace MetaError1 with MetaErrorT1 and position the error
to the qualident.
* gm2-compiler/P3Build.bnf (M2StateCheck): Import procedures.
(seenError): New variable.
(WasNoError): Remove variable.
(BlockState): New variable.
(ErrorString): Rewrite using seenError.
(CompilationUnit): Ditto.
(QualidentCheck): New rule.
(ConstantDeclaration): Bookend with InclConst and ExclConst.
(Constructor): Add InclConstructor, ExclConstructor and call
CheckQualident.
(ConstActualParameters): Call PushState, PopState, InclConstFunc
and CheckQualident.
(TypeDeclaration): Bookend with InclType and ExclType.
(SimpleType): Call QualidentCheck.
(CaseTag): Ditto.
(OptReturnType): Ditto.
(VariableDeclaration): Bookend with InclVar and ExclVar.
(Designator): Call QualidentCheck.
(Formal;Type): Ditto.
* gm2-compiler/PCBuild.bnf (M2StateCheck): Import procedures.
(ConstantDeclaration): Rewrite using InclConst and ExclConst.
(Constructor): Bookend with InclConstructor and ExclConstructor.
Call CheckQualident.
(ConstructorOrConstActualParameters): Rewrite and cal
l CheckQualident.
(ConstActualParameters): Bookend with PushState PopState.
Call InclConstFunc and CheckQualident.
* gm2-gcc/init.cc (_M2_M2StateCheck_init): New declaration.
(_M2_P3Build_init): New declaration.
(init_PerCompilationInit): Call _M2_M2StateCheck_init and
_M2_P3Build_init.
* gm2-compiler/M2StateCheck.def: New file.
* gm2-compiler/M2StateCheck.mod: New file.

gcc/testsuite/ChangeLog:

PR modula2/116048
* gm2/errors/fail/errors-fail.exp: Remove -Wstudents
and add -Wuninit-variable-checking=all.
Replace gm2_init_pim with gm2_init_iso.
* gm2/errors/fail/testfio.mod: Modify test code to
provoke an error in the first basic block.
* gm2/errors/fail/testparam.mod: Ditto.
* gm2/errors/fail/array1.mod: Ditto.
* gm2/errors/fail/badtype.mod: New test.
* gm2/errors/fail/badvar.mod: New test.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
13 files changed:
gcc/m2/Make-lang.in
gcc/m2/gm2-compiler/M2Quads.mod
gcc/m2/gm2-compiler/M2StateCheck.def [new file with mode: 0644]
gcc/m2/gm2-compiler/M2StateCheck.mod [new file with mode: 0644]
gcc/m2/gm2-compiler/P3Build.bnf
gcc/m2/gm2-compiler/PCBuild.bnf
gcc/m2/gm2-gcc/init.cc
gcc/testsuite/gm2/errors/fail/array1.mod
gcc/testsuite/gm2/errors/fail/badtype.mod [new file with mode: 0644]
gcc/testsuite/gm2/errors/fail/badvar.mod [new file with mode: 0644]
gcc/testsuite/gm2/errors/fail/errors-fail.exp
gcc/testsuite/gm2/errors/fail/testfio.mod
gcc/testsuite/gm2/errors/fail/testparam.mod