From eb619490b01baa2fc2b5ee98d15516c4a2372e74 Mon Sep 17 00:00:00 2001 From: Gaius Mulley Date: Fri, 26 Jan 2024 19:04:48 +0000 Subject: modula2: detect string and pointer formal and actual parameter incompatibility This patch improves the location accuracy of parameters and fixes bugs in parameter checking in M2Check. It also corrects the location of constant declarations. gcc/m2/ChangeLog: * gm2-compiler/M2Check.mod (dumpIndice): New procedure. (dumpIndex): New procedure. (dumptInfo): New procedure. (buildError4): Add comment and pass formal and actual to MetaError4. Improve text describing error. (buildError2): Generate different error descriptions for the three error kinds. (checkConstMeta): Add block comment. Add more meta checks and call doCheckPair to complete string const checking. Add tinfo parameter. (checkConstEquivalence): Add tinfo parameter. * gm2-compiler/M2GCCDeclare.mod (PrintVerboseFromList): Print the length of a const string. * gm2-compiler/M2GenGCC.mod (CodeParam): Remove parameters op1, op2 and op3. (doParam): Add paramtok parameter. Use paramtok instead rather than CurrentQuadToken. (CodeParam): Rewrite. * gm2-compiler/M2Quads.mod (CheckProcedureParameters): Add comments explaining that const strings are not checked in M2Quads.mod. (FailParameter): Use MetaErrorT2 with tokpos rather than MetaError2. (doBuildBinaryOp): Assign OldPos and OperatorPos before the IF block. * gm2-compiler/SymbolTable.mod (PutConstString): Add call to InitWhereDeclaredTok. gcc/testsuite/ChangeLog: * gm2/pim/fail/badpointer4.mod: New test. * gm2/pim/fail/strconst.def: New test. Signed-off-by: Gaius Mulley --- gcc/testsuite/gm2/pim/fail/badpointer4.mod | 20 ++++++++++++++++++++ gcc/testsuite/gm2/pim/fail/strconst.def | 6 ++++++ 2 files changed, 26 insertions(+) create mode 100644 gcc/testsuite/gm2/pim/fail/badpointer4.mod create mode 100644 gcc/testsuite/gm2/pim/fail/strconst.def (limited to 'gcc/testsuite/gm2') diff --git a/gcc/testsuite/gm2/pim/fail/badpointer4.mod b/gcc/testsuite/gm2/pim/fail/badpointer4.mod new file mode 100644 index 0000000..b5fb8ad --- /dev/null +++ b/gcc/testsuite/gm2/pim/fail/badpointer4.mod @@ -0,0 +1,20 @@ +MODULE badpointer4 ; + +FROM DynamicStrings IMPORT String ; +FROM strconst IMPORT Hello ; + + +PROCEDURE testproc (s: String) ; +BEGIN +END testproc ; + + +PROCEDURE foo ; +BEGIN + testproc (Hello) +END foo ; + + +BEGIN + foo +END badpointer4. diff --git a/gcc/testsuite/gm2/pim/fail/strconst.def b/gcc/testsuite/gm2/pim/fail/strconst.def new file mode 100644 index 0000000..867e006 --- /dev/null +++ b/gcc/testsuite/gm2/pim/fail/strconst.def @@ -0,0 +1,6 @@ +DEFINITION MODULE strconst ; + +CONST + Hello = "hello world" ; + +END strconst. -- cgit v1.1