PR-107959 bugfix ICE detect attempt to create aggregate constant using bad type
The module below causes an ICE.
MODULE badipv4 ;
TYPE
IPV4 = ARRAY [1..4] OF CHAR ;
CONST
Loopback = IPV4 {127, 0, 0, 1} ;
END badipv4.
The fix was to replace the internal error with a failure boolean and
issue error messages based on the constructor. It also required changes
propagating tokenno into the range checking code which is then passed
to M2ALU which generates the aggregate constant.
gcc/m2/ChangeLog:
* gm2-compiler/M2ALU.mod (CheckGetCharFromString): Return TRUE if
successful otherwise return FALSE and issue an error message.
Add extra parameter baseType.
(InitialiseArrayOfCharWith) Use CheckGetCharFromString and pass
baseType.
* gm2-compiler/M2Quads.def (StartBuildDefFile):
Add parameter tok. (StartBuildModFile) Add parameter tok.
(EndBuildFile) Add parameter tok.
(StartBuildInit) Add parameter tok.
(EndBuildInit) Add parameter tok.
(StartBuildFinally) Add parameter tok.
(EndBuildFinally) Add parameter tok.
(BuildExceptInitial) Add parameter tok.
(BuildExceptInitial) Add parameter tok.
(BuildExceptFinally) Add parameter tok.
(BuildExceptProcedure) Add parameter tok.
(BuildReThrow) Add parameter tok.
(StartBuildInnerInit) Add parameter tok.
(EndBuildInnerInit) Add parameter tok.
(BuildModuleStart) Add parameter tok.
(BuildModuleStart) Add parameter tok.
* gm2-compiler/M2Quads.mod (ForLoopInfo): Redefined as a pointer
to record. (ForInfo) Redefined as an Index.
(EndBuildFile) Add parameter tok.
(StartBuildInit) Add parameter tok.
(EndBuildInit) Add parameter tok.
(StartBuildFinally) Add parameter tok.
(EndBuildFinally) Add parameter tok.
(BuildExceptInitial) Add parameter tok.
(BuildExceptInitial) Add parameter tok.
(BuildExceptFinally) Add parameter tok.
(BuildExceptProcedure) Add parameter tok.
(BuildReThrow) Add parameter tok.
(StartBuildInnerInit) Add parameter tok.
(EndBuildInnerInit) Add parameter tok.
(BuildModuleStart) Add parameter tok.
(BuildModuleStart) Add parameter tok.
(ForLoopAnalysis): Use ForInfo Indexing
procedures and ForLoopInfo to check for loops.
(AddForInfo): Reimplemented using ForInfo and
Indexing procedures.
(CheckForIndex): Pass ForLoopInfo parameter.
Reimplemented.
(BuildEndFor): Add parameter to AddForInfo.
* gm2-compiler/M2Range.mod (FoldAssignment):
Use tokenNo in the Range when declaring constant.
(FoldParameterAssign) Use tokenNo in the Range
when declaring constant. (FoldReturn) Use tokenNo
in the Range when declaring constant.
(FoldReturn) Use tokenNo
in the Range when declaring constant.
* gm2-compiler/P3Build.bnf (ProgramModule) pass module
token and end token to respective build procedures.
(ImplementationModule) pass module
token and end token to respective build procedures.
(Block) Pass token to build routines.
(InitialBlockBody) Pass token to build routines.
(FinalBlockBody) Pass token to build routines.
(ProcedureBlockBody) Pass token to build routines.
(ModuleDeclaration) Pass token to build routines.
(DefinitionModule) Pass token to build routines.
* gm2-compiler/PHBuild.bnf (ProgramModule) pass module
token and end token to respective build procedures.
(ImplementationModule) pass module
token and end token to respective build procedures.
(Block) Pass token to build routines.
(InitialBlockBody) Pass token to build routines.
(FinalBlockBody) Pass token to build routines.
(ProcedureBlockBody) Pass token to build routines.
(ModuleDeclaration) Pass token to build routines.
(DefinitionModule) Pass token to build routines.