[gcc r15-1886] PR modula2/115804 ICE during gimplification with new isfinite optab

2024-07-07 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:4594d555aa551a9998fc921363c5f6ea50630d5c

commit r15-1886-g4594d555aa551a9998fc921363c5f6ea50630d5c
Author: Gaius Mulley 
Date:   Sun Jul 7 22:42:51 2024 +0100

PR modula2/115804 ICE during gimplification with new isfinite optab

The calls to five m2 builtins have the incorrect return type.
This was detected when adding isfinitedf2 optab to the s390
backend which results in ICEs during gimplification in the
gm2 testsuite.

gcc/m2/ChangeLog:

PR modula2/115804
* gm2-gcc/m2builtins.cc (builtin_function_entry): Add GTY.
(DoBuiltinMemCopy): Add rettype and use rettype in the call.
(DoBuiltinAlloca): Ditto.
(DoBuiltinIsfinite): Ditto.
(DoBuiltinIsnan): Ditto.
(m2builtins_BuiltInHugeVal): Ditto.
(m2builtins_BuiltInHugeValShort): Ditto.
(m2builtins_BuiltInHugeValLong): Ditto.

Co-Authored-By: Stefan Schulze Frielinghaus  
Co-Authored-By: Andrew Pinski  

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-gcc/m2builtins.cc | 26 +++---
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/gcc/m2/gm2-gcc/m2builtins.cc b/gcc/m2/gm2-gcc/m2builtins.cc
index cfb4751e15a..31c344c4a59 100644
--- a/gcc/m2/gm2-gcc/m2builtins.cc
+++ b/gcc/m2/gm2-gcc/m2builtins.cc
@@ -138,7 +138,7 @@ struct builtin_function_entry
 /* Entries are added by examining gcc/builtins.def and copying those
functions which can be applied to Modula-2.  */
 
-static struct builtin_function_entry list_of_builtins[] = {
+static struct GTY(()) builtin_function_entry list_of_builtins[] = {
   { "__builtin_alloca", BT_FN_PTR_SIZE, BUILT_IN_ALLOCA, BUILT_IN_NORMAL,
 "alloca", NULL, NULL, bf_extension_lib },
   { "__builtin_memcpy", BT_FN_TRAD_PTR_PTR_CONST_PTR_SIZE, BUILT_IN_MEMCPY,
@@ -1007,10 +1007,11 @@ static tree
 DoBuiltinMemCopy (location_t location, tree dest, tree src, tree bytes)
 {
   tree functype = TREE_TYPE (gm2_memcpy_node);
+  tree rettype = TREE_TYPE (functype);
   tree funcptr
   = build1 (ADDR_EXPR, build_pointer_type (functype), gm2_memcpy_node);
   tree call
-  = m2treelib_DoCall3 (location, ptr_type_node, funcptr, dest, src, bytes);
+  = m2treelib_DoCall3 (location, rettype, funcptr, dest, src, bytes);
   return call;
 }
 
@@ -1018,10 +1019,10 @@ static tree
 DoBuiltinAlloca (location_t location, tree bytes)
 {
   tree functype = TREE_TYPE (gm2_alloca_node);
+  tree rettype = TREE_TYPE (functype);
   tree funcptr
   = build1 (ADDR_EXPR, build_pointer_type (functype), gm2_alloca_node);
-  tree call = m2treelib_DoCall1 (location, ptr_type_node, funcptr, bytes);
-
+  tree call = m2treelib_DoCall1 (location, rettype, funcptr, bytes);
   return call;
 }
 
@@ -1029,10 +1030,10 @@ static tree
 DoBuiltinIsfinite (location_t location, tree value)
 {
   tree functype = TREE_TYPE (gm2_isfinite_node);
+  tree rettype = TREE_TYPE (functype);
   tree funcptr
   = build1 (ADDR_EXPR, build_pointer_type (functype), gm2_isfinite_node);
-  tree call = m2treelib_DoCall1 (location, ptr_type_node, funcptr, value);
-
+  tree call = m2treelib_DoCall1 (location, rettype, funcptr, value);
   return call;
 }
 
@@ -1040,10 +1041,10 @@ static tree
 DoBuiltinIsnan (location_t location, tree value)
 {
   tree functype = TREE_TYPE (gm2_isnan_node);
+  tree rettype = TREE_TYPE (functype);
   tree funcptr
   = build1 (ADDR_EXPR, build_pointer_type (functype), gm2_isnan_node);
-  tree call = m2treelib_DoCall1 (location, ptr_type_node, funcptr, value);
-
+  tree call = m2treelib_DoCall1 (location, rettype, funcptr, value);
   return call;
 }
 
@@ -1051,9 +1052,10 @@ tree
 m2builtins_BuiltInHugeVal (location_t location)
 {
   tree functype = TREE_TYPE (gm2_huge_val_node);
+  tree rettype = TREE_TYPE (functype);
   tree funcptr
   = build1 (ADDR_EXPR, build_pointer_type (functype), gm2_huge_val_node);
-  tree call = m2treelib_DoCall0 (location, ptr_type_node, funcptr);
+  tree call = m2treelib_DoCall0 (location, rettype, funcptr);
   return call;
 }
 
@@ -1061,9 +1063,10 @@ tree
 m2builtins_BuiltInHugeValShort (location_t location)
 {
   tree functype = TREE_TYPE (gm2_huge_valf_node);
+  tree rettype = TREE_TYPE (functype);
   tree funcptr
   = build1 (ADDR_EXPR, build_pointer_type (functype), gm2_huge_valf_node);
-  tree call = m2treelib_DoCall0 (location, ptr_type_node, funcptr);
+  tree call = m2treelib_DoCall0 (location, rettype, funcptr);
   return call;
 }
 
@@ -1071,9 +1074,10 @@ tree
 m2builtins_BuiltInHugeValLong (location_t location)
 {
   tree functype = TREE_TYPE (gm2_huge_vall_node);
+  tree rettype = TREE_TYPE (functype);
   tree funcptr
   = build1 (ADDR_EXPR, build_pointer_type (functype), gm2_huge_vall_node);
-  tree call = m2treelib_DoCall0 (location, ptr_type_node, funcptr);
+  tree call = m2treelib_DoCall0 (location, rettype, funcptr);
   return call;
 }


[gcc r15-1940] PR modula2/115823 Wrong expansion of isnormal optab

2024-07-10 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:2d1f68e7965795dc66db83bc7840ba7a23eeb01b

commit r15-1940-g2d1f68e7965795dc66db83bc7840ba7a23eeb01b
Author: Gaius Mulley 
Date:   Wed Jul 10 15:52:37 2024 +0100

PR modula2/115823 Wrong expansion of isnormal optab

The bug fix changes gcc/m2/gm2-gcc/m2builtins.c:m2builtins_BuiltinExists
to recognise both __builtin_ and functionname as a builtin.

gcc/m2/ChangeLog:

PR modula2/115823
* gm2-gcc/m2builtins.cc (struct builtin_macro_definition): New
field builtinname.
(builtin_function_match): New function.
(builtin_macro_match): Ditto.
(m2builtins_BuiltinExists): Use builtin_function_match and
builtin_macro_match.
(lookup_builtin_macro): Use builtin_macro_match.
(lookup_builtin_function): Use builtin_function_match.
(define_builtin): Assign builtinname field.

gcc/testsuite/ChangeLog:

PR modula2/115823
* gm2/builtins/run/pass/testalloa.mod: New test.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-gcc/m2builtins.cc  | 31 ---
 gcc/testsuite/gm2/builtins/run/pass/testalloa.mod | 47 +++
 2 files changed, 73 insertions(+), 5 deletions(-)

diff --git a/gcc/m2/gm2-gcc/m2builtins.cc b/gcc/m2/gm2-gcc/m2builtins.cc
index 31c344c4a59e..e3e55a699917 100644
--- a/gcc/m2/gm2-gcc/m2builtins.cc
+++ b/gcc/m2/gm2-gcc/m2builtins.cc
@@ -396,6 +396,7 @@ struct builtin_type_info
 struct GTY(()) builtin_macro_definition
 {
   const char *name;
+  const char *builtinname;
   tree function_node;
   tree return_node;
 };
@@ -911,6 +912,26 @@ target_support_exists (struct builtin_function_entry *fe)
 }
 }
 
+/* Return true if name matches the builtin name.  */
+
+static
+bool builtin_function_match (struct builtin_function_entry *fe,
+const char *name)
+{
+  return (strcmp (name, fe->name) == 0)
+|| (strcmp (name, fe->library_name) == 0);
+}
+
+/* Return true if name matches the builtin macro name.  */
+
+static
+bool builtin_macro_match (builtin_macro_definition bmd,
+ const char *name)
+{
+  return (strcmp (bmd.name, name) == 0)
+|| (strcmp (bmd.builtinname, name) == 0);
+}
+
 
 /* BuiltinExists - returns TRUE if the builtin function, name, exists
for this target architecture.  */
@@ -921,12 +942,11 @@ m2builtins_BuiltinExists (char *name)
   struct builtin_function_entry *fe;
 
   for (fe = &list_of_builtins[0]; fe->name != NULL; fe++)
-if (strcmp (name, fe->name) == 0)
+if (builtin_function_match (fe, name))
   return true;
-  // return target_support_exists (fe);
   int length = vec_safe_length (builtin_macros);
   for (int idx = 0; idx < length; idx++)
-if (strcmp ((*builtin_macros)[idx].name, name) == 0)
+if (builtin_macro_match ((*builtin_macros)[idx], name))
   return true;
   return false;
 }
@@ -939,7 +959,7 @@ lookup_builtin_macro (location_t location, char *name)
 {
   int length = vec_safe_length (builtin_macros);
   for (int idx = 0; idx < length; idx++)
-if (strcmp ((*builtin_macros)[idx].name, name) == 0)
+if (builtin_macro_match ((*builtin_macros)[idx], name))
   {
 tree functype = TREE_TYPE ((*builtin_macros)[idx].function_node);
 tree funcptr = build1 (ADDR_EXPR, build_pointer_type (functype),
@@ -965,7 +985,7 @@ lookup_builtin_function (location_t location, char *name)
   struct builtin_function_entry *fe;
 
   for (fe = &list_of_builtins[0]; fe->name != NULL; fe++)
-if ((strcmp (name, fe->name) == 0) && target_support_exists (fe))
+if (builtin_function_match (fe, name) && target_support_exists (fe))
   {
 tree functype = TREE_TYPE (fe->function_node);
 tree funcptr = build1 (ADDR_EXPR, build_pointer_type (functype),
@@ -1422,6 +1442,7 @@ define_builtin (enum built_in_function val, const char 
*name, tree prototype,
   set_call_expr_flags (decl, flags);
   set_builtin_decl (val, decl, true);
   bmd.name = name;
+  bmd.builtinname = libname;
   bmd.function_node = decl;
   bmd.return_node = TREE_TYPE (prototype);
   vec_safe_push (builtin_macros, bmd);
diff --git a/gcc/testsuite/gm2/builtins/run/pass/testalloa.mod 
b/gcc/testsuite/gm2/builtins/run/pass/testalloa.mod
new file mode 100644
index ..9d88dbae3043
--- /dev/null
+++ b/gcc/testsuite/gm2/builtins/run/pass/testalloa.mod
@@ -0,0 +1,47 @@
+MODULE testalloa ;
+
+FROM libc IMPORT printf, exit ;
+FROM Builtins IMPORT alloca ;
+FROM SYSTEM IMPORT ADR, ADDRESS ;
+
+
+(*
+   assert -
+*)
+
+PROCEDURE assert (value: BOOLEAN; message: ARRAY OF CHAR) ;
+BEGIN
+   IF NOT value
+   THEN
+  printf ("test failed: %s\n", ADR (message)) ;
+  code := 1
+   END
+END assert ;
+
+
+(*
+   test -
+*)
+
+PROCEDURE test ;
+VAR
+   ptr: ADDRESS ;
+BEGIN
+   ptr := alloca (10) ;
+   assert (ptr # NIL, "alloca (10) # NIL")
+END test ;
+
+
+VAR
+   cod

[gcc r15-2007] modula2: bootstrap fix for string and vector headers.

2024-07-12 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:f4047a8614d2215e0d6acf071c521ac08ab1bbb2

commit r15-2007-gf4047a8614d2215e0d6acf071c521ac08ab1bbb2
Author: FX Coudert 
Date:   Fri Jul 12 15:39:50 2024 +0100

modula2: bootstrap fix for string and vector headers.

This patch fixes the include of headers ( and ) which
are included after GCC's system.h has been included.  It defines
INCLUDE_STRING before including "system.h".  This allows gcc to
bootstrap with Apple clang 15.

gcc/m2/ChangeLog:

* gm2-gcc/m2linemap.cc (INCLUDE_STRING): Define before
include of gcc-consolidation.h.
* gm2spec.cc (INCLUDE_STRING): Define before include of
system.h.
(INCLUDE_VECTOR): Ditto.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-gcc/m2linemap.cc | 2 +-
 gcc/m2/gm2spec.cc   | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/m2/gm2-gcc/m2linemap.cc b/gcc/m2/gm2-gcc/m2linemap.cc
index c916ba6155af..fcf589e840f8 100644
--- a/gcc/m2/gm2-gcc/m2linemap.cc
+++ b/gcc/m2/gm2-gcc/m2linemap.cc
@@ -19,6 +19,7 @@ You should have received a copy of the GNU General Public 
License
 along with GNU Modula-2; see the file COPYING3.  If not see
 .  */
 
+#define INCLUDE_STRING
 #include "gcc-consolidation.h"
 
 /* Utilize some of the C build routines */
@@ -36,7 +37,6 @@ along with GNU Modula-2; see the file COPYING3.  If not see
 #define m2linemap_c
 #include "m2linemap.h"
 #include "m2color.h"
-#include 
 
 static int inFile = FALSE;
 
diff --git a/gcc/m2/gm2spec.cc b/gcc/m2/gm2spec.cc
index a4faf88027a2..2a4dccf8b93c 100644
--- a/gcc/m2/gm2spec.cc
+++ b/gcc/m2/gm2spec.cc
@@ -20,6 +20,8 @@ along with GNU Modula-2; see the file COPYING3.  If not see
 .  */
 
 #include "config.h"
+#define INCLUDE_STRING
+#define INCLUDE_VECTOR
 #include "system.h"
 #include "coretypes.h"
 #include "tm.h"
@@ -31,8 +33,6 @@ along with GNU Modula-2; see the file COPYING3.  If not see
 #include "gcc.h"
 #include "opts.h"
 #include "vec.h"
-#include 
-#include 
 
 #include "m2/gm2config.h"


[gcc r15-2067] PR modula2/115957 ICE on procedure local const declaration

2024-07-16 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:d9709fafb2c498ba2f4c920f953c9b78fa3bf114

commit r15-2067-gd9709fafb2c498ba2f4c920f953c9b78fa3bf114
Author: Gaius Mulley 
Date:   Tue Jul 16 15:27:21 2024 +0100

PR modula2/115957 ICE on procedure local const declaration

An ICE would occur if a constant was declared using a variable term.
This fix catches variable terms in constant expressions and generates
an unrecoverable error.

gcc/m2/ChangeLog:

PR modula2/115957
* gm2-compiler/M2StackAddress.mod (PopAddress): Detect tail=NIL
and generate an internal error.
* gm2-compiler/PCBuild.bnf (InConstParameter): New variable.
(InConstBlock): New variable.
(ErrorString): Rewrite using MetaErrorStringT0.
(ErrorArrayAt): Rewrite using MetaErrorStringT0.
(WarnMissingToken): Use MetaErrorStringT0.
(CompilationUnit): Set seenError FALSE.
(init): Initialize InConstParameter and InConstBlock.
(ConstantDeclaration): Set InConstBlock.
(ConstSetOrQualidentOrFunction): Call CheckNotVar if not
InConstParameter and InConstBlock.
(ConstActualParameters): Set InConstParameter TRUE and restore
value at the end.
* gm2-compiler/PCSymBuild.def (CheckNotVar): New procedure.
Remove all unnecessary export qualified list.
* gm2-compiler/PCSymBuild.mod (CheckNotVar): New procedure.

gcc/testsuite/ChangeLog:

PR modula2/115957
* gm2/errors/fail/badconst.mod: New test.
* gm2/pim/fail/tinyadr.mod: New test.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-compiler/M2StackAddress.mod | 11 +---
 gcc/m2/gm2-compiler/PCBuild.bnf| 40 +-
 gcc/m2/gm2-compiler/PCSymBuild.def | 38 +---
 gcc/m2/gm2-compiler/PCSymBuild.mod | 18 +-
 gcc/testsuite/gm2/errors/fail/badconst.mod | 19 ++
 gcc/testsuite/gm2/pim/fail/tinyadr.mod | 12 +
 6 files changed, 90 insertions(+), 48 deletions(-)

diff --git a/gcc/m2/gm2-compiler/M2StackAddress.mod 
b/gcc/m2/gm2-compiler/M2StackAddress.mod
index c7262dce3b38..ff65b42059c4 100644
--- a/gcc/m2/gm2-compiler/M2StackAddress.mod
+++ b/gcc/m2/gm2-compiler/M2StackAddress.mod
@@ -157,9 +157,14 @@ BEGIN
 END ;
 DISPOSE(b)
  END ;
- WITH s^.tail^ DO
-DEC(items) ;
-RETURN( bucket[items] )
+ IF s^.tail = NIL
+ THEN
+InternalError ('stack underflow')
+ ELSE
+WITH s^.tail^ DO
+   DEC(items) ;
+   RETURN( bucket[items] )
+END
  END
   END
END
diff --git a/gcc/m2/gm2-compiler/PCBuild.bnf b/gcc/m2/gm2-compiler/PCBuild.bnf
index 46f46af73ffe..0e45b2e889cc 100644
--- a/gcc/m2/gm2-compiler/PCBuild.bnf
+++ b/gcc/m2/gm2-compiler/PCBuild.bnf
@@ -47,7 +47,7 @@ IMPLEMENTATION MODULE PCBuild ;
 FROM M2LexBuf IMPORT currentstring, currenttoken, GetToken, InsertToken,
  InsertTokenAndRewind, GetTokenNo, MakeVirtualTok ;
 
-FROM M2Error IMPORT ErrorStringAt, WriteFormat1, WriteFormat2 ;
+FROM M2MetaError IMPORT MetaErrorStringT0 ;
 FROM NameKey IMPORT NulName, Name, makekey ;
 FROM DynamicStrings IMPORT String, InitString, KillString, Mark, ConCat, 
ConCatChar ;
 FROM M2Printf IMPORT printf0 ;
@@ -102,7 +102,8 @@ FROM PCSymBuild IMPORT PCStartBuildProgModule,
PushConstType,
PushConstAttributeType,
PushConstAttributePairType,
-   PushRType ;
+   PushRType,
+   CheckNotVar ;
 
 FROM SymbolTable IMPORT MakeGnuAsm, PutGnuAsmVolatile, PutGnuAsm, 
PutGnuAsmInput,
 PutGnuAsmOutput, PutGnuAsmTrash, PutGnuAsmVolatile,
@@ -127,13 +128,15 @@ CONST
Pass1 = FALSE ;
 
 VAR
-   WasNoError  : BOOLEAN ;
+   InConstParameter,
+   InConstBlock,
+   seenError   : BOOLEAN ;
 
 
 PROCEDURE ErrorString (s: String) ;
 BEGIN
-   ErrorStringAt (s, GetTokenNo ()) ;
-   WasNoError := FALSE
+   MetaErrorStringT0 (GetTokenNo (), s) ;
+   seenError := TRUE
 END ErrorString ;
 
 
@@ -145,7 +148,7 @@ END ErrorArray ;
 
 PROCEDURE ErrorArrayAt (a: ARRAY OF CHAR; tok: CARDINAL) ;
 BEGIN
-   ErrorStringAt (InitString(a), tok)
+   MetaErrorStringT0 (tok, InitString (a))
 END ErrorArrayAt ;
 
 
@@ -220,7 +223,7 @@ BEGIN
str := DescribeStop(s0, s1, s2) ;
 
str := ConCat(InitString('syntax error,'), Mark(str)) ;
-   ErrorStringAt(str, GetTokenNo())
+   MetaErrorStringT0 (GetTokenNo (), str)
 END WarnMissingToken ;
 
 
@@ -338,9 +341,9 @@ END Expect ;
 
 PROCEDURE CompilationUnit () : BOOLEAN ;
 BEGIN
-   WasNoError := TRUE ;
+   seenError := FALSE ;
FileUnit(SetOfStop0{eoftok}, SetOfStop1{}, SetOfStop2{}) ;
-   RETURN( WasNoError )

[gcc r15-2228] PR modula2/116048 ICE when encountering wrong kind of qualident

2024-07-23 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:7f8064ff0e2ac90c5bb6c30cc61acc5a28ebbe4c

commit r15-2228-g7f8064ff0e2ac90c5bb6c30cc61acc5a28ebbe4c
Author: Gaius Mulley 
Date:   Tue Jul 23 15:54:16 2024 +0100

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 

Diff:
---
 gcc/m2/Make-lang.in   |   4 +
 gcc/m2/gm2-compiler/M2Quads.mod   |  45 ++--
 gcc/m2/gm2-compiler/M2StateCheck.def  | 154 
 gcc/m2/gm2-compiler/M2StateCheck.mod  | 344 ++
 gcc/m2/gm2-compiler/P3Build.bnf   |  65 +++--
 gcc/m2/gm2-compiler/PCBuild.bnf   |  45 ++--
 gcc/m2/gm2-gcc/init.cc|   4 +
 gcc/testsuite/gm2/errors/fail/array1.mod  |   5 +
 gcc/testsuite/gm2/errors/fail/badtype.mod |  10 +
 gcc/testsuite/gm2/errors/fail/badvar.mod  |  10 +
 gcc/testsuite/gm2/errors/fail/errors-fail.exp |   2 +-
 gcc/testsuite/gm2/errors/fail/testfio.mod |   8 +
 gcc/testsuite/gm2/errors/fail/testparam.mod   |   5 +
 13 files changed, 645 insertions(+), 56 deletions(-)

diff --git a/gcc/m2/Make-lang.in b/gcc/m2/Make-lang.in
index daa7ef6747a5..2bd60ca29393 100644
--- a/gcc/m2/Make-lang.in
+++ b/gcc/m2/Make-lang.in
@@ -808,6 +808,7 @@ GM2-COMP-BOOT-DEFS = \
M2Size.def \
M2StackAddress.def \
M2StackWord.def \
+   M2StateCheck.def \
M2Students.def \
M2Swig.def \
M2SymInit.def \
@@ -882,6 +883,7 @@ GM2-COMP-BOOT-MODS = \
M2Size.mod \
M2StackAddress.mod \
M2StackWord.mod \
+   M2StateCheck.mod \
M2Students.mod \
M2Swig.mod \
M2SymInit.mod \
@@ -1090,6 +1092,7 @@ GM2-COMP-DEFS = \
M2Size.def \
  

[gcc r15-2256] modula2: Add GNU flex as a build and install prerequisite.

2024-07-24 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:52f3473e375b1bb57d08c97291a82c04070036c3

commit r15-2256-g52f3473e375b1bb57d08c97291a82c04070036c3
Author: Gaius Mulley 
Date:   Wed Jul 24 14:25:45 2024 +0100

modula2: Add GNU flex as a build and install prerequisite.

gcc/ChangeLog:

* doc/install.texi (GM2-prerequisite): Add GNU flex.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/doc/install.texi | 4 
 1 file changed, 4 insertions(+)

diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index dda623f4410a..4973f195daf9 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -334,6 +334,10 @@ environment to your ``good'' shell prior to running
 @command{zsh} is not a fully compliant POSIX shell and will not
 work when configuring GCC@.
 
+@item GNU flex
+
+Necessary to build the lexical analysis module.
+
 @item A POSIX or SVR4 awk
 
 Necessary for creating some of the generated source files for GCC@.


[gcc r15-2257] modula2: Improve error message to include symbol name.

2024-07-24 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:6a99f3ae962542165fdfc077f1040ea4d936691b

commit r15-2257-g6a99f3ae962542165fdfc077f1040ea4d936691b
Author: Gaius Mulley 
Date:   Wed Jul 24 14:26:39 2024 +0100

modula2: Improve error message to include symbol name.

gcc/m2/ChangeLog:

* gm2-compiler/M2StateCheck.mod (GenerateError): Add
symbol name to the error message.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-compiler/M2StateCheck.mod | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/m2/gm2-compiler/M2StateCheck.mod 
b/gcc/m2/gm2-compiler/M2StateCheck.mod
index e53cb174474c..940c433bcc14 100644
--- a/gcc/m2/gm2-compiler/M2StateCheck.mod
+++ b/gcc/m2/gm2-compiler/M2StateCheck.mod
@@ -306,7 +306,7 @@ PROCEDURE GenerateError (tok: CARDINAL; s: StateCheck; sym: 
CARDINAL) ;
 VAR
str: String ;
 BEGIN
-   str := InitString ('not expecting a {%1Ad} {%1a: }in a ') ;
+   str := InitString ('not expecting the {%1Ad} {%1a} in a ') ;
IF const IN s^.state
THEN
   str := ConCat (str, Mark (InitString ('{%kCONST} block')))


[gcc r15-2366] PR modula2/115823 Wrong expansion of isnormal optab

2024-07-28 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:79e029a41825f533bb87b4bee5427b90b62175ae

commit r15-2366-g79e029a41825f533bb87b4bee5427b90b62175ae
Author: Gaius Mulley 
Date:   Sun Jul 28 19:20:43 2024 +0100

PR modula2/115823 Wrong expansion of isnormal optab

This patch corrects the function declaration of a builtin
(using the libname rather than the source name).

gcc/m2/ChangeLog:

PR modula2/115823
* gm2-gcc/m2builtins.cc (define_builtin): Build
the function decl using the libname.

gcc/testsuite/ChangeLog:

PR modula2/115823
* gm2/builtins/run/pass/testisnormal.mod: Change to an
implementation module.
* gm2/builtins/run/pass/testisnormal.def: New test.
* gm2/builtins/run/pass/testsinl.def: New test.
* gm2/builtins/run/pass/testsinl.mod: New test.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-gcc/m2builtins.cc   |  4 ++--
 .../gm2/builtins/run/pass/testisnormal.def |  5 +
 .../gm2/builtins/run/pass/testisnormal.mod |  2 +-
 gcc/testsuite/gm2/builtins/run/pass/testsinl.def   |  5 +
 gcc/testsuite/gm2/builtins/run/pass/testsinl.mod   | 23 ++
 5 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/gcc/m2/gm2-gcc/m2builtins.cc b/gcc/m2/gm2-gcc/m2builtins.cc
index e3e55a699917..44f48fc01ba8 100644
--- a/gcc/m2/gm2-gcc/m2builtins.cc
+++ b/gcc/m2/gm2-gcc/m2builtins.cc
@@ -1431,8 +1431,8 @@ define_builtin (enum built_in_function val, const char 
*name, tree prototype,
   tree decl;
   builtin_macro_definition bmd;
 
-  decl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL, get_identifier (name),
- prototype);
+  decl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL,
+get_identifier (libname), prototype);
   DECL_EXTERNAL (decl) = 1;
   TREE_PUBLIC (decl) = 1;
   SET_DECL_ASSEMBLER_NAME (decl, get_identifier (libname));
diff --git a/gcc/testsuite/gm2/builtins/run/pass/testisnormal.def 
b/gcc/testsuite/gm2/builtins/run/pass/testisnormal.def
new file mode 100644
index ..df01cc353eb5
--- /dev/null
+++ b/gcc/testsuite/gm2/builtins/run/pass/testisnormal.def
@@ -0,0 +1,5 @@
+DEFINITION MODULE testisnormal ;
+
+PROCEDURE test ;
+
+END testisnormal.
diff --git a/gcc/testsuite/gm2/builtins/run/pass/testisnormal.mod 
b/gcc/testsuite/gm2/builtins/run/pass/testisnormal.mod
index 6b65a7b9b122..1349d80e8e8e 100644
--- a/gcc/testsuite/gm2/builtins/run/pass/testisnormal.mod
+++ b/gcc/testsuite/gm2/builtins/run/pass/testisnormal.mod
@@ -1,4 +1,4 @@
-MODULE testisnormal ;
+IMPLEMENTATION MODULE testisnormal ;
 
 FROM libc IMPORT printf, exit ;
 FROM Builtins IMPORT isnormal ;
diff --git a/gcc/testsuite/gm2/builtins/run/pass/testsinl.def 
b/gcc/testsuite/gm2/builtins/run/pass/testsinl.def
new file mode 100644
index ..7afd3cc86235
--- /dev/null
+++ b/gcc/testsuite/gm2/builtins/run/pass/testsinl.def
@@ -0,0 +1,5 @@
+DEFINITION MODULE testsinl ;
+
+PROCEDURE test ;
+
+END testsinl.
diff --git a/gcc/testsuite/gm2/builtins/run/pass/testsinl.mod 
b/gcc/testsuite/gm2/builtins/run/pass/testsinl.mod
new file mode 100644
index ..7f669f89c8e2
--- /dev/null
+++ b/gcc/testsuite/gm2/builtins/run/pass/testsinl.mod
@@ -0,0 +1,23 @@
+IMPLEMENTATION MODULE testsinl ;
+
+FROM libc IMPORT printf ;
+FROM Builtins IMPORT sinl ;
+
+
+(*
+   test -
+*)
+
+PROCEDURE test ;
+VAR
+   result: LONGREAL ;
+BEGIN
+   result := sinl (3.14) ;
+   printf ("sinl (3.14) = %lg\n", result) ;
+END test ;
+
+
+BEGIN
+   test ;
+   printf ("all tests pass\n")
+END testsinl.


[gcc r14-9365] PR modula2/109969 Linking large project causes an ICE

2024-03-07 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:99309b98c2e80a42886da36668e1e8d3d082699e

commit r14-9365-g99309b98c2e80a42886da36668e1e8d3d082699e
Author: Gaius Mulley 
Date:   Thu Mar 7 19:41:58 2024 +

PR modula2/109969 Linking large project causes an ICE

This patch contains a re-write of M2LexBuf.mod which removes the linked
list of token buckets and simplifies the implementation using a dynamic
array.  It contains more checking (for empty source files for example).
The patch also contains a fix for an ICE in gcc/m2/gm2-gcc/builtins.cc

gcc/m2/ChangeLog:

PR modula2/109969
* gm2-compiler/M2LexBuf.def (TokenToLineNo): Rename parameter.
(TokenToColumnNo): Rename parameter.
(TokenToLocation): Rename parameter.
(FindFileNameFromToken): Rename parameter.
(DumpTokens): Rewrite comment.
* gm2-compiler/M2LexBuf.mod: Rewrite.
* gm2-compiler/P0SyntaxCheck.bnf (CheckInsertCandidate):
DumpTokens before and after inserting recovery token.
* gm2-gcc/m2builtins.cc (do_target_support_exists): Add
bf_c99_compl case.
* gm2-libs/Indexing.def (InitIndexTuned): New procedure
function.
(IsEmpty): New procedure function.
* gm2-libs/Indexing.mod (InitIndexTuned): New procedure
function.
(IsEmpty): New procedure function.
(Index): New field GrowFactor.
(PutIndice): Use GrowFactor to extend dynamic array.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-compiler/M2LexBuf.def  |  32 +-
 gcc/m2/gm2-compiler/M2LexBuf.mod  | 810 --
 gcc/m2/gm2-compiler/P0SyntaxCheck.bnf |  10 +-
 gcc/m2/gm2-gcc/m2builtins.cc  |   2 +
 gcc/m2/gm2-libs/Indexing.def  |  22 +-
 gcc/m2/gm2-libs/Indexing.mod  |  46 +-
 6 files changed, 451 insertions(+), 471 deletions(-)

diff --git a/gcc/m2/gm2-compiler/M2LexBuf.def b/gcc/m2/gm2-compiler/M2LexBuf.def
index 27610ec49dd..07f5934a631 100644
--- a/gcc/m2/gm2-compiler/M2LexBuf.def
+++ b/gcc/m2/gm2-compiler/M2LexBuf.def
@@ -1,4 +1,4 @@
-(* M2LexBuf.def provides a buffer for m2.lex.
+(* M2LexBuf.def provides a buffer for m2.flex.
 
 Copyright (C) 2001-2024 Free Software Foundation, Inc.
 Contributed by Gaius Mulley .
@@ -35,18 +35,6 @@ FROM DynamicStrings IMPORT String ;
 FROM m2linemap IMPORT location_t ;
 FROM NameKey IMPORT Name ;
 
-EXPORT QUALIFIED OpenSource, CloseSource, ReInitialize, GetToken, InsertToken,
- InsertTokenAndRewind, GetPreviousTokenLineNo, GetLineNo,
- GetColumnNo, GetTokenNo, TokenToLineNo, TokenToColumnNo,
- TokenToLocation, GetTokenName,
- FindFileNameFromToken, GetFileName,
- ResetForNewPass,
- currenttoken, currentstring, currentinteger,
- AddTok, AddTokCharStar, AddTokInteger,
- MakeVirtualTok, MakeVirtual2Tok,
- SetFile, PushFile, PopFile,
- PrintTokenNo, DisplayToken, DumpTokens,
- BuiltinTokenNo, UnknownTokenNo ;
 
 CONST
UnknownTokenNo = 0 ;
@@ -143,13 +131,13 @@ PROCEDURE GetTokenName (tokenno: CARDINAL) : Name ;
 
 (*
TokenToLineNo - returns the line number of the current file for the
-   TokenNo. The depth refers to the include depth.
+   tokenno. The depth refers to the include depth.
A depth of 0 is the current file, depth of 1 is the file
which included the current file. Zero is returned if the
depth exceeds the file nesting level.
 *)
 
-PROCEDURE TokenToLineNo (TokenNo: CARDINAL; depth: CARDINAL) : CARDINAL ;
+PROCEDURE TokenToLineNo (tokenno: CARDINAL; depth: CARDINAL) : CARDINAL ;
 
 
 (*
@@ -162,31 +150,31 @@ PROCEDURE GetColumnNo () : CARDINAL ;
 
 (*
TokenToColumnNo - returns the column number of the current file for the
- TokenNo. The depth refers to the include depth.
+ tokenno. The depth refers to the include depth.
  A depth of 0 is the current file, depth of 1 is the file
  which included the current file. Zero is returned if the
  depth exceeds the file nesting level.
 *)
 
-PROCEDURE TokenToColumnNo (TokenNo: CARDINAL; depth: CARDINAL) : CARDINAL ;
+PROCEDURE TokenToColumnNo (tokenno: CARDINAL; depth: CARDINAL) : CARDINAL ;
 
 
 (*
-   TokenToLocation - returns the location_t corresponding to, TokenNo.
+   TokenToLocation - returns the location_t corresponding to tokenno.
 *)
 
-PROCEDURE TokenToLocation (TokenNo: CARDINAL) : location_t ;
+PROCEDURE TokenToLocation (tokenno: CARDINAL) : location_t ;
 
 
 (*
FindFileNameFromToken - returns the complete FileName for the appropriate
-   source file yields the token number, TokenNo.
+

[gcc r14-9381] modula2: Add constant aggregate tests

2024-03-07 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:131d1753ac71eb62f0b14fa9a1cb0e125e9a3ca1

commit r14-9381-g131d1753ac71eb62f0b14fa9a1cb0e125e9a3ca1
Author: Gaius Mulley 
Date:   Fri Mar 8 06:26:55 2024 +

modula2: Add constant aggregate tests

This patch adds four constant aggregate tests and assignment of
arrays by a constant in two different scopes.

gcc/testsuite/ChangeLog:

* gm2/iso/pass/arrayconst.mod: New test.
* gm2/iso/pass/arrayconst2.mod: New test.
* gm2/iso/pass/arrayconst3.mod: New test.
* gm2/iso/pass/arrayconst4.mod: New test.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/testsuite/gm2/iso/pass/arrayconst.mod  | 31 ++
 gcc/testsuite/gm2/iso/pass/arrayconst2.mod | 31 ++
 gcc/testsuite/gm2/iso/pass/arrayconst3.mod | 35 ++
 gcc/testsuite/gm2/iso/pass/arrayconst4.mod | 35 ++
 4 files changed, 132 insertions(+)

diff --git a/gcc/testsuite/gm2/iso/pass/arrayconst.mod 
b/gcc/testsuite/gm2/iso/pass/arrayconst.mod
new file mode 100644
index 000..05ce4c911d1
--- /dev/null
+++ b/gcc/testsuite/gm2/iso/pass/arrayconst.mod
@@ -0,0 +1,31 @@
+MODULE arrayconst ;
+
+
+PROCEDURE foo ;
+TYPE
+   array = ARRAY [0..3] OF REAL ;
+CONST
+   value = array {1.0, 2.0, 3.0, 4.0} ;
+VAR
+   r: REAL ;
+BEGIN
+   r := value[1] ;
+END foo ;
+
+
+PROCEDURE bar ;
+TYPE
+   array = ARRAY [0..3] OF REAL ;
+CONST
+   value = array {5.0, 6.0, 7.0, 8.0} ;
+VAR
+   r: REAL ;
+BEGIN
+   r := value[1] ;
+END bar ;
+
+
+BEGIN
+   foo ;
+   bar
+END arrayconst.
diff --git a/gcc/testsuite/gm2/iso/pass/arrayconst2.mod 
b/gcc/testsuite/gm2/iso/pass/arrayconst2.mod
new file mode 100644
index 000..cee4b1457cb
--- /dev/null
+++ b/gcc/testsuite/gm2/iso/pass/arrayconst2.mod
@@ -0,0 +1,31 @@
+MODULE arrayconst ;
+
+
+PROCEDURE foo ;
+TYPE
+   array = ARRAY [0..3] OF REAL ;
+CONST
+   value = array {1.0, 2.0, 3.0, 4.0} ;
+VAR
+   c: array ;
+BEGIN
+   c := value
+END foo ;
+
+
+PROCEDURE bar ;
+TYPE
+   array = ARRAY [0..3] OF REAL ;
+CONST
+   value = array {5.0, 6.0, 7.0, 8.0} ;
+VAR
+   c: array ;
+BEGIN
+   c := value
+END bar ;
+
+
+BEGIN
+   foo ;
+   bar
+END arrayconst.
diff --git a/gcc/testsuite/gm2/iso/pass/arrayconst3.mod 
b/gcc/testsuite/gm2/iso/pass/arrayconst3.mod
new file mode 100644
index 000..0402e6f6bac
--- /dev/null
+++ b/gcc/testsuite/gm2/iso/pass/arrayconst3.mod
@@ -0,0 +1,35 @@
+MODULE arrayconst3 ;
+
+
+PROCEDURE foo ;
+CONST
+   len = 4 ;
+TYPE
+   array = ARRAY [0..len -1] OF REAL ;
+CONST
+   value = array {1.0, 2.0, 3.0, 4.0} ;
+VAR
+   r: REAL ;
+BEGIN
+   r := value[1] ;
+END foo ;
+
+
+PROCEDURE bar ;
+CONST
+   len = 2 ;
+TYPE
+   array = ARRAY [0..len -1] OF REAL ;
+CONST
+   value = array {5.0, 6.0} ;
+VAR
+   r: REAL ;
+BEGIN
+   r := value[1] ;
+END bar ;
+
+
+BEGIN
+   foo ;
+   bar
+END arrayconst3.
diff --git a/gcc/testsuite/gm2/iso/pass/arrayconst4.mod 
b/gcc/testsuite/gm2/iso/pass/arrayconst4.mod
new file mode 100644
index 000..0b14229cd8a
--- /dev/null
+++ b/gcc/testsuite/gm2/iso/pass/arrayconst4.mod
@@ -0,0 +1,35 @@
+MODULE arrayconst4 ;
+
+
+PROCEDURE foo ;
+CONST
+   len = 4 ;
+TYPE
+   array = ARRAY [0..len -1] OF REAL ;
+CONST
+   value = array {1.0, 2.0, 3.0, 4.0} ;
+VAR
+   c: array ;
+BEGIN
+   c := value
+END foo ;
+
+
+PROCEDURE bar ;
+CONST
+   len = 2 ;
+TYPE
+   array = ARRAY [0..len -1] OF REAL ;
+CONST
+   value = array {5.0, 6.0} ;
+VAR
+   c: array ;
+BEGIN
+   c := value
+END bar ;
+
+
+BEGIN
+   foo ;
+   bar
+END arrayconst4.


[gcc r14-9390] modula2: Rebuild bootstrap tools with faster dynamic arrays

2024-03-08 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:3cdaa6491fe805ffc1dc545722b97660f31572fa

commit r14-9390-g3cdaa6491fe805ffc1dc545722b97660f31572fa
Author: Gaius Mulley 
Date:   Fri Mar 8 12:52:04 2024 +

modula2: Rebuild bootstrap tools with faster dynamic arrays

This patch configures the larger dynamic arrays to use a larger
growth factor and larger initial size.  It also rebuilds mc and pge
using the improved default array sizes in Indexing.mod.

gcc/m2/ChangeLog:

* gm2-compiler/M2Quads.mod (Init): Use InitIndexTuned with
default size 65K.
* gm2-compiler/SymbolConversion.mod (Init): Ditto.
* gm2-compiler/SymbolTable.mod (BEGIN): Ditto.
* mc-boot/GM2Dependent.cc: Rebuild.
* mc-boot/GM2Dependent.h: Rebuild.
* mc-boot/GM2RTS.cc: Rebuild.
* pge-boot/GIndexing.cc: Rebuild.
* pge-boot/GIndexing.h: Rebuild.
* pge-boot/GM2Dependent.cc: Rebuild.
* pge-boot/GM2Dependent.h: Rebuild.
* pge-boot/GM2RTS.cc: Rebuild.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-compiler/M2Quads.mod  |   5 +-
 gcc/m2/gm2-compiler/SymbolConversion.mod |   6 +-
 gcc/m2/gm2-compiler/SymbolTable.mod  |   7 +-
 gcc/m2/mc-boot/GM2Dependent.cc   | 202 +--
 gcc/m2/mc-boot/GM2Dependent.h|  32 +
 gcc/m2/mc-boot/GM2RTS.cc | 118 ++
 gcc/m2/pge-boot/GIndexing.cc |  59 +++--
 gcc/m2/pge-boot/GIndexing.h  |  15 +++
 gcc/m2/pge-boot/GM2Dependent.cc  | 202 +--
 gcc/m2/pge-boot/GM2Dependent.h   |  32 +
 gcc/m2/pge-boot/GM2RTS.cc| 119 ++
 11 files changed, 540 insertions(+), 257 deletions(-)

diff --git a/gcc/m2/gm2-compiler/M2Quads.mod b/gcc/m2/gm2-compiler/M2Quads.mod
index ff0fda9cd41..2be229d0bf8 100644
--- a/gcc/m2/gm2-compiler/M2Quads.mod
+++ b/gcc/m2/gm2-compiler/M2Quads.mod
@@ -230,7 +230,8 @@ FROM M2StackWord IMPORT StackOfWord, InitStackWord, 
KillStackWord,
 PushWord, PopWord, PeepWord, RemoveTop,
 IsEmptyWord, NoOfItemsInStackWord ;
 
-FROM Indexing IMPORT Index, InitIndex, GetIndice, PutIndice, InBounds, 
HighIndice, IncludeIndiceIntoIndex ;
+FROM Indexing IMPORT Index, InitIndex, GetIndice, PutIndice, InBounds, 
HighIndice,
+ IncludeIndiceIntoIndex, InitIndexTuned ;
 
 FROM M2Range IMPORT InitAssignmentRangeCheck,
 InitReturnRangeCheck,
@@ -15451,7 +15452,7 @@ BEGIN
LogicalXorTok := MakeKey('_LXOR') ;
LogicalDifferenceTok := MakeKey('_LDIFF') ;
ArithPlusTok := MakeKey ('_ARITH_+') ;
-   QuadArray := InitIndex (1) ;
+   QuadArray := InitIndexTuned (1, 1024*1024 DIV 16, 16) ;
FreeList := 1 ;
NewQuad(NextQuad) ;
Assert(NextQuad=1) ;
diff --git a/gcc/m2/gm2-compiler/SymbolConversion.mod 
b/gcc/m2/gm2-compiler/SymbolConversion.mod
index c3c484db00a..b8f0f70b435 100644
--- a/gcc/m2/gm2-compiler/SymbolConversion.mod
+++ b/gcc/m2/gm2-compiler/SymbolConversion.mod
@@ -24,7 +24,7 @@ IMPLEMENTATION MODULE SymbolConversion ;
 FROM NameKey IMPORT Name ;
 
 FROM Indexing IMPORT Index, InitIndex, PutIndice, GetIndice, InBounds,
- DebugIndex ;
+ DebugIndex, InitIndexTuned ;
 
 FROM SymbolTable IMPORT IsConst, PopValue, IsValueSolved, GetSymName,
 GetType, SkipType ;
@@ -237,8 +237,8 @@ END Poison ;
 
 PROCEDURE Init ;
 BEGIN
-   mod2gcc := InitIndex(1) ;
-   ALLOCATE(PoisonedSymbol, 1)
+   mod2gcc := InitIndexTuned (1, 1024*1024 DIV 16, 16) ;
+   ALLOCATE (PoisonedSymbol, 1)
 END Init ;
 
 
diff --git a/gcc/m2/gm2-compiler/SymbolTable.mod 
b/gcc/m2/gm2-compiler/SymbolTable.mod
index c57c0333188..b49cc889dca 100644
--- a/gcc/m2/gm2-compiler/SymbolTable.mod
+++ b/gcc/m2/gm2-compiler/SymbolTable.mod
@@ -28,7 +28,10 @@ FROM M2Debug IMPORT Assert ;
 FROM libc IMPORT printf ;
 
 IMPORT Indexing ;
-FROM Indexing IMPORT InitIndex, InBounds, LowIndice, HighIndice, PutIndice, 
GetIndice ;
+
+FROM Indexing IMPORT InitIndex, InBounds, LowIndice, HighIndice,
+ PutIndice, GetIndice, InitIndexTuned ;
+
 FROM Sets IMPORT Set, InitSet, IncludeElementIntoSet, IsElementInSet ;
 FROM m2linemap IMPORT location_t ;
 
@@ -1644,7 +1647,7 @@ BEGIN
InitTree (ConstLitPoolTree) ;
InitTree (DefModuleTree) ;
InitTree (ModuleTree) ;
-   Symbols := InitIndex (1) ;
+   Symbols := InitIndexTuned (1, 1024*1024 DIV 16, 16) ;
ConstLitArray := InitIndex (1) ;
FreeSymbol := 1 ;
ScopePtr := 1 ;
diff --git a/gcc/m2/mc-boot/GM2Dependent.cc b/gcc/m2/mc-boot/GM2Dependent.cc
index cda07e8460b..bf0daab4563 100644
--- a/gcc/m2/mc-boot/GM2Dependent.cc
+++ b/gcc/m2/mc-boot/GM2Dependent.cc
@@ -55,7 +55,6 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If 
not, see
 #   include "GSYSTEM.h"
 #   include "GStor

[gcc r14-9429] PR modula2/114295 Incorrect location if compiling implementation without definition

2024-03-11 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:8410402272038aae7e4b2bd76df38607a78cad95

commit r14-9429-g8410402272038aae7e4b2bd76df38607a78cad95
Author: Gaius Mulley 
Date:   Mon Mar 11 15:21:42 2024 +

PR modula2/114295 Incorrect location if compiling implementation without 
definition

This patch fixes a bug which occurred if gm2 was asked to compile an
implementation module and could not find the definition module.  The error
location would be set to the SYSTEM module.  The bug occurred as the
module sym was created during the peep phase after which the few tokens are
destroyed and recreated during parsing.  The bug fix is to call
PutDeclared when the module is encountered during parsing which updates
the tokenno associated with the module.

gcc/m2/ChangeLog:

PR modula2/114295
* gm2-compiler/M2Batch.mod (MakeProgramSource): Call PutDeclared
if the module is known.
(MakeDefinitionSource): Ditto.
(MakeImplementationSource): Ditto.
* gm2-compiler/M2Comp.mod (ExamineHeader): New procedure.
(ExamineCompilationUnit): Rewrite.
(PeepInto): Rewrite.
* gm2-compiler/M2Error.mod (NewError): Remove default call to
GetTokenNo.
* gm2-compiler/M2Quads.mod (callRequestDependant): Push tokno with
Adr.
(BuildStringAdrParam): Ditto.
(doBuildBinaryOp): Push OperatorPos on the bool stack.
(BuildRelOp): Ditto.
* gm2-compiler/P2Build.bnf (SetType): Pass set token pos to
BuildSetType.
(PointerType): Pass pointer token pos to BuildPointerType.
* gm2-compiler/P2SymBuild.def (BuildPointerType): Add parameter
pointerpos.
(BuildSetType): Add parameter setpos.
* gm2-compiler/P2SymBuild.mod (BuildPointerType): Add parameter
pointerpos.  Build combined token and use it when creating a
pointer type.
(BuildSetType): Add parameter setpos.  Build combined token and
use it when creating a set type.
* gm2-compiler/SymbolTable.mod (DebugUnknownToken): New constant.
(CheckTok): New procedure function.
(MakeProcedure): Call CheckTok.
(MakeRecord): Ditto.
(MakeVarient): Ditto.
(MakeEnumeration): Ditto.
(MakeHiddenType): Ditto.
(MakeConstant): Ditto.
(MakeConstStringCnul): Ditto.
(MakeSubrange): Ditto.
(MakeTemporary): Ditto.
(MakeVariableForParam): Ditto.
(MakeParameterHeapVar): Ditto.
(MakePointer): Ditto.
(MakeSet): Ditto.
(MakeUnbounded): Ditto.
(MakeProcType): Ditto.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-compiler/M2Batch.mod | 12 -
 gcc/m2/gm2-compiler/M2Comp.mod  | 88 +++--
 gcc/m2/gm2-compiler/M2Error.mod |  6 +--
 gcc/m2/gm2-compiler/M2Quads.mod | 42 +-
 gcc/m2/gm2-compiler/P2Build.bnf | 13 +++---
 gcc/m2/gm2-compiler/P2SymBuild.def  |  4 +-
 gcc/m2/gm2-compiler/P2SymBuild.mod  | 45 ++-
 gcc/m2/gm2-compiler/SymbolTable.mod | 47 +++-
 8 files changed, 179 insertions(+), 78 deletions(-)

diff --git a/gcc/m2/gm2-compiler/M2Batch.mod b/gcc/m2/gm2-compiler/M2Batch.mod
index d6eb53ff90d..8cfc906513c 100644
--- a/gcc/m2/gm2-compiler/M2Batch.mod
+++ b/gcc/m2/gm2-compiler/M2Batch.mod
@@ -23,7 +23,11 @@ IMPLEMENTATION MODULE M2Batch ;
 
 
 FROM M2Debug IMPORT Assert ;
-FROM SymbolTable IMPORT MakeModule, MakeDefImp, IsModule, IsDefImp, GetScope, 
GetLocalSym, GetCurrentScope, GetSym, NulSym ;
+
+FROM SymbolTable IMPORT MakeModule, MakeDefImp, IsModule, IsDefImp,
+GetScope, GetLocalSym, GetCurrentScope,
+PutDeclared, GetSym, NulSym ;
+
 FROM NameKey IMPORT GetKey, WriteKey ;
 FROM M2Printf IMPORT printf2 ;
 FROM M2Error IMPORT InternalError ;
@@ -69,6 +73,8 @@ BEGIN
   Sym := MakeModule (tok, n) ;
   Put (Sym, n) ;
   Push (Sym)
+   ELSE
+  PutDeclared (tok, Sym)
END ;
RETURN Sym
 END MakeProgramSource ;
@@ -96,6 +102,8 @@ BEGIN
   Sym := MakeDefImp (tok, n) ;
   Put (Sym, n) ;
   Push (Sym)
+   ELSE
+  PutDeclared (tok, Sym)
END ;
RETURN Sym
 END MakeDefinitionSource ;
@@ -123,6 +131,8 @@ BEGIN
   Sym := MakeDefImp (tok, n) ;
   Put (Sym, n) ;
   Push (Sym)
+   ELSE
+  PutDeclared (tok, Sym)
END ;
RETURN Sym
 END MakeImplementationSource ;
diff --git a/gcc/m2/gm2-compiler/M2Comp.mod b/gcc/m2/gm2-compiler/M2Comp.mod
index c10c301cbde..719ae6641dc 100644
--- a/gcc/m2/gm2-compiler/M2Comp.mod
+++ b/gcc/m2/gm2-compiler/M2Comp.mod
@@ -30,7 +30,8 @@ FROM M2Search IMPORT FindSourceDefFile, FindSourceModFile ;
 FROM M2Code IMPORT Code ;
 
 FROM M2LexBuf IMPORT OpenSource, CloseSo

[gcc r14-9463] PR modula2/114333 set type comparison against a cardinal should cause an error

2024-03-14 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:b7f70cfdb6f7ab369ecca14a99a0064d2a11ddd2

commit r14-9463-gb7f70cfdb6f7ab369ecca14a99a0064d2a11ddd2
Author: Gaius Mulley 
Date:   Thu Mar 14 11:23:42 2024 +

PR modula2/114333 set type comparison against a cardinal should cause an 
error

The type checker M2Check.mod needs extending to detect if a set, array or
record is in either operand at the end of the cascaded test list.

gcc/m2/ChangeLog:

PR modula2/114333
* gm2-compiler/M2Check.mod (checkUnbounded): New procedure
function.
(checkArrayTypeEquivalence): Extend checking to cover unbounded
arrays, arrays and constants.
(IsTyped): Simplified the expression and corrected a test for
IsConstructor.
(checkTypeKindViolation): New procedure function.
(doCheckPair): Call checkTypeKindViolation.
* gm2-compiler/M2GenGCC.mod (CodeStatement): Remove parameters
to CodeEqu and CodeNotEqu.
(PerformCodeIfEqu): New procedure.
(CodeIfEqu): Rewrite.
(PerformCodeIfNotEqu): New procedure.
(CodeIfNotEqu): Rewrite.
* gm2-compiler/M2Quads.mod (BuildRelOpFromBoolean): Correct
comment.

gcc/testsuite/ChangeLog:

PR modula2/114333
* gm2/cse/pass/testcse54.mod: New test.
* gm2/iso/run/pass/array9.mod: New test.
* gm2/iso/run/pass/strcons3.mod: New test.
* gm2/iso/run/pass/strcons4.mod: New test.
* gm2/pim/fail/badset1.mod: New test.
* gm2/pim/fail/badset2.mod: New test.
* gm2/pim/fail/badset3.mod: New test.
* gm2/pim/fail/badset4.mod: New test.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-compiler/M2Check.mod | 111 +--
 gcc/m2/gm2-compiler/M2GenGCC.mod| 212 ++--
 gcc/m2/gm2-compiler/M2Quads.mod |   2 +-
 gcc/testsuite/gm2/cse/pass/testcse54.mod|   7 +
 gcc/testsuite/gm2/iso/run/pass/array9.mod   |  28 
 gcc/testsuite/gm2/iso/run/pass/strcons3.mod |  30 
 gcc/testsuite/gm2/iso/run/pass/strcons4.mod |  36 +
 gcc/testsuite/gm2/pim/fail/badset1.mod  |  13 ++
 gcc/testsuite/gm2/pim/fail/badset2.mod  |  13 ++
 gcc/testsuite/gm2/pim/fail/badset3.mod  |  11 ++
 gcc/testsuite/gm2/pim/fail/badset4.mod  |  11 ++
 11 files changed, 383 insertions(+), 91 deletions(-)

diff --git a/gcc/m2/gm2-compiler/M2Check.mod b/gcc/m2/gm2-compiler/M2Check.mod
index 5b45ad39c11..20d463d207b 100644
--- a/gcc/m2/gm2-compiler/M2Check.mod
+++ b/gcc/m2/gm2-compiler/M2Check.mod
@@ -46,7 +46,8 @@ FROM SymbolTable IMPORT NulSym, IsRecord, IsSet, GetDType, 
GetSType, IsType,
 GetDeclaredMod, IsSubrange, GetArraySubscript, IsConst,
 IsReallyPointer, IsPointer, IsParameter, ModeOfAddr,
 GetMode, GetType, IsUnbounded, IsComposite, 
IsConstructor,
-IsParameter, IsConstString, IsConstLitInternal, 
IsConstLit ;
+IsParameter, IsConstString, IsConstLitInternal, 
IsConstLit,
+GetStringLength ;
 
 FROM M2GCCDeclare IMPORT GetTypeMin, GetTypeMax ;
 FROM M2System IMPORT Address ;
@@ -258,7 +259,35 @@ END checkSubrange ;
 
 
 (*
-   checkArrayTypeEquivalence -
+   checkUnbounded - check to see if the unbounded is type compatible with 
right.
+This is only allowed during parameter passing.
+*)
+
+PROCEDURE checkUnbounded (result: status; tinfo: tInfo; unbounded, right: 
CARDINAL) : status ;
+VAR
+   lLow,  rLow,
+   lHigh, rHigh: CARDINAL ;
+BEGIN
+   (* Firstly check to see if we have resolved this as false.  *)
+   IF isFalse (result)
+   THEN
+  RETURN result
+   ELSE
+  Assert (IsUnbounded (unbounded)) ;
+  IF tinfo^.kind = parameter
+  THEN
+ (* --fixme-- we should check the unbounded data type against the type 
of right.  *)
+ RETURN true
+  ELSE
+ (* Not allowed to use an unbounded symbol (type) in an expression or 
assignment.  *)
+ RETURN false
+  END
+   END
+END checkUnbounded ;
+
+
+(*
+   checkArrayTypeEquivalence - check array and unbounded array type 
equivalence.
 *)
 
 PROCEDURE checkArrayTypeEquivalence (result: status; tinfo: tInfo;
@@ -273,7 +302,7 @@ BEGIN
THEN
   lSub := GetArraySubscript (left) ;
   rSub := GetArraySubscript (right) ;
-  result := checkPair (result, tinfo, GetType (left), GetType (right)) ;
+  result := checkPair (result, tinfo, GetSType (left), GetSType (right)) ;
   IF (lSub # NulSym) AND (rSub # NulSym)
   THEN
  result := checkSubrange (result, tinfo, getSType (lSub), getSType 
(rSub))
@@ -284,8 +313,22 @@ BEGIN
   THEN
  RETURN true
   ELSE
- result := checkPair (result, tinfo, GetType (left), GetType (right))
+ re

[gcc r14-9475] PR modula2/114333 set type comparison against cardinal should cause error addendum

2024-03-14 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:7aeedff6a426cc05024af0bc92116d676a5ba42b

commit r14-9475-g7aeedff6a426cc05024af0bc92116d676a5ba42b
Author: Gaius Mulley 
Date:   Thu Mar 14 15:34:36 2024 +

PR modula2/114333 set type comparison against cardinal should cause error 
addendum

This patch applies the new stricter type checking procedure function to
the remaining 6 comparisons: less, greater, lessequ, greequ, ifin and
ifnotin.

gcc/m2/ChangeLog:

PR modula2/114333
* gm2-compiler/M2GenGCC.mod (CodeStatement): Remove op1, op2 and
op3 parameters to CodeIfLess, CodeIfLessEqu, CodeIfGreEqu, 
CodeIfGre,
CodeIfIn, CodeIfNotIn.
(CodeIfLess): Rewrite.
(PerformCodeIfLess): New procedure.
(CodeIfLess): Rewrite.
(PerformCodeIfLess): New procedure.
(CodeIfLessEqu): Rewrite.
(PerformCodeIfLessEqu): New procedure.
(CodeIfGreEqu): Rewrite.
(PerformCodeIfGreEqu): New procedure.
(CodeIfGre): Rewrite.
(PerformCodeIfGre): New procedure.
(CodeIfIn): Rewrite.
(PerformCodeIfIn): New procedure.
(CodeIfNotIn): Rewrite.
(PerformCodeIfNotIn): New procedure.

gcc/testsuite/ChangeLog:

PR modula2/114333
* gm2/pim/fail/badset5.mod: New test.
* gm2/pim/fail/badset6.mod: New test.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-compiler/M2GenGCC.mod   | 438 -
 gcc/testsuite/gm2/pim/fail/badset5.mod |  13 +
 gcc/testsuite/gm2/pim/fail/badset6.mod |  23 ++
 3 files changed, 300 insertions(+), 174 deletions(-)

diff --git a/gcc/m2/gm2-compiler/M2GenGCC.mod b/gcc/m2/gm2-compiler/M2GenGCC.mod
index 7633b8425ae..7e27373a6ac 100644
--- a/gcc/m2/gm2-compiler/M2GenGCC.mod
+++ b/gcc/m2/gm2-compiler/M2GenGCC.mod
@@ -510,14 +510,14 @@ BEGIN
LogicalAndOp   : CodeSetAnd (q) |
LogicalXorOp   : CodeSetSymmetricDifference (q) |
LogicalDiffOp  : CodeSetLogicalDifference (q) |
-   IfLessOp   : CodeIfLess (q, op1, op2, op3) |
+   IfLessOp   : CodeIfLess (q) |
IfEquOp: CodeIfEqu (q) |
IfNotEquOp : CodeIfNotEqu (q) |
-   IfGreEquOp : CodeIfGreEqu (q, op1, op2, op3) |
-   IfLessEquOp: CodeIfLessEqu (q, op1, op2, op3) |
-   IfGreOp: CodeIfGre (q, op1, op2, op3) |
-   IfInOp : CodeIfIn (q, op1, op2, op3) |
-   IfNotInOp  : CodeIfNotIn (q, op1, op2, op3) |
+   IfGreEquOp : CodeIfGreEqu (q) |
+   IfLessEquOp: CodeIfLessEqu (q) |
+   IfGreOp: CodeIfGre (q) |
+   IfInOp : CodeIfIn (q) |
+   IfNotInOp  : CodeIfNotIn (q) |
IndrXOp: CodeIndrX (q, op1, op2, op3) |
XIndrOp: CodeXIndr (q) |
CallOp : CodeCall (CurrentQuadToken, op3) |
@@ -6831,50 +6831,67 @@ END CodeIfSetLess ;
 
 
 (*
-   CodeIfLess - codes the quadruple if op1 < op2 then goto op3
+   PerformCodeIfLess - codes the quadruple if op1 < op2 then goto op3
 *)
 
-PROCEDURE CodeIfLess (quad: CARDINAL; op1, op2, op3: CARDINAL) ;
+PROCEDURE PerformCodeIfLess (quad: CARDINAL) ;
 VAR
tl, tr  : Tree ;
-   location: location_t ;
+   location   : location_t ;
+   left, right, dest, combined,
+   leftpos, rightpos, destpos : CARDINAL ;
+   overflow   : BOOLEAN ;
+   op : QuadOperator ;
 BEGIN
-   location := TokenToLocation(CurrentQuadToken) ;
+   GetQuadOtok (quad, combined, op,
+left, right, dest, overflow,
+leftpos, rightpos, destpos) ;
+   location := TokenToLocation (combined) ;
 
-   (* firstly ensure that any constant literal is declared *)
-   DeclareConstant(CurrentQuadToken, op1) ;
-   DeclareConstant(CurrentQuadToken, op2) ;
-   IF IsConst(op1) AND IsConst(op2)
+   IF IsConst(left) AND IsConst(right)
THEN
-  PushValue(op1) ;
-  PushValue(op2) ;
+  PushValue(left) ;
+  PushValue(right) ;
   IF Less(CurrentQuadToken)
   THEN
- BuildGoto(location, string(CreateLabelName(op3)))
+ BuildGoto(location, string(CreateLabelName(dest)))
   ELSE
  (* fall through *)
   END
-   ELSIF IsConstSet(op1) OR (IsVar(op1) AND IsSet(SkipType(GetType(op1 OR
- IsConstSet(op2) OR (IsVar(op2) AND IsSet(SkipType(GetType(op2
+   ELSIF IsConstSet(left) OR (IsVar(left) AND IsSet(SkipType(GetType(left 
OR
+ IsConstSet(right) OR (IsVar(right) AND 
IsSet(SkipType(GetType(right
THEN
-  CodeIfSetLess(quad, op1, op2, op3)
+  CodeIfSetLess(quad, left, right, dest)
ELSE
-  IF IsComposite(GetType(op1)) OR IsComposite(GetType(op2))
+  IF IsComposite(GetType(left)) OR IsComposite(GetType(right))
   THEN
- MetaErrorT2 (CurrentQuadToken,
+ MetaErrorT2 (combined,
   'compar

[gcc r14-9483] PR modula2/114294 expression causes ICE

2024-03-14 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:6dbf0d252f69ab2924256e6778ba7dc55d5b6915

commit r14-9483-g6dbf0d252f69ab2924256e6778ba7dc55d5b6915
Author: Gaius Mulley 
Date:   Thu Mar 14 19:09:34 2024 +

PR modula2/114294 expression causes ICE

This patch fixes an ICE when encountering an expression:
1 + HIGH (a[0]).  The fix was to assign a type to the constant
created by BuildConstHighFromSym in M2Quads.mod.

gcc/m2/ChangeLog:

PR modula2/114294
* gm2-compiler/M2Quads.mod (BuildConstHighFromSym):
Call PutConst to assign the type Cardinal in the result
constant.

gcc/testsuite/ChangeLog:

PR modula2/114294
* gm2/pim/pass/log: Removed.
* gm2/pim/pass/highexp.mod: New test.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-compiler/M2Quads.mod|   1 +
 gcc/testsuite/gm2/pim/pass/highexp.mod |   9 +
 gcc/testsuite/gm2/pim/pass/log | 457 -
 3 files changed, 10 insertions(+), 457 deletions(-)

diff --git a/gcc/m2/gm2-compiler/M2Quads.mod b/gcc/m2/gm2-compiler/M2Quads.mod
index 0263074d845..1776a09b41f 100644
--- a/gcc/m2/gm2-compiler/M2Quads.mod
+++ b/gcc/m2/gm2-compiler/M2Quads.mod
@@ -8400,6 +8400,7 @@ VAR
 BEGIN
PopT (NoOfParam) ;
ReturnVar := MakeTemporary (tok, ImmediateValue) ;
+   PutConst (ReturnVar, Cardinal) ;
GenHigh (tok, ReturnVar, 1, OperandT (1)) ;
PopN (NoOfParam+1) ;
PushTtok (ReturnVar, tok)
diff --git a/gcc/testsuite/gm2/pim/pass/highexp.mod 
b/gcc/testsuite/gm2/pim/pass/highexp.mod
new file mode 100644
index 000..f98be7df331
--- /dev/null
+++ b/gcc/testsuite/gm2/pim/pass/highexp.mod
@@ -0,0 +1,9 @@
+MODULE highexp ;
+
+
+VAR
+   a: ARRAY [0..9] OF CHAR ;
+   c: CARDINAL ;
+BEGIN
+   c := 1 + HIGH (a)
+END highexp.
diff --git a/gcc/testsuite/gm2/pim/pass/log b/gcc/testsuite/gm2/pim/pass/log
deleted file mode 100644
index 5bbdc50ab6e..000
--- a/gcc/testsuite/gm2/pim/pass/log
+++ /dev/null
@@ -1,457 +0,0 @@
-=
-Stabs setchar3
-GNU gdb 6.3
-Copyright (C) 2004-2024 Free Software Foundation, Inc.
-GDB is free software, covered by the GNU General Public License, and you are
-welcome to change it and/or distribute copies of it under certain conditions.
-Type "show copying" to see the conditions.
-There is absolutely no warranty for GDB.  Type "show warranty" for details.
-This GDB was configured as "x86_64-unknown-linux-gnu"...Using host 
libthread_db library "/lib/libthread_db.so.1".
-
-Breakpoint 1 at 0x421298: file setchar3.mod, line 30.
-
-Breakpoint 1, _M2_setchar3_init () at setchar3.mod:30
-30ch := 'z' ;
-31s := smallchar{} ;
-$1 = {}
-type = SET ['A'..'Z']
-=
-Dwarf2 setchar3
-GNU gdb 6.3
-Copyright (C) 2004-2024 Free Software Foundation, Inc.
-GDB is free software, covered by the GNU General Public License, and you are
-welcome to change it and/or distribute copies of it under certain conditions.
-Type "show copying" to see the conditions.
-There is absolutely no warranty for GDB.  Type "show warranty" for details.
-This GDB was configured as "x86_64-unknown-linux-gnu"...Using host 
libthread_db library "/lib/libthread_db.so.1".
-
-Breakpoint 1 at 0x421298: file setchar3.mod, line 30.
-
-Breakpoint 1, _M2_setchar3_init () at setchar3.mod:30
-30ch := 'z' ;
-31s := smallchar{} ;
-$1 = {}
-type = SET ['A'..'Z']
-=
-Stabs subrange15
-GNU gdb 6.3
-Copyright (C) 2004-2024 Free Software Foundation, Inc.
-GDB is free software, covered by the GNU General Public License, and you are
-welcome to change it and/or distribute copies of it under certain conditions.
-Type "show copying" to see the conditions.
-There is absolutely no warranty for GDB.  Type "show warranty" for details.
-This GDB was configured as "x86_64-unknown-linux-gnu"...Using host 
libthread_db library "/lib/libthread_db.so.1".
-
-Breakpoint 1 at 0x421298: file subrange15.mod, line 8.
-
-Breakpoint 1, _M2_subrange15_init () at subrange15.mod:8
-8 s := 20 ;
-9 s := 21 ;
-$1 = 20
-type = [20..40]
-=
-Dwarf2 subrange15
-GNU gdb 6.3
-Copyright (C) 2004-2024 Free Software Foundation, Inc.
-GDB is free software, covered by the GNU General Public License, and you are
-welcome to change it and/or distribute copies of it under certain conditions.
-Type "show copying" to see the conditions.
-There is absolutely no warranty for GDB.  Type "show warranty" for details.
-This GDB was configured as "x86_64-unknown-linux-gnu"...Using host 
libthread_db library "/lib/libthread_db.so.1".
-
-Breakpoint 1 at 0x421298: file subrange15.mod, line 8.
-
-Breakpoint 1, _M2_subrange15_init () at subrange15.mod:8
-8 s := 20 ;
-9 s := 21 ;
-$1 = 20
-type = [20..40]
-

[gcc r14-9506] PR modula2/114296 ICE when attempting to create a constant set with a variable element

2024-03-17 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:f065c582d9c8e0a4fee7ee563c584ee3b1975bea

commit r14-9506-gf065c582d9c8e0a4fee7ee563c584ee3b1975bea
Author: Gaius Mulley 
Date:   Sun Mar 17 14:49:23 2024 +

PR modula2/114296 ICE when attempting to create a constant set with a 
variable element

This patch corrects the virtual token creation for the aggregate constant
and also corrects tokens for constructor components.

gcc/m2/ChangeLog:

PR modula2/114296
* gm2-compiler/M2ALU.mod (ElementsSolved): Add tokenno parameter.
Add constant checks and generate error messages.
(EvalSetValues): Pass tokenno parameter to ElementsSolved.
* gm2-compiler/M2LexBuf.mod (stop): New procedure.
(MakeVirtualTok): Call stop if caret = BadTokenNo.
* gm2-compiler/M2Quads.def (BuildNulExpression): Add tokpos
parameter.
(BuildSetStart): Ditto.
(BuildEmptySet): Ditto.
(BuildConstructorEnd): Add startpos parameter.
(BuildTypeForConstructor): Add tokpos parameter.
* gm2-compiler/M2Quads.mod (BuildNulExpression): Add tokpos
parameter and push tokpos to the quad stack.
(BuildSetStart): Add tokpos parameter and push tokpos.
(BuildSetEnd): Rewrite.
(BuildEmptySet): Add tokpos parameter and push tokpos with
the set type.
(BuildConstructorStart): Pop typepos.
(BuildConstructorEnd): Add startpos parameter.
Create valtok from startpos and cbratokpos.
(BuildTypeForConstructor): Add tokpos parameter.
* gm2-compiler/M2Range.def (InitAssignmentRangeCheck): Rename
d to des and e to expr.
Add destok and exprtok parameters.
* gm2-compiler/M2Range.mod (InitAssignmentRangeCheck): Rename
d to des and e to expr.
Add destok and exprtok parameters.
Save destok and exprtok into range record.
(FoldAssignment): Pass exprtok to TryDeclareConstant.
* gm2-compiler/P3Build.bnf (ComponentValue): Rewrite.
(Constructor): Rewrite.
(ConstSetOrQualidentOrFunction): Rewrite.
(SetOrQualidentOrFunction): Rewrite.
* gm2-compiler/PCBuild.bnf (ConstSetOrQualidentOrFunction): Rewrite.
(SetOrQualidentOrFunction): Rewrite.
* gm2-compiler/PHBuild.bnf (Constructor): Rewrite.
(ConstSetOrQualidentOrFunction): Rewrite.

gcc/testsuite/ChangeLog:

PR modula2/114296
* gm2/pim/fail/badtype2.mod: New test.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-compiler/M2ALU.mod   |  14 +++-
 gcc/m2/gm2-compiler/M2LexBuf.mod|  13 +++-
 gcc/m2/gm2-compiler/M2Quads.def |  15 ++--
 gcc/m2/gm2-compiler/M2Quads.mod | 124 ++--
 gcc/m2/gm2-compiler/M2Range.def |   4 +-
 gcc/m2/gm2-compiler/M2Range.mod |  14 ++--
 gcc/m2/gm2-compiler/P3Build.bnf |  48 -
 gcc/m2/gm2-compiler/PCBuild.bnf |  11 +--
 gcc/m2/gm2-compiler/PHBuild.bnf |  16 +++--
 gcc/testsuite/gm2/pim/fail/badtype2.mod |   9 +++
 10 files changed, 173 insertions(+), 95 deletions(-)

diff --git a/gcc/m2/gm2-compiler/M2ALU.mod b/gcc/m2/gm2-compiler/M2ALU.mod
index 58d4b5c24ed..cfa372671cd 100644
--- a/gcc/m2/gm2-compiler/M2ALU.mod
+++ b/gcc/m2/gm2-compiler/M2ALU.mod
@@ -2922,10 +2922,20 @@ END AddField ;
ElementsSolved - returns TRUE if all ranges in the set have been solved.
 *)
 
-PROCEDURE ElementsSolved (r: listOfRange) : BOOLEAN ;
+PROCEDURE ElementsSolved (tokenno: CARDINAL; r: listOfRange) : BOOLEAN ;
 BEGIN
WHILE r#NIL DO
   WITH r^ DO
+ IF NOT IsConst (low)
+ THEN
+MetaErrorT1 (tokenno, 'a constant set can only contain constant 
set elements, {%1Ead} is not a constant',
+ low)
+ END ;
+ IF (high # low) AND (NOT IsConst (high))
+ THEN
+MetaErrorT1 (tokenno, 'a constant set can only contain constant 
set elements, {%1Ead} is not a constant',
+ high)
+ END ;
  IF NOT (IsSolvedGCC(low) AND IsSolvedGCC(high))
  THEN
 RETURN( FALSE )
@@ -3088,7 +3098,7 @@ END CombineElements ;
 
 PROCEDURE EvalSetValues (tokenno: CARDINAL; r: listOfRange) : BOOLEAN ;
 BEGIN
-   IF ElementsSolved(r)
+   IF ElementsSolved (tokenno, r)
THEN
   SortElements(tokenno, r) ;
   CombineElements(tokenno, r) ;
diff --git a/gcc/m2/gm2-compiler/M2LexBuf.mod b/gcc/m2/gm2-compiler/M2LexBuf.mod
index 8d9b5a5a6e3..df073630bc1 100644
--- a/gcc/m2/gm2-compiler/M2LexBuf.mod
+++ b/gcc/m2/gm2-compiler/M2LexBuf.mod
@@ -48,6 +48,7 @@ CONST
Tracing= FALSE ;
Debugging  = FALSE ;
DebugRecover   = FALSE ;
+   BadTokenNo = 32579 ;
InitialSourceToken = 2 ;  

[gcc r14-9520] PR modula2/114380 Incorrect type specified in an error message

2024-03-18 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:d2029bbc69df7341775faf6cf1aa13d978c223a1

commit r14-9520-gd2029bbc69df7341775faf6cf1aa13d978c223a1
Author: Gaius Mulley 
Date:   Mon Mar 18 16:40:35 2024 +

PR modula2/114380 Incorrect type specified in an error message

This patch corrects an error message relating to a variable of
a SET type. The bugfix is not to skip over set types (in
GetLowestType).

gcc/m2/ChangeLog:

PR modula2/114380
* gm2-compiler/SymbolTable.mod (GetLowestType): Do not
skip over a set type, but return sym.

gcc/testsuite/ChangeLog:

PR modula2/114380
* gm2/pim/fail/badset7.mod: New test.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-compiler/SymbolTable.mod|  2 +-
 gcc/testsuite/gm2/pim/fail/badset7.mod | 14 ++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/gcc/m2/gm2-compiler/SymbolTable.mod 
b/gcc/m2/gm2-compiler/SymbolTable.mod
index c08de6a97c3..9d572cff19c 100644
--- a/gcc/m2/gm2-compiler/SymbolTable.mod
+++ b/gcc/m2/gm2-compiler/SymbolTable.mod
@@ -6154,7 +6154,7 @@ BEGIN
   SubrangeSym : type := Subrange.Type |
   ArraySym: type := Array.Type |
   SubscriptSym: type := Subscript.Type |
-  SetSym  : type := Set.Type |
+  SetSym  : type := Sym |(* Stop at the set type.  *)
   UnboundedSym: type := Unbounded.Type |
   UndefinedSym: type := NulSym |
   DummySym: type := NulSym
diff --git a/gcc/testsuite/gm2/pim/fail/badset7.mod 
b/gcc/testsuite/gm2/pim/fail/badset7.mod
new file mode 100644
index 000..5c2499be739
--- /dev/null
+++ b/gcc/testsuite/gm2/pim/fail/badset7.mod
@@ -0,0 +1,14 @@
+MODULE badset7 ;
+
+FROM SYSTEM IMPORT WORD ;
+
+PROCEDURE func () : WORD ;
+BEGIN
+   RETURN WORD (0)
+END func ;
+
+VAR
+   b: BITSET ;
+BEGIN
+   b := func () - {6..31}
+END badset7.


[gcc r14-9598] PR modula2/114418 missing import of TSIZE from system causes ICE

2024-03-21 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:ba744d50ac0360f7992a42494db766f6548913e3

commit r14-9598-gba744d50ac0360f7992a42494db766f6548913e3
Author: Gaius Mulley 
Date:   Thu Mar 21 18:30:23 2024 +

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:
---
 gcc/m2/gm2-compiler/PCSymBuild.mod   | 48 +---
 gcc/testsuite/gm2/pim/fail/missingtsize.mod  |  8 +
 gcc/testsuite/gm2/pim/fail/missingtsize2.mod |  8 +
 3 files changed, 53 insertions(+), 11 deletions(-)

diff --git a/gcc/m2/gm2-compiler/PCSymBuild.mod 
b/gcc/m2/gm2-compiler/PCSymBuild.mod
index e2165408781..9a6e8c06e70 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 000..23ec055d7be
--- /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 000..8e859445ab0
--- /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


[gcc r14-9599] PR modula2/113836 gm2 does not dump gimple or quadruples to file

2024-03-21 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:48d49200510198cafcab55601cd8e5f8eb541f01

commit r14-9599-g48d49200510198cafcab55601cd8e5f8eb541f01
Author: Gaius Mulley 
Date:   Thu Mar 21 19:38:03 2024 +

PR modula2/113836 gm2 does not dump gimple or quadruples to file

This patch provides the localized modula2 changes to gcc/m2
which facilitate the dumping of gimple and quadruples to file.
PR modula2/113836 will be full complete after a subsequent patch
adding changes to lang.opt and documentation.  The lang.opt
patch requires all language bootstrap regression testing whereas
this patch is isolated to gcc/m2 and only the m2 language.

gcc/m2/ChangeLog:

PR modula2/113836
* Make-lang.in (GM2_C_OBJS): Add m2/gm2-gcc/m2pp.o.
(m2/m2pp.o): Remove rule.
(GM2-COMP-BOOT-DEFS): Add M2LangDump.def.
(GM2-COMP-BOOT-MODS): Add M2LangDump.mod.
(GM2-GCC-DEFS): Add M2LangDump.def.
(GM2-GCC-MODS): Add M2LangDump.mod.
* gm2-compiler/M2CaseList.mod (WriteCase): Rewrite.
* gm2-compiler/M2Code.mod (DoModuleDeclare): Call
DumpFilteredResolver depending upon DumpLangDecl.
(DoCodeBlock): Call CreateDumpGimple depending upon
DumpLangGimple.
(Code): Replace DisplayQuadList blocks with DumpQuadruples.
(DisplayQuadsInScope): Remove.
(DisplayQuadNumbers): Remove.
(CodeBlock): Rewrite.
* gm2-compiler/M2GCCDeclare.def (IncludeDumpSymbol): New procedure.
(DumpFilteredResolver): New procedure.
(DumpFilteredDefinitive): New procedure.
* gm2-compiler/M2GCCDeclare.mod (IncludeDumpSymbol): New procedure.
(DumpFilteredResolver): New procedure.
(DumpFilteredDefinitive): New procedure.
(doInclude): Rewrite to use GetDumpFile.
(WatchIncludeList): Remove fixed debugging value.
(doExclude): Rewrite to use GetDumpFile.
(DeclareTypesConstantsProceduresInRange): Remove fixed debugging
values.
(PreAddModGcc): Rename parameter t as tree.
(IncludeGetNth): Rewrite to use GetDumpFile.
(IncludeType): Ditto.
(IncludeSubscript): Ditto.
(PrintLocalSymbol): Ditto.
(PrintLocalSymbols): Ditto.
(IncludeGetVarient): Ditto.
(PrintDeclared): Ditto.
(PrintAlignment): Ditto.
(PrintDecl): Ditto.
(PrintScope): Ditto.
(PrintProcedure): Ditto.
(PrintSym): Ditto.
(PrintSymbol): Ditto.
(PrintTerse): Ditto.
* gm2-compiler/M2Options.def (GetDumpLangDeclFilename): New
procedure function.
(SetDumpLangDeclFilename): New procedure.
(GetDumpLangQuadFilename): New procedure function.
(SetDumpLangQuadFilename): New procedure.
(GetDumpLangGimpleFilename): New procedure function.
(SetDumpLangGimpleFilename): New procedure.
(SetM2DumpFilter): New procedure.
(GetM2DumpFilter): New procedure function.
(GetDumpLangGimple): New procedure function.
* gm2-compiler/M2Options.mod (GetDumpLangDeclFilename): New
procedure function.
(SetDumpLangDeclFilename): New procedure.
(GetDumpLangQuadFilename): New procedure function.
(SetDumpLangQuadFilename): New procedure.
(GetDumpLangGimpleFilename): New procedure function.
(SetDumpLangGimpleFilename): New procedure.
(SetM2DumpFilter): New procedure.
(GetM2DumpFilter): New procedure function.
(GetDumpLangGimple): New procedure function.
* gm2-compiler/M2Quads.def (DumpQuadruples): New procedure.
* gm2-compiler/M2Quads.mod (DumpUntil): New procedure.
(GetCtorInit): New procedure function.
(GetCtorFini): New procedure function.
(DumpQuadrupleFilter): New procedure function.
(DumpQuadrupleAll): New procedure.
(DisplayQuadList): Remove procedure.
(DumpQuadruples): New procedure.
(DisplayQuadRange): Rewrite.
(DisplayQuad): Ditto.
(DisplayProcedureAttributes): Ditto.
(WriteOperator): Ditto.
(WriteMode): Ditto.
* gm2-compiler/M2Scope.mod (ForeachScopeBlockDo2): Replace
DisplayQuadruples with TraceQuadruples.
(ForeachScopeBlockDo3): Replace DisplayQuadruples with
TraceQuadruples.
* gm2-compiler/SymbolConversion.def (Gcc2Mod): New procedure 
function.
* gm2-compiler/SymbolConversion.mod: New procedure function.
* gm2-gcc/m2misc.cc (m2misc_DebugTree): New function.
(m2misc_DebugTreeChain): New function.
* gm2-gcc/m2options.h (M2Options_GetDumpLangDeclF

[gcc r14-9602] PR modula2/114422 Attempting to declare a set of unknown type causes ICE

2024-03-21 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:1542e8a44cc35e63233d3557afbf501c5ff84c55

commit r14-9602-g1542e8a44cc35e63233d3557afbf501c5ff84c55
Author: Gaius Mulley 
Date:   Fri Mar 22 01:47:31 2024 +

PR modula2/114422 Attempting to declare a set of unknown type causes ICE

This patch corrects an error message directive which did not
escape the { character.  The patch also contains test cases
to stress set declaration errors.

gcc/m2/ChangeLog:

PR modula2/114422
* gm2-compiler/M2Quads.mod (BuildConstructor): Add escape
character.

gcc/testsuite/ChangeLog:

PR modula2/114422
* gm2/iso/fail/badset.mod: New test.
* gm2/iso/fail/badset2.mod: New test.
* gm2/iso/fail/badset3.mod: New test.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-compiler/M2Quads.mod| 2 +-
 gcc/testsuite/gm2/iso/fail/badset.mod  | 7 +++
 gcc/testsuite/gm2/iso/fail/badset2.mod | 9 +
 gcc/testsuite/gm2/iso/fail/badset3.mod | 9 +
 4 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/gcc/m2/gm2-compiler/M2Quads.mod b/gcc/m2/gm2-compiler/M2Quads.mod
index ac654e89c91..52d72f6cd62 100644
--- a/gcc/m2/gm2-compiler/M2Quads.mod
+++ b/gcc/m2/gm2-compiler/M2Quads.mod
@@ -12172,7 +12172,7 @@ BEGIN
IF type = NulSym
THEN
   MetaErrorT0 (tokcbrpos,
-   '{%E}constructor requires a type before the opening {')
+   '{%E}constructor requires a type before the opening %{')
ELSE
   ChangeToConstructor (tok, type) ;
   PutConstructorFrom (constValue, type) ;
diff --git a/gcc/testsuite/gm2/iso/fail/badset.mod 
b/gcc/testsuite/gm2/iso/fail/badset.mod
new file mode 100644
index 000..8bfc49f948e
--- /dev/null
+++ b/gcc/testsuite/gm2/iso/fail/badset.mod
@@ -0,0 +1,7 @@
+MODULE badset ;
+
+VAR
+   set: set ;
+BEGIN
+
+END badset.
diff --git a/gcc/testsuite/gm2/iso/fail/badset2.mod 
b/gcc/testsuite/gm2/iso/fail/badset2.mod
new file mode 100644
index 000..d883d1ffe75
--- /dev/null
+++ b/gcc/testsuite/gm2/iso/fail/badset2.mod
@@ -0,0 +1,9 @@
+MODULE badset2 ;
+
+TYPE
+   userset = SET OF CHAR ;
+VAR
+   set: userset ;
+BEGIN
+   set := set {}
+END badset2.
diff --git a/gcc/testsuite/gm2/iso/fail/badset3.mod 
b/gcc/testsuite/gm2/iso/fail/badset3.mod
new file mode 100644
index 000..29131ff4c5a
--- /dev/null
+++ b/gcc/testsuite/gm2/iso/fail/badset3.mod
@@ -0,0 +1,9 @@
+MODULE badset3 ;
+
+TYPE
+   userset = SET OF CHAR ;
+VAR
+   set: userset ;
+BEGIN
+   set := unknown {}
+END badset3.


[gcc r14-9647] PR modula2/114443 missing quote cause ICE

2024-03-23 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:c8a343f9f8602f4e6c1b385ddbeb58572234d447

commit r14-9647-gc8a343f9f8602f4e6c1b385ddbeb58572234d447
Author: Gaius Mulley 
Date:   Sat Mar 23 15:49:23 2024 +

PR modula2/114443 missing quote cause ICE

This patch inserts a missing quotation at the end of a line
if required (after an appropiate error message is generated).

gcc/m2/ChangeLog:

PR modula2/114443
* m2.flex: Call AddTokCharStar with a stringtok if
end of line is reached without a closing quote.

gcc/testsuite/ChangeLog:

PR modula2/114443
* gm2/pim/fail/missingquote.mod: New test.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/m2.flex  | 2 ++
 gcc/testsuite/gm2/pim/fail/missingquote.mod | 8 
 2 files changed, 10 insertions(+)

diff --git a/gcc/m2/m2.flex b/gcc/m2/m2.flex
index f8f5ce64ad3..e8ee383878e 100644
--- a/gcc/m2/m2.flex
+++ b/gcc/m2/m2.flex
@@ -188,12 +188,14 @@ extern  void  yylex   (void);
 \"[^\"\n]*\"   { updatepos(); 
M2LexBuf_AddTokCharStar(M2Reserved_stringtok, yytext); return; }
 \"[^\"\n]*${ updatepos();
  m2flex_M2Error("missing terminating quote, \"");
+M2LexBuf_AddTokCharStar(M2Reserved_stringtok, 
yytext);
  resetpos(); return;
}
 
 '[^'\n]*'  { updatepos(); 
M2LexBuf_AddTokCharStar(M2Reserved_stringtok, yytext); return; }
 '[^'\n]*$  { updatepos();
  m2flex_M2Error("missing terminating quote, '");
+M2LexBuf_AddTokCharStar(M2Reserved_stringtok, 
yytext);
  resetpos(); return;
}
 
diff --git a/gcc/testsuite/gm2/pim/fail/missingquote.mod 
b/gcc/testsuite/gm2/pim/fail/missingquote.mod
new file mode 100644
index 000..e78f0e339ac
--- /dev/null
+++ b/gcc/testsuite/gm2/pim/fail/missingquote.mod
@@ -0,0 +1,8 @@
+MODULE missingquote ;
+
+CONST
+   MyConst = 'foobar
+
+BEGIN
+
+END missingquote.


[gcc r14-9648] PR modula2/114444 trunc float malformed error cause ICE

2024-03-23 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:a68458187d4c889dc11b2b95f08a61adf087f69d

commit r14-9648-ga68458187d4c889dc11b2b95f08a61adf087f69d
Author: Gaius Mulley 
Date:   Sat Mar 23 16:04:23 2024 +

PR modula2/11 trunc float malformed error cause ICE

This patch corrects two error format specifiers.

gcc/m2/ChangeLog:

PR modula2/11
* gm2-compiler/M2Quads.mod (BuildTruncFunction): Correct
error format specifier.
(BuildFloatFunction): Correct error format specifier.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-compiler/M2Quads.mod | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/m2/gm2-compiler/M2Quads.mod b/gcc/m2/gm2-compiler/M2Quads.mod
index 52d72f6cd62..891a76b4660 100644
--- a/gcc/m2/gm2-compiler/M2Quads.mod
+++ b/gcc/m2/gm2-compiler/M2Quads.mod
@@ -9840,12 +9840,12 @@ BEGIN
BuildConvertFunction
 ELSE
MetaErrorT1 (functok,
-'argument to {%1E%ad} must be a float point type', 
Sym) ;
+'argument to {%1Ead} must be a float point type', 
Sym) ;
PushTFtok (MakeConstLit (functok, MakeKey('0'), Type), Type, 
functok)
 END
  ELSE
 MetaErrorT2 (vartok,
- 'argument to {%1E%ad} must be a variable or constant, 
seen {%2ad}',
+ 'argument to {%1Ead} must be a variable or constant, 
seen {%2ad}',
  Sym, Var) ;
 PushTFtok (MakeConstLit (functok, MakeKey('0'), Type), Type, 
functok)
  END
@@ -9924,7 +9924,7 @@ BEGIN
 BuildConvertFunction
  ELSE
 MetaErrorT1 (vartok,
- 'argument to {%1E%ad} must be a variable or 
constant', ProcSym) ;
+ 'argument to {%1Ead} must be a variable or constant', 
ProcSym) ;
 PushTFtok (MakeConstLit (functok, MakeKey('0.0'), Type), Type, 
functok)
  END
   ELSE


[gcc r14-9653] modula2: Rebuild documentation sections for target independent libs

2024-03-25 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:44863af22d2c3168fb73d00cc58f393a35d3070d

commit r14-9653-g44863af22d2c3168fb73d00cc58f393a35d3070d
Author: Gaius Mulley 
Date:   Mon Mar 25 14:33:54 2024 +

modula2: Rebuild documentation sections for target independent libs

This patch rebuilds the documentation for the target independent
library sections.

gcc/m2/ChangeLog:

* Make-lang.in (doc/m2.pdf): Add line break.
* target-independent/m2/Builtins.texi: Rebuilt.
* target-independent/m2/gm2-libs.texi: Rebuilt.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/Make-lang.in|   3 +-
 gcc/m2/target-independent/m2/Builtins.texi |  11 +-
 gcc/m2/target-independent/m2/gm2-libs.texi | 599 +++--
 3 files changed, 574 insertions(+), 39 deletions(-)

diff --git a/gcc/m2/Make-lang.in b/gcc/m2/Make-lang.in
index 49ec168b205..ef6990ce617 100644
--- a/gcc/m2/Make-lang.in
+++ b/gcc/m2/Make-lang.in
@@ -168,7 +168,8 @@ doc/m2.ps: doc/m2.dvi
 m2.pdf: doc/m2.pdf
 
 doc/m2.pdf: $(TEXISRC) $(objdir)/m2/images/gnu.eps
-   $(TEXI2PDF) -I $(objdir)/m2 -I $(srcdir)/doc/include 
$(srcdir)/doc/gm2.texi -o $@
+   $(TEXI2PDF) -I $(objdir)/m2 -I $(srcdir)/doc/include \
+  $(srcdir)/doc/gm2.texi -o $@
 
 M2_PDFFILES = doc/m2.pdf
 
diff --git a/gcc/m2/target-independent/m2/Builtins.texi 
b/gcc/m2/target-independent/m2/Builtins.texi
index 6f50bfa338e..b6903215293 100644
--- a/gcc/m2/target-independent/m2/Builtins.texi
+++ b/gcc/m2/target-independent/m2/Builtins.texi
@@ -6,6 +6,13 @@ FROM SYSTEM IMPORT ADDRESS ;
 
 (* floating point intrinsic procedure functions *)
 
+@findex isnanf
+PROCEDURE __BUILTIN__ isnanf (x: SHORTREAL) : INTEGER ;
+@findex isnan
+PROCEDURE __BUILTIN__ isnan (x: REAL) : INTEGER ;
+@findex isnanl
+PROCEDURE __BUILTIN__ isnanl (x: LONGREAL) : INTEGER ;
+
 @findex isfinitef
 PROCEDURE __BUILTIN__ isfinitef (x: SHORTREAL) : INTEGER ;
 @findex isfinite
@@ -113,9 +120,9 @@ PROCEDURE __BUILTIN__ nextafterf (x, y: SHORTREAL) : 
SHORTREAL ;
 PROCEDURE __BUILTIN__ nextafterl (x, y: LONGREAL) : LONGREAL ;
 
 @findex nexttoward
-PROCEDURE __BUILTIN__ nexttoward (x, y: REAL) : LONGREAL ;
+PROCEDURE __BUILTIN__ nexttoward (x: REAL; y: LONGREAL) : REAL ;
 @findex nexttowardf
-PROCEDURE __BUILTIN__ nexttowardf (x, y: SHORTREAL) : LONGREAL ;
+PROCEDURE __BUILTIN__ nexttowardf (x: SHORTREAL; y: LONGREAL) : SHORTREAL ;
 @findex nexttowardl
 PROCEDURE __BUILTIN__ nexttowardl (x, y: LONGREAL) : LONGREAL ;
 
diff --git a/gcc/m2/target-independent/m2/gm2-libs.texi 
b/gcc/m2/target-independent/m2/gm2-libs.texi
index 0531a4a1753..db8189f4059 100644
--- a/gcc/m2/target-independent/m2/gm2-libs.texi
+++ b/gcc/m2/target-independent/m2/gm2-libs.texi
@@ -242,6 +242,13 @@ FROM SYSTEM IMPORT ADDRESS ;
 
 (* floating point intrinsic procedure functions *)
 
+@findex isnanf
+PROCEDURE __BUILTIN__ isnanf (x: SHORTREAL) : INTEGER ;
+@findex isnan
+PROCEDURE __BUILTIN__ isnan (x: REAL) : INTEGER ;
+@findex isnanl
+PROCEDURE __BUILTIN__ isnanl (x: LONGREAL) : INTEGER ;
+
 @findex isfinitef
 PROCEDURE __BUILTIN__ isfinitef (x: SHORTREAL) : INTEGER ;
 @findex isfinite
@@ -349,9 +356,9 @@ PROCEDURE __BUILTIN__ nextafterf (x, y: SHORTREAL) : 
SHORTREAL ;
 PROCEDURE __BUILTIN__ nextafterl (x, y: LONGREAL) : LONGREAL ;
 
 @findex nexttoward
-PROCEDURE __BUILTIN__ nexttoward (x, y: REAL) : LONGREAL ;
+PROCEDURE __BUILTIN__ nexttoward (x: REAL; y: LONGREAL) : REAL ;
 @findex nexttowardf
-PROCEDURE __BUILTIN__ nexttowardf (x, y: SHORTREAL) : LONGREAL ;
+PROCEDURE __BUILTIN__ nexttowardf (x: SHORTREAL; y: LONGREAL) : SHORTREAL ;
 @findex nexttowardl
 PROCEDURE __BUILTIN__ nexttowardl (x, y: LONGREAL) : LONGREAL ;
 
@@ -662,10 +669,10 @@ DEFINITION MODULE DynamicStrings ;
 FROM SYSTEM IMPORT ADDRESS ;
 EXPORT QUALIFIED String,
  InitString, KillString, Fin, InitStringCharStar,
- InitStringChar, Index, RIndex,
+ InitStringChar, Index, RIndex, ReverseIndex,
  Mark, Length, ConCat, ConCatChar, Assign, Dup, Add,
  Equal, EqualCharStar, EqualArray, ToUpper, ToLower,
- CopyOut, Mult, Slice,
+ CopyOut, Mult, Slice, ReplaceChar,
  RemoveWhitePrefix, RemoveWhitePostfix, RemoveComment,
  char, string,
  InitStringDB, InitStringCharStarDB, InitStringCharDB,
@@ -766,6 +773,15 @@ PROCEDURE ConCatChar (a: String; ch: CHAR) : String ;
 PROCEDURE Assign (a, b: String) : String ;
 
 
+(*
+   ReplaceChar - returns string s after it has changed all
+ occurances of from to to.
+*)
+
+@findex ReplaceChar
+PROCEDURE ReplaceChar (s: String; from, to: CHAR) : String ;
+
+
 (*
Dup - duplicate a String, s, returning the copy of s.
 *)
@@ -845,14 +861,29 @@ PROCEDURE Index (s: String; ch: CHAR; o: CARDINAL) : 
INTEGER ;
 
 (*
RIndex - returns the indice of the last occurance of, ch,
-in

[gcc r14-9675] PR modula2/114478 isnormal builtin unavailable from m2

2024-03-26 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:b1af867d22e3108402c62f97d8fcd1df303c9dab

commit r14-9675-gb1af867d22e3108402c62f97d8fcd1df303c9dab
Author: Gaius Mulley 
Date:   Tue Mar 26 15:33:52 2024 +

PR modula2/114478 isnormal builtin unavailable from m2

This patch adds isnormal (and isgreater, isless, isgreaterequal,
islessequal, islessgreater, isunordered) c99 macro similar prototyped
builtins to m2.

gcc/m2/ChangeLog:

PR modula2/114478
* gm2-gcc/m2builtins.cc (struct builtin_macro_definition): New 
struct.
(lookup_builtin_macro): New function.
(m2builtins_BuildBuiltinTree): Rewrite to lookup builtin function
and builtin macro.
(lookup_builtin_function): New function.
(define_builtin): Rename parameter type to prototype push macro
definition to builtin_macros vector.
(define_builtin_ext): New function.
(define_builtin_math): New function.
(m2builtins_init): Add isgreater, isless, isgreaterequal,
islessequal, islessgreater, isunordered, isnormal to macro 
definitions.
* gm2-libs/Builtins.def (isgreater): New procedure function.
(isgreaterf): Ditto.
(isgreaterl): Ditto.
(isgreaterequal): Ditto.
(isgreaterequalf): Ditto.
(isgreaterequall): Ditto.
(isless): Ditto.
(islessf): Ditto.
(islessl): Ditto.
(islessequal): Ditto.
(islessequalf): Ditto.
(islessequall): Ditto.
(islessgreater): Ditto.
(islessgreaterf): Ditto.
(islessgreaterl): Ditto.
(isunordered): Ditto.
(isunorderedf): Ditto.
(isunorderedl): Ditto.
(iseqsig): Ditto.
(iseqsigf): Ditto.
(iseqsigl): Ditto.
(isnormal): Ditto.
(isnormalf): Ditto.
(isnormall): Ditto.
(isinf_sign): Ditto.
(isinf_signf): Ditto.
(isinf_signl): Ditto.
* gm2-libs/Builtins.mod (isgreater): New procedure function.
(isgreaterf): Ditto.
(isgreaterl): Ditto.
(isgreaterequal): Ditto.
(isgreaterequalf): Ditto.
(isgreaterequall): Ditto.
(isless): Ditto.
(islessf): Ditto.
(islessl): Ditto.
(islessequal): Ditto.
(islessequalf): Ditto.
(islessequall): Ditto.
(islessgreater): Ditto.
(islessgreaterf): Ditto.
(islessgreaterl): Ditto.
(isunordered): Ditto.
(isunorderedf): Ditto.
(isunorderedl): Ditto.
(iseqsig): Ditto.
(iseqsigf): Ditto.
(iseqsigl): Ditto.
(isnormal): Ditto.
(isnormalf): Ditto.
(isnormall): Ditto.
(isinf_sign): Ditto.
(isinf_signf): Ditto.
(isinf_signl): Ditto.

gcc/testsuite/ChangeLog:

PR modula2/114478
* gm2/builtins/run/pass/builtins-run-pass.exp: New test.
* gm2/builtins/run/pass/testcomparisons.mod: New test.
* gm2/builtins/run/pass/testisnormal.mod: New test.
* gm2/pimlib/run/pass/testchar.mod: New test.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-gcc/m2builtins.cc   | 147 +++
 gcc/m2/gm2-libs/Builtins.def   |  40 -
 gcc/m2/gm2-libs/Builtins.mod   | 161 +++--
 .../gm2/builtins/run/pass/builtins-run-pass.exp|  36 +
 .../gm2/builtins/run/pass/testcomparisons.mod  |  77 ++
 .../gm2/builtins/run/pass/testisnormal.mod |  49 +++
 gcc/testsuite/gm2/pimlib/run/pass/testchar.mod |  71 +
 7 files changed, 539 insertions(+), 42 deletions(-)

diff --git a/gcc/m2/gm2-gcc/m2builtins.cc b/gcc/m2/gm2-gcc/m2builtins.cc
index e4fc6a50c1c..cfb4751e15a 100644
--- a/gcc/m2/gm2-gcc/m2builtins.cc
+++ b/gcc/m2/gm2-gcc/m2builtins.cc
@@ -393,6 +393,13 @@ struct builtin_type_info
   tree (*functionHandler) (location_t, tree);
 };
 
+struct GTY(()) builtin_macro_definition
+{
+  const char *name;
+  tree function_node;
+  tree return_node;
+};
+
 static GTY (()) tree sizetype_endlink;
 static GTY (()) tree unsigned_endlink;
 static GTY (()) tree endlink;
@@ -418,6 +425,7 @@ static GTY (()) tree long_doubleptr_type_node;
 static GTY (()) tree doubleptr_type_node;
 static GTY (()) tree floatptr_type_node;
 static GTY (()) tree builtin_ftype_int_var;
+static GTY (()) vec *builtin_macros;
 
 /* Prototypes for locally defined functions.  */
 static tree DoBuiltinAlloca (location_t location, tree n);
@@ -916,21 +924,45 @@ m2builtins_BuiltinExists (char *name)
 if (strcmp (name, fe->name) == 0)
   return true;
   // return target_support_exists (fe);
-
+  int length = vec_s

[gcc r14-9702] modula2: Rebuild documentation sections for target independent libs

2024-03-28 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:7907ff2bcb50d1d88dc8d22e740de33ab151d00c

commit r14-9702-g7907ff2bcb50d1d88dc8d22e740de33ab151d00c
Author: Gaius Mulley 
Date:   Thu Mar 28 08:31:06 2024 +

modula2: Rebuild documentation sections for target independent libs

This patch rebuilds the documentation for the target independent
library sections.

gcc/m2/ChangeLog:

* target-independent/m2/Builtins.texi: Rebuilt.
* target-independent/m2/gm2-libs.texi: Rebuilt.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/target-independent/m2/Builtins.texi | 67 +-
 gcc/m2/target-independent/m2/gm2-libs.texi | 67 +-
 2 files changed, 130 insertions(+), 4 deletions(-)

diff --git a/gcc/m2/target-independent/m2/Builtins.texi 
b/gcc/m2/target-independent/m2/Builtins.texi
index b6903215293..4ebad46b96a 100644
--- a/gcc/m2/target-independent/m2/Builtins.texi
+++ b/gcc/m2/target-independent/m2/Builtins.texi
@@ -4,7 +4,7 @@ DEFINITION MODULE Builtins ;
 
 FROM SYSTEM IMPORT ADDRESS ;
 
-(* floating point intrinsic procedure functions *)
+(* Floating point intrinsic procedure functions.  *)
 
 @findex isnanf
 PROCEDURE __BUILTIN__ isnanf (x: SHORTREAL) : INTEGER ;
@@ -140,7 +140,70 @@ PROCEDURE __BUILTIN__ scalbnf (x: SHORTREAL; n: INTEGER) : 
SHORTREAL ;
 @findex scalbnl
 PROCEDURE __BUILTIN__ scalbnl (x: LONGREAL; n: INTEGER) : LONGREAL ;
 
-(* complex arithmetic intrincic procedure functions *)
+@findex isgreater
+PROCEDURE __BUILTIN__ isgreater (x, y: REAL) : INTEGER ;
+@findex isgreaterf
+PROCEDURE __BUILTIN__ isgreaterf (x, y: SHORTREAL) : INTEGER ;
+@findex isgreaterl
+PROCEDURE __BUILTIN__ isgreaterl (x, y: LONGREAL) : INTEGER ;
+
+@findex isgreaterequal
+PROCEDURE __BUILTIN__ isgreaterequal (x, y: REAL) : INTEGER ;
+@findex isgreaterequalf
+PROCEDURE __BUILTIN__ isgreaterequalf (x, y: SHORTREAL) : INTEGER ;
+@findex isgreaterequall
+PROCEDURE __BUILTIN__ isgreaterequall (x, y: LONGREAL) : INTEGER ;
+
+@findex isless
+PROCEDURE __BUILTIN__ isless (x, y: REAL) : INTEGER ;
+@findex islessf
+PROCEDURE __BUILTIN__ islessf (x, y: SHORTREAL) : INTEGER ;
+@findex islessl
+PROCEDURE __BUILTIN__ islessl (x, y: LONGREAL) : INTEGER ;
+
+@findex islessequal
+PROCEDURE __BUILTIN__ islessequal (x, y: REAL) : INTEGER ;
+@findex islessequalf
+PROCEDURE __BUILTIN__ islessequalf (x, y: SHORTREAL) : INTEGER ;
+@findex islessequall
+PROCEDURE __BUILTIN__ islessequall (x, y: LONGREAL) : INTEGER ;
+
+@findex islessgreater
+PROCEDURE __BUILTIN__ islessgreater (x, y: REAL) : INTEGER ;
+@findex islessgreaterf
+PROCEDURE __BUILTIN__ islessgreaterf (x, y: SHORTREAL) : INTEGER ;
+@findex islessgreaterl
+PROCEDURE __BUILTIN__ islessgreaterl (x, y: LONGREAL) : INTEGER ;
+
+@findex isunordered
+PROCEDURE __BUILTIN__ isunordered (x, y: REAL) : INTEGER ;
+@findex isunorderedf
+PROCEDURE __BUILTIN__ isunorderedf (x, y: SHORTREAL) : INTEGER ;
+@findex isunorderedl
+PROCEDURE __BUILTIN__ isunorderedl (x, y: LONGREAL) : INTEGER ;
+
+@findex iseqsig
+PROCEDURE __BUILTIN__ iseqsig (x, y: REAL) : INTEGER ;
+@findex iseqsigf
+PROCEDURE __BUILTIN__ iseqsigf (x, y: SHORTREAL) : INTEGER ;
+@findex iseqsigl
+PROCEDURE __BUILTIN__ iseqsigl (x, y: LONGREAL) : INTEGER ;
+
+@findex isnormal
+PROCEDURE __BUILTIN__ isnormal (r: REAL) : INTEGER ;
+@findex isnormalf
+PROCEDURE __BUILTIN__ isnormalf (s: SHORTREAL) : INTEGER ;
+@findex isnormall
+PROCEDURE __BUILTIN__ isnormall (l: LONGREAL) : INTEGER ;
+
+@findex isinf_sign
+PROCEDURE __BUILTIN__ isinf_sign (r: REAL) : INTEGER ;
+@findex isinf_signf
+PROCEDURE __BUILTIN__ isinf_signf (s: SHORTREAL) : INTEGER ;
+@findex isinf_signl
+PROCEDURE __BUILTIN__ isinf_signl (l: LONGREAL) : INTEGER ;
+
+(* Complex arithmetic intrincic procedure functions.  *)
 
 @findex cabsf
 PROCEDURE __BUILTIN__ cabsf (z: SHORTCOMPLEX) : SHORTREAL ;
diff --git a/gcc/m2/target-independent/m2/gm2-libs.texi 
b/gcc/m2/target-independent/m2/gm2-libs.texi
index db8189f4059..10b466811c1 100644
--- a/gcc/m2/target-independent/m2/gm2-libs.texi
+++ b/gcc/m2/target-independent/m2/gm2-libs.texi
@@ -240,7 +240,7 @@ DEFINITION MODULE Builtins ;
 
 FROM SYSTEM IMPORT ADDRESS ;
 
-(* floating point intrinsic procedure functions *)
+(* Floating point intrinsic procedure functions.  *)
 
 @findex isnanf
 PROCEDURE __BUILTIN__ isnanf (x: SHORTREAL) : INTEGER ;
@@ -376,7 +376,70 @@ PROCEDURE __BUILTIN__ scalbnf (x: SHORTREAL; n: INTEGER) : 
SHORTREAL ;
 @findex scalbnl
 PROCEDURE __BUILTIN__ scalbnl (x: LONGREAL; n: INTEGER) : LONGREAL ;
 
-(* complex arithmetic intrincic procedure functions *)
+@findex isgreater
+PROCEDURE __BUILTIN__ isgreater (x, y: REAL) : INTEGER ;
+@findex isgreaterf
+PROCEDURE __BUILTIN__ isgreaterf (x, y: SHORTREAL) : INTEGER ;
+@findex isgreaterl
+PROCEDURE __BUILTIN__ isgreaterl (x, y: LONGREAL) : INTEGER ;
+
+@findex isgreaterequal
+PROCEDURE __BUILTIN__ isgreaterequal (x, y: REAL) : INTEGER ;
+@findex isgreaterequalf
+PROCEDURE __BUILTI

[gcc r14-9709] PR modula2/114517 gm2 does not allow comparison operator hash in column one

2024-03-28 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:04799f03e8d01b903295ef3a100a0117b7ddbf5e

commit r14-9709-g04799f03e8d01b903295ef3a100a0117b7ddbf5e
Author: Gaius Mulley <(no_default)>
Date:   Thu Mar 28 14:57:49 2024 +

PR modula2/114517 gm2 does not allow comparison operator hash in column one

This patch allows -fno-cpp to be supplied to gm2.  Without this patch
it causes an ICE.  The patch allows -fno-cpp to turn off cpp flags.
These are tested in m2.flex to decide whether a change of state is
allowed (enabling handling of #line directives).

gcc/ChangeLog:

PR modula2/114517
* doc/gm2.texi: Mention gm2 treats a # in the first column
as a preprocessor directive unless -fno-cpp is supplied.

gcc/m2/ChangeLog:

PR modula2/114517
* gm2-compiler/M2Options.def (SetCpp): Add comment.
(GetCpp): Move after SetCpp.
(GetLineDirectives): New procedure function.
* gm2-compiler/M2Options.mod (GetLineDirectives): New
procedure function.
* gm2-gcc/m2options.h (M2Options_GetLineDirectives): New
prototype.
* gm2-lang.cc (gm2_langhook_init_options): OPT_fcpp only
assert if !value.
* m2.flex: Test GetLineDirectives before changing to LINE0
state.

gcc/testsuite/ChangeLog:

PR modula2/114517
* gm2/cpp/fail/hashfirstcolumn2.mod: New test.
* gm2/imports/fail/imports-fail.exp: New test.
* gm2/imports/fail/localmodule2.mod: New test.
* gm2/imports/run/pass/localmodule.mod: New test.

Signed-off-by: Gaius Mulley <(no_default)>

Diff:
---
 gcc/doc/gm2.texi   |  3 +-
 gcc/m2/gm2-compiler/M2Options.def  | 36 +-
 gcc/m2/gm2-compiler/M2Options.mod  | 10 ++
 gcc/m2/gm2-gcc/m2options.h |  1 +
 gcc/m2/gm2-lang.cc |  3 +-
 gcc/m2/m2.flex | 10 --
 gcc/testsuite/gm2/cpp/fail/hashfirstcolumn2.mod| 18 +++
 gcc/testsuite/gm2/imports/fail/imports-fail.exp| 36 ++
 gcc/testsuite/gm2/imports/fail/localmodule2.mod| 27 
 gcc/testsuite/gm2/imports/run/pass/localmodule.mod | 27 
 10 files changed, 153 insertions(+), 18 deletions(-)

diff --git a/gcc/doc/gm2.texi b/gcc/doc/gm2.texi
index 028a0715f64..9f6d4140e42 100644
--- a/gcc/doc/gm2.texi
+++ b/gcc/doc/gm2.texi
@@ -1657,7 +1657,8 @@ The preprocessor @samp{cpp} can be invoked via the 
@samp{-fcpp}
 command line option.  This in turn invokes @samp{cpp} with the
 following arguments @samp{-traditional -lang-asm}.  These options
 preserve comments and all quotations.  @samp{gm2} treats a @samp{#}
-character in the first column as a preprocessor directive.
+character in the first column as a preprocessor directive unless
+@samp{-fno-cpp} is supplied.
 
 For example here is a module which calls @code{FatalError}
 via the macro @code{ERROR}.
diff --git a/gcc/m2/gm2-compiler/M2Options.def 
b/gcc/m2/gm2-compiler/M2Options.def
index 90b5178f88a..e4ebf41802f 100644
--- a/gcc/m2/gm2-compiler/M2Options.def
+++ b/gcc/m2/gm2-compiler/M2Options.def
@@ -328,6 +328,28 @@ PROCEDURE SetObj (arg: ADDRESS) ;
 PROCEDURE GetObj () : ADDRESS ;
 
 
+(*
+   SetCpp - enables the source to be preprocessed and enables the
+recognition of C preprocessor line directives.
+*)
+
+PROCEDURE SetCpp (value: BOOLEAN) : BOOLEAN ;
+
+
+(*
+   GetCpp - returns TRUE if the C preprocessor was used.
+*)
+
+PROCEDURE GetCpp () : BOOLEAN ;
+
+
+(*
+   GetLineDirectives - returns TRUE if line directives are allowed.
+*)
+
+PROCEDURE GetLineDirectives () : BOOLEAN ;
+
+
 (*
SetScaffoldDynamic - set the -fscaffold-dynamic flag.
 *)
@@ -467,20 +489,6 @@ PROCEDURE SetQuiet (value: BOOLEAN) : BOOLEAN ;
 PROCEDURE SetCC1Quiet (value: BOOLEAN) ;
 
 
-(*
-   SetCpp -
-*)
-
-PROCEDURE SetCpp (value: BOOLEAN) : BOOLEAN ;
-
-
-(*
-   GetCpp - returns TRUE if the C preprocessor was used.
-*)
-
-PROCEDURE GetCpp () : BOOLEAN ;
-
-
 (*
SetM2g - set the -fm2-g flag.
 *)
diff --git a/gcc/m2/gm2-compiler/M2Options.mod 
b/gcc/m2/gm2-compiler/M2Options.mod
index 30203158e5c..b0de8cdfe82 100644
--- a/gcc/m2/gm2-compiler/M2Options.mod
+++ b/gcc/m2/gm2-compiler/M2Options.mod
@@ -672,6 +672,16 @@ BEGIN
 END GetCpp ;
 
 
+(*
+   GetLineDirectives - returns TRUE if line directives are allowed.
+*)
+
+PROCEDURE GetLineDirectives () : BOOLEAN ;
+BEGIN
+   RETURN LineDirectives
+END GetLineDirectives ;
+
+
 (*
SetPPOnly - set the PPonly (preprocess only) to value.
 *)
diff --git a/gcc/m2/gm2-gcc/m2options.h b/gcc/m2/gm2-gcc/m2options.h
index a03fdc5975f..4b3a23f18db 100644
--- a/gcc/m2/gm2-gcc/m2options.h
+++ b/gcc/m2/gm2-gcc/m2options.h
@@ -104,6 +104,7 @@ EXTERN void M2Options_FinaliseOptions (void);
 EXTERN void 

[gcc r14-9710] PR modula2/114520 Incorrect ordering of import/export statements cause confusion

2024-03-28 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:aeee63ffbf4f4fbc4d90d8aae808d6b67f0148a3

commit r14-9710-gaeee63ffbf4f4fbc4d90d8aae808d6b67f0148a3
Author: Gaius Mulley 
Date:   Thu Mar 28 16:49:44 2024 +

PR modula2/114520 Incorrect ordering of import/export statements cause 
confusion

The error recovery causes misleading error messages to appear if an
EXPORT and IMPORT statement are in the wrong order.  This patch
detects the incorrect order and issues an error message and prevents
error recovery.  The fix should be improved and made more general if
another similar case is required.

gcc/m2/ChangeLog:

PR modula2/114520
* gm2-compiler/P0SyntaxCheck.bnf (DetectImport): New
procedure.
(EnableImportCheck): New boolean.
(Expect): Call DetectImport.
(Export): Set EnableImportCheck TRUE before ';' and FALSE
afterwards.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-compiler/P0SyntaxCheck.bnf | 31 +++
 1 file changed, 27 insertions(+), 4 deletions(-)

diff --git a/gcc/m2/gm2-compiler/P0SyntaxCheck.bnf 
b/gcc/m2/gm2-compiler/P0SyntaxCheck.bnf
index c1c86c1827d..07f861adac9 100644
--- a/gcc/m2/gm2-compiler/P0SyntaxCheck.bnf
+++ b/gcc/m2/gm2-compiler/P0SyntaxCheck.bnf
@@ -82,9 +82,10 @@ CONST
(* giving up.  
*)
 
 VAR
-   seenError  : BOOLEAN ;
-   LastIdent  : Name ;
-   InsertCount: CARDINAL ;
+   EnableImportCheck,
+   seenError: BOOLEAN ;
+   LastIdent: Name ;
+   InsertCount  : CARDINAL ;
 
 
 PROCEDURE ErrorString (s: String) ;
@@ -319,6 +320,21 @@ BEGIN
 END PeepToken ;
 
 
+(*
+   DetectImport - checks whether the next token is an import or from and if so
+  generates an error message.  This is called after an export
+  statement to notify the user that the ordering is incorrect.
+*)
+
+PROCEDURE DetectImport ;
+BEGIN
+   IF (currenttoken = importtok) OR (currenttoken = fromtok)
+   THEN
+  ErrorArray ('an {%AkIMPORT} statement must preceed an {%kEXPORT} 
statement')
+   END
+END DetectImport ;
+
+
 (*
Expect -
 *)
@@ -328,6 +344,10 @@ BEGIN
IF currenttoken=t
THEN
   GetToken ;
+  IF EnableImportCheck
+  THEN
+ DetectImport
+  END ;
   IF Pass0
   THEN
  PeepToken (stopset0, stopset1, stopset2)
@@ -347,6 +367,7 @@ END Expect ;
 PROCEDURE CompilationUnit () : BOOLEAN ;
 BEGIN
seenError := FALSE ;
+   EnableImportCheck := FALSE ;
InsertCount := 0 ;
FileUnit (SetOfStop0{eoftok}, SetOfStop1{}, SetOfStop2{}) ;
RETURN NOT seenError
@@ -883,7 +904,9 @@ Priority := "[" ConstExpression "]" =:
 Export := "EXPORT" ( "QUALIFIED"   IdentList |
  "UNQUALIFIED" IdentList |
   IdentList
-   ) ";" =:
+   )   % 
EnableImportCheck := TRUE %
+ ";"   % 
EnableImportCheck := FALSE %
+ =:
 
 Import :=  "FROM" Ident "IMPORT" IdentList ";" |
"IMPORT"% 
PushTtok (ImportTok, GetTokenNo () -1)


[gcc r14-9739] PR modula2/114548 gm2 fails to identify variable in a const expression

2024-04-01 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:4bd2f59af4a78cdc80039cffa51c1d9ad91081a3

commit r14-9739-g4bd2f59af4a78cdc80039cffa51c1d9ad91081a3
Author: Gaius Mulley 
Date:   Mon Apr 1 19:18:36 2024 +0100

PR modula2/114548 gm2 fails to identify variable in a const expression

This patch introduces stricter checking within standard procedure
functions which detect whether paramaters are variable when used
in a const expression.

gcc/m2/ChangeLog:

PR modula2/114548
* gm2-compiler/M2Quads.mod (ConvertToAddress): Pass
procedure, false parameters to BuildConvertFunction.
(PushOne): Pass procedure, true parameters to
BuildConvertFunction.
Remove usused parameter internal.
(BuildPseudoBy): Remove parameter to PushOne.
(BuildIncProcedure): Ditto.
(BuildDecProcedure): Ditto.
(BuildFunctionCall): Add ConstExpr parameter to
BuildPseudoFunctionCall.
(BuildConstFunctionCall): Add procedure and true to
BuildConvertFunction.
(BuildPseudoFunctionCall): Add ConstExpr parameter.
Pass ProcSym and ConstExpr to BuildLengthFunction,
BuildConvertFunction, BuildOddFunction, BuildAbsFunction,
BuildCapFunction, BuildValFunction, BuildChrFunction,
BuildOrdFunction, BuildIntFunction, BuildTruncFunction,
BuildFloatFunction, BuildAddAdrFunction, BuildSubAdrFunction,
BuildDifAdrFunction, BuildCastFunction, BuildReFunction,
BuildImFunction and BuildCmplxFunction.
(BuildAddAdrFunction): Add ProcSym, ConstExpr parameters and
check for constant parameters.
(BuildSubAdrFunction): Ditto.
(BuildDifAdrFunction): Ditto.
(ConstExprError): Ditto.
(BuildLengthFunction): Ditto.
(BuildOddFunction): Ditto.
(BuildAbsFunction): Ditto.
(BuildCapFunction): Ditto.
(BuildChrFunction): Ditto.
(BuildOrdFunction): Ditto.
(BuildIntFunction): Ditto.
(BuildValFunction): Ditto.
(BuildCastFunction): Ditto.
(BuildConvertFunction): Ditto.
(BuildTruncFunction): Ditto.
(BuildFloatFunction): Ditto.
(BuildReFunction): Ditto.
(BuildImFunction): Ditto.
(BuildCmplxFunction): Ditto.

gcc/testsuite/ChangeLog:

PR modula2/114548
* gm2/iso/const/fail/expression.mod: New test.
* gm2/iso/const/fail/iso-const-fail.exp: New test.
* gm2/iso/const/fail/testabs.mod: New test.
* gm2/iso/const/fail/testaddadr.mod: New test.
* gm2/iso/const/fail/testcap.mod: New test.
* gm2/iso/const/fail/testcap2.mod: New test.
* gm2/iso/const/fail/testchr.mod: New test.
* gm2/iso/const/fail/testchr2.mod: New test.
* gm2/iso/const/fail/testcmplx.mod: New test.
* gm2/iso/const/fail/testfloat.mod: New test.
* gm2/iso/const/fail/testim.mod: New test.
* gm2/iso/const/fail/testint.mod: New test.
* gm2/iso/const/fail/testlength.mod: New test.
* gm2/iso/const/fail/testodd.mod: New test.
* gm2/iso/const/fail/testord.mod: New test.
* gm2/iso/const/fail/testre.mod: New test.
* gm2/iso/const/fail/testtrunc.mod: New test.
* gm2/iso/const/fail/testval.mod: New test.
* gm2/iso/const/pass/constbool.mod: New test.
* gm2/iso/const/pass/constbool2.mod: New test.
* gm2/iso/const/pass/constbool3.mod: New test.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-compiler/M2Quads.mod| 454 ++---
 gcc/testsuite/gm2/iso/const/fail/expression.mod|  10 +
 .../gm2/iso/const/fail/iso-const-fail.exp  |  36 ++
 gcc/testsuite/gm2/iso/const/fail/testabs.mod   |  10 +
 gcc/testsuite/gm2/iso/const/fail/testaddadr.mod|  12 +
 gcc/testsuite/gm2/iso/const/fail/testcap.mod   |  10 +
 gcc/testsuite/gm2/iso/const/fail/testcap2.mod  |  10 +
 gcc/testsuite/gm2/iso/const/fail/testchr.mod   |  10 +
 gcc/testsuite/gm2/iso/const/fail/testchr2.mod  |  10 +
 gcc/testsuite/gm2/iso/const/fail/testcmplx.mod |  10 +
 gcc/testsuite/gm2/iso/const/fail/testfloat.mod |  10 +
 gcc/testsuite/gm2/iso/const/fail/testim.mod|  10 +
 gcc/testsuite/gm2/iso/const/fail/testint.mod   |  10 +
 gcc/testsuite/gm2/iso/const/fail/testlength.mod|  11 +
 gcc/testsuite/gm2/iso/const/fail/testodd.mod   |  10 +
 gcc/testsuite/gm2/iso/const/fail/testord.mod   |  10 +
 gcc/testsuite/gm2/iso/const/fail/testre.mod|  10 +
 gcc/testsuite/gm2/iso/const/fail/testtrunc.mod |  10 +
 gcc/testsuite/gm2/iso/const/fail/testval.mod   |  10 +
 gcc/testsuite/gm2/iso/const/pass/constbool.mod |  14 +
 gc

[gcc r14-9764] PR modula2/114565 progress trace would be useful to isolate ICE for users

2024-04-02 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:1bafa6a3fdbb53651ffa5d854c2341c487bf3269

commit r14-9764-g1bafa6a3fdbb53651ffa5d854c2341c487bf3269
Author: Gaius Mulley 
Date:   Tue Apr 2 23:47:42 2024 +0100

PR modula2/114565 progress trace would be useful to isolate ICE for users

This patch introduces the internal option -fm2-debug-trace= which can
be given a comma separated list of filter terms.  Currently it allows:
all,line,token,quad.  The patch allows users to trace the progress of
cc1gm2 so that source which causes an ICE can be reduced.  Once
PR113836 is complete it is expected that the trace information will be
written to file.

gcc/m2/ChangeLog:

PR modula2/114565
* gm2-compiler/M2GenGCC.mod (CodeStatement): Test
GetDebugTraceQuad before calling DisplayQuad.
* gm2-compiler/M2LexBuf.mod (NumberIO): Import CardToStr.
(GetToken): Test GetDebugTraceToken before writing the
token number or token line.
* gm2-compiler/M2Options.def (SetDebugTraceQuad): Rename to
(SetM2DebugTraceFilter): ...this.
(SetDebugTraceAPI): Remove.
(GetDebugTraceQuad): New procedure function.
(GetDebugTraceTree): Ditto.
(GetDebugTraceToken): Ditto.
(GetDebugTraceLine): Ditto.
(GetDebugFunctionLineNumbers): Ditto.
* gm2-compiler/M2Options.mod (DebugFunctionLineNumbers): New
boolean variable.
(DebugTraceQuad): Ditto.
(DebugTraceTree): Ditto.
(DebugTraceLine): Ditto.
(DebugTraceToken): Ditto.
(errors1): New procedure.
(SetDebugTraceQuad): Remove.
(SetM2DebugTraceFilter): New procedure implemented.
(SetM2DebugTrace): Ditto.
(GetDebugTraceQuad): Ditto.
(GetDebugTraceToken ): Ditto.
(GetDebugTraceLine): Ditto.
(SetDebugTraceLine): Remove.
* gm2-compiler/M2Quads.mod (GenQuadOTrash): Test
GetDebugTraceQuad and call DisplayQuad.
(GenQuadOTypetok): Ditto.
* gm2-compiler/SymbolTable.mod: Replace
DebugFunctionLineNumbers with GetDebugFunctionLineNumbers.
* gm2-gcc/init.cc (_M2_M2LangDump_init): Add prototype.
(init_PerCompilationInit): Add call.
* gm2-gcc/m2misc.cc (m2misc_cerror): New function.
(m2misc_error): Ditto.
* gm2-gcc/m2misc.def (error): New procedure.
(cerror): Ditto.
* gm2-gcc/m2misc.h (m2misc_cerror): New prototype.
(m2misc_error): Ditto.
* gm2-gcc/m2options.h (M2Options_SetDebugTraceQuad): New
prototype.
(M2Options_SetDebugTraceAPI): Remove.
(M2Options_GetDebugTraceToken): New prototype.
(M2Options_GetDebugTraceLine): Ditto.
(M2Options_SetDebugFunctionLineNumbers): Ditto.
(M2Options_GetDebugFunctionLineNumbers): Ditto.
(M2Options_SetM2DebugTraceFilter): Ditto.
* gm2-lang.cc (gm2_langhook_init_options): Remove
OPT_fdebug_trace_quad case.
Remove OPT_fdebug_trace_api case.
Add OPT_fm2_debug_trace_ case.
* lang.opt (fm2-debug-trace): New option.
(fdebug-trace-api): Remove.
(fdebug-trace-quad): Remove.
* m2.flex (m2flex_M2Error): Check s for NULL.
(skipnewline): New function.
(consumeLine): Call traceline.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-compiler/M2GenGCC.mod|   5 +-
 gcc/m2/gm2-compiler/M2LexBuf.mod|  24 +-
 gcc/m2/gm2-compiler/M2Options.def   |  54 +
 gcc/m2/gm2-compiler/M2Options.mod   | 154 +++-
 gcc/m2/gm2-compiler/M2Quads.mod |  18 -
 gcc/m2/gm2-compiler/SymbolTable.mod |   6 +-
 gcc/m2/gm2-gcc/init.cc  |   2 +
 gcc/m2/gm2-gcc/m2misc.cc|  16 
 gcc/m2/gm2-gcc/m2misc.def   |   4 +
 gcc/m2/gm2-gcc/m2misc.h |   2 +
 gcc/m2/gm2-gcc/m2options.h  |   7 +-
 gcc/m2/gm2-lang.cc  |   9 +--
 gcc/m2/lang.opt |  14 ++--
 gcc/m2/m2.flex  |  35 +++-
 14 files changed, 285 insertions(+), 65 deletions(-)

diff --git a/gcc/m2/gm2-compiler/M2GenGCC.mod b/gcc/m2/gm2-compiler/M2GenGCC.mod
index 7e27373a6ac..60f58cc2d1b 100644
--- a/gcc/m2/gm2-compiler/M2GenGCC.mod
+++ b/gcc/m2/gm2-compiler/M2GenGCC.mod
@@ -96,8 +96,7 @@ FROM M2MetaError IMPORT MetaErrorT0, MetaErrorT1, 
MetaErrorT2, MetaErrorT3,
 FROM M2Options IMPORT UnboundedByReference, PedanticCast,
   VerboseUnbounded, Iso, Pim, DebugBuiltins, WholeProgram,
   StrictTypeChecking, AutoInit, cflag, ScaffoldMain,
-  ScaffoldDynamic, ScaffoldStatic,
-  DebugTraceQuad, DebugTraceAPI ;
+  

[gcc r14-9823] PR modula2/114617 gm2 unable to resolve const expressions using relop ICE

2024-04-06 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:4e3c8257304c55f2ebfb24bd6de3236bda0f054e

commit r14-9823-g4e3c8257304c55f2ebfb24bd6de3236bda0f054e
Author: Gaius Mulley 
Date:   Sat Apr 6 23:45:35 2024 +0100

PR modula2/114617 gm2 unable to resolve const expressions using relop ICE

This patch allows cc1gm2 to resolve constant expressions which use
relative operators.  Previous to the patch the result of a relop
was stored in a temporary variable set by an if then else quadruple
sequence.  This patch marks a const expression in the quadruples
and then reduces this sequence of quadruples into a single
assignment to an internal constant.

gcc/m2/ChangeLog:

PR modula2/114617
* gm2-compiler/M2GenGCC.mod (CodeStatememt): Add quad trace.
(ResolveConstantExpressions): Add parameter p to FoldIfLess,
FoldIfGre, FoldIfLessEqu, FoldIfGreEqu, FoldIfEqu, FoldIfNotEqu,
FoldIfIn and FoldIfNotIn.
(CodeInline): Add constExpr variable and pass it to GetQuadOtok.
(CodeReturnValue): Ditto.
(CodeParam): Ditto.
(FoldStringLength): Ditto.
(FoldStringConvertM2nul): Ditto.
(FoldStringConvertCnul): Ditto.
(DeclaredOperandsBecomes): Ditto.
(TypeCheckBecomes): Ditto.
(PerformFoldBecomes): Ditto.
(CodeBecomes): Ditto.
(CheckElementSetTypes): Ditto.
(CodeBinarySet): Ditto.
(PerformCodeIfLess): Ditto.
(PerformCodeIfGre): Ditto.
(PerformCodeIfLessEqu): Ditto.
(PerformCodeIfGreEqu): Ditto.
(PerformCodeIfEqu): Ditto.
(PerformCodeIfNotEqu): Ditto.
(IsValidExpressionRelOp): Ditto.
(PerformCodeIfIn): Ditto.
(PerformCodeIfNotIn): Ditto.
(CodeXIndr): Ditto.
(QuadCondition): New procedure function.
(IsBooleanRelOpPattern): Ditto.
(FoldBooleanRelopPattern): Ditto.
(FoldIfGre): Check for boolean relop constant expression and
add parameter p.
(FoldIfLessEqu): Ditto.
(FoldIfIn): Ditto.
(FoldIfEqu): Ditto.
(FoldIfNotIn): Ditto.
(FoldIfGreEqu): New procedure.
(FoldIfNotEqu): Ditto.
* gm2-compiler/M2Optimize.mod (ReduceBranch): Add constExpr
variable and pass it to GetQuadOtok.
* gm2-compiler/M2Quads.def (IsBecomes): New procedure function.
(IsDummy): Ditto.
(IsQuadConstExpr): Ditto.
(SetQuadConstExpr): Ditto.
(GetQuadDest): New procedure.
(GetQuadOp1): New procedure.
(GetQuadOp2): New procedure.
(GetQuadOp3): New procedure.
(GetQuadOtok): New procedure.
(GetQuadOTypetok): New procedure.
(PutQuadOtok): New procedure.
(IsInConstParameters): New procedure function.
* gm2-compiler/M2Quads.mod (IsBecomes): New procedure function.
(IsDummy): Ditto.
(IsQuadConstExpr): Ditto.
(SetQuadConstExpr): Ditto.
(GetQuadDest): New procedure.
(GetQuadOp1): New procedure.
(GetQuadOp2): New procedure.
(GetQuadOp3): New procedure.
(GetQuadOtok): New procedure.
(GetQuadOTypetok): New procedure.
(PutQuadOtok): New procedure.
(IsInConstParameters): New procedure function.
(ConstStack): Remove to ...
(ConstExprStack): ... this.
(ConstParamStack): New variable and initialize.
(QuadFrame): New field ConstExpr.
(GetQuadOtok): Add parameter constExpr and assign.
(PutQuadOtok): Add constExpr parameter and assign.
(PutQuadOType): Ditto.
(GetQuadOTypetok): Ditto.
(EraseQuad): Assign ConstExpr to FALSE.
(FoldSubrange): Set ConstExpr to FALSE in BecomesOp.
(PushInConstParameters): New procedure.
(PopInConstParameters): New procedure.
(IsInConstParameters): New procedure function.
* gm2-compiler/M2SymInit.mod (IssueConditional): Add
constExpr boolean variable.
(CheckReadBeforeInitQuad): Ditto.
(trashParam): Ditto.
* gm2-compiler/P3Build.bnf (ConstExpression): Call
PushInConstExpression and PopInConstExpression.
(ConstSetOrQualidentOrFunction): Call
PushInConstParameters and PopInConstParameters.
* gm2-compiler/PCBuild.bnf (ConstExpression): Call
PushInConstExpression and PopInConstExpression.
* gm2-compiler/PHBuild.bnf: Ditto
* gm2-gcc/m2expr.cc (m2expr_BuildCondIfExpression): New
function.
* gm2-gcc/m2expr.def (BuildCondIfExpression): New prototype.
* gm2-gcc/m2expr.h (m2expr_BuildCon

[gcc r14-9849] PR modula2/114648 cc1gm2 by default does not handle C pre-processor file and line directives

2024-04-08 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:600bf396799a022e65938de572ad1a79a951b95a

commit r14-9849-g600bf396799a022e65938de572ad1a79a951b95a
Author: Gaius Mulley 
Date:   Tue Apr 9 02:35:11 2024 +0100

PR modula2/114648 cc1gm2 by default does not handle C pre-processor file 
and line directives

This patch fixes the default behavior of cc1gm2 to the description in
the documentation.  By default cc1gm2 will allow C preprocessor
directives (they can be turned off via -fno-cpp).

gcc/m2/ChangeLog:

PR modula2/114648
* gm2-compiler/M2Options.mod (LineDirectives): Initially
set to true.

gcc/testsuite/ChangeLog:

PR modula2/114648
* gm2/cpp/default/pass/AdvParse.def: New test.
* gm2/cpp/default/pass/AdvParse.mod: New test.
* gm2/cpp/default/pass/cpp-default-pass.exp: New test.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-compiler/M2Options.mod  |  2 +-
 gcc/testsuite/gm2/cpp/default/pass/AdvParse.def|  5 +++
 gcc/testsuite/gm2/cpp/default/pass/AdvParse.mod|  8 +
 .../gm2/cpp/default/pass/cpp-default-pass.exp  | 36 ++
 4 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/gcc/m2/gm2-compiler/M2Options.mod 
b/gcc/m2/gm2-compiler/M2Options.mod
index 09d62cbc732..d04cded17f0 100644
--- a/gcc/m2/gm2-compiler/M2Options.mod
+++ b/gcc/m2/gm2-compiler/M2Options.mod
@@ -1944,7 +1944,7 @@ BEGIN
ReturnChecking:= FALSE ;
CaseElseChecking  := FALSE ;
CPreProcessor := FALSE ;
-   LineDirectives:= FALSE ;
+   LineDirectives:= TRUE ;
ExtendedOpaque:= FALSE ;
UnboundedByReference  := FALSE ;
VerboseUnbounded  := FALSE ;
diff --git a/gcc/testsuite/gm2/cpp/default/pass/AdvParse.def 
b/gcc/testsuite/gm2/cpp/default/pass/AdvParse.def
new file mode 100644
index 000..391a803116f
--- /dev/null
+++ b/gcc/testsuite/gm2/cpp/default/pass/AdvParse.def
@@ -0,0 +1,5 @@
+DEFINITION MODULE AdvParse ;
+
+PROCEDURE foo ;
+
+END AdvParse.
diff --git a/gcc/testsuite/gm2/cpp/default/pass/AdvParse.mod 
b/gcc/testsuite/gm2/cpp/default/pass/AdvParse.mod
new file mode 100644
index 000..ed3727c63c6
--- /dev/null
+++ b/gcc/testsuite/gm2/cpp/default/pass/AdvParse.mod
@@ -0,0 +1,8 @@
+# 2 "AdvParse.bnf"
+IMPLEMENTATION MODULE AdvParse ;
+
+PROCEDURE foo ;
+BEGIN
+END foo ;
+
+END AdvParse.
\ No newline at end of file
diff --git a/gcc/testsuite/gm2/cpp/default/pass/cpp-default-pass.exp 
b/gcc/testsuite/gm2/cpp/default/pass/cpp-default-pass.exp
new file mode 100644
index 000..0b373cfd655
--- /dev/null
+++ b/gcc/testsuite/gm2/cpp/default/pass/cpp-default-pass.exp
@@ -0,0 +1,36 @@
+# Copyright (C) 2024 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# .
+
+# This file was written by Gaius Mulley (gaiusm...@gmail.com)
+# for GNU Modula-2.
+
+if $tracelevel then {
+strace $tracelevel
+}
+
+# load support procs
+load_lib gm2-torture.exp
+
+gm2_init_pim "${srcdir}/gm2/cpp/default/pass/"
+
+foreach testcase [lsort [glob -nocomplain $srcdir/$subdir/*.mod]] {
+# If we're only testing specific files and this isn't one of them, skip it.
+if ![runtest_file_p $runtests $testcase] then {
+   continue
+}
+
+gm2-torture $testcase
+}


[gcc r14-9867] modula2: tidyup makeSystem

2024-04-09 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:46120d7d12318f98cbeeef1bae886222ecc92d52

commit r14-9867-g46120d7d12318f98cbeeef1bae886222ecc92d52
Author: Gaius Mulley 
Date:   Tue Apr 9 11:02:17 2024 +0100

modula2: tidyup makeSystem

This patch provides a tidyup for gcc/m2/tools-src/makeSystem.
It only runs the compiler once and will echo a debug command line
should it fail.

gcc/m2/ChangeLog:

* tools-src/makeSystem: Invoke ${COMPILER} once and adjust
the echo string to expand the shell variables with -wrapper
gdb, --args.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/tools-src/makeSystem | 14 +-
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/gcc/m2/tools-src/makeSystem b/gcc/m2/tools-src/makeSystem
index 824aeb76676..393713eb873 100644
--- a/gcc/m2/tools-src/makeSystem
+++ b/gcc/m2/tools-src/makeSystem
@@ -101,8 +101,10 @@ displayEnd () {
 MINIMAL="-fno-scaffold-main -fno-scaffold-dynamic -fno-scaffold-static 
-fno-m2-plugin"
 
 rm -f ${OUTPUTFILE}
-if ${COMPILER} ${DIALECT} ${LIBRARY} ${MINIMAL} \
-  -S -fdump-system-exports ${SYSTEMMOD} -o /dev/null 2>&1 > 
/dev/null ; then
+${COMPILER} ${DIALECT} ${LIBRARY} ${MINIMAL} \
+   -S -fdump-system-exports ${SYSTEMMOD} -o /dev/null 2>&1 > /dev/null
+res=$?
+if [ ${res} -eq 0 ] ; then
 types=`${COMPILER} ${DIALECT} ${LIBRARY} ${MINIMAL} -fno-m2-plugin -S 
-fdump-system-exports ${SYSTEMMOD} -o /dev/null | cut -f5 -d' '`
 touch ${OUTPUTFILE}
 displayStart
@@ -111,7 +113,9 @@ if ${COMPILER} ${DIALECT} ${LIBRARY} ${MINIMAL} \
 displayBuiltinTypes
 displayEnd
 else
-${COMPILER} ${DIALECT} ${LIBRARY} ${MINIMAL} \
-   -S -fdump-system-exports ${SYSTEMMOD} -o /dev/null
-exit $?
+echo "the command below failed:"
+echo "${COMPILER} ${DIALECT} ${LIBRARY} ${MINIMAL} -S 
-fdump-system-exports ${SYSTEMMOD}"
+echo "to debug the command use"
+echo "${COMPILER} ${DIALECT} ${LIBRARY} ${MINIMAL} -S 
-fdump-system-exports ${SYSTEMMOD} -wrapper gdb,--args"
+exit $res
 fi


[gcc r14-9868] modula2: remove description of fdebug-trace-quad, fdebug-trace-api and add fm2-debug-trace=

2024-04-09 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:897a241ddde53eae912c612a1623c84ff4dfe339

commit r14-9868-g897a241ddde53eae912c612a1623c84ff4dfe339
Author: Gaius Mulley 
Date:   Tue Apr 9 11:21:02 2024 +0100

modula2: remove description of fdebug-trace-quad, fdebug-trace-api and add 
fm2-debug-trace=

This documentation fix removes the descriptions of -fdebug-trace-quad
and -fdebug-trace-api.  It adds a description of -fm2-debug-trace=
together with the trace alternatives: line,token,quad,all.

gcc/ChangeLog:

* doc/gm2.texi (Compiler options): Remove -fdebug-trace-quad.
Remove -fdebug-trace-api.
Add -fm2-debug-trace=.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/doc/gm2.texi | 13 +
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/gcc/doc/gm2.texi b/gcc/doc/gm2.texi
index 9f6d4140e42..19b864573c1 100644
--- a/gcc/doc/gm2.texi
+++ b/gcc/doc/gm2.texi
@@ -398,14 +398,6 @@ it allows users to single step code into an intrinsic 
function.
 @c Modula-2
 @c turn on internal debugging of the compiler (internal switch)
 
-@c fdebug-trace-quad
-@c Modula-2
-@c turn on quadruple tracing (internal switch)
-
-@c fdebug-trace-api
-@c Modula-2
-@c turn on the Modula-2 api tracing (internal switch)
-
 @c fdebug-function-line-numbers
 @c Modula-2
 @c turn on the Modula-2 function line number generation (internal switch)
@@ -474,6 +466,11 @@ this option forces the use of the static version.
 @c Modula-2 Joined
 @c set all location values to a specific value (internal switch)
 
+@c fm2-debug-trace=
+@c Modula-2 Joined
+@c turn on trace debugging using a comma separated list:
+@c line,token,quad,all.
+
 @item -fm2-g
 improve the debugging experience for new programmers at the expense
 of generating @code{nop} instructions if necessary to ensure single


[gcc r14-9915] modula2: add modula-2 language section to languages supported by GCC

2024-04-11 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:0dc39dee836761f1bc993d760f4ed5f3d127897a

commit r14-9915-g0dc39dee836761f1bc993d760f4ed5f3d127897a
Author: Gaius Mulley 
Date:   Thu Apr 11 15:04:49 2024 +0100

modula2: add modula-2 language section to languages supported by GCC

This patch introduces a small modula-2 language section to the
Language Standards Supported by GCC node.

gcc/ChangeLog:

* doc/standards.texi (Language Standards Supported by GCC):
Add Modula-2 language section.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/doc/standards.texi | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/gcc/doc/standards.texi b/gcc/doc/standards.texi
index 06444ee15f7..586835b28f3 100644
--- a/gcc/doc/standards.texi
+++ b/gcc/doc/standards.texi
@@ -332,6 +332,17 @@ GCC supports the D 2.0 programming language.  The D 
language itself is
 currently defined by its reference implementation and supporting language
 specification, described at @uref{https://dlang.org/spec/spec.html}.
 
+@section Modula-2 language
+
+GCC supports the Modula-2 language and is compliant with the PIM2,
+PIM3, PIM4 and ISO dialects.  Also implemented are a complete set of
+free ISO libraries.  It also contains a collection of PIM libraries
+and some Logitech compatible libraries.
+
+For more information on Modula-2 see
+@uref{https://gcc.gnu.org/readings.html}.  The online manual is
+available at @uref{https://gcc.gnu.org/onlinedocs/gm2/index.html}.
+
 @section References for Other Languages
 
 @xref{Top, GNAT Reference Manual, About This Guide, gnat_rm,


[gcc r14-9998] PR modula2/114745: const cast causes ICE

2024-04-16 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:eadd05d5601063bd0c7ef6c3606b4eeb856d57d7

commit r14-9998-geadd05d5601063bd0c7ef6c3606b4eeb856d57d7
Author: Gaius Mulley 
Date:   Tue Apr 16 23:08:43 2024 +0100

PR modula2/114745: const cast causes ICE

This patch allows SYSTEM.CAST to be used during a const expression and
prevents an ICE.

gcc/m2/ChangeLog:

PR modula2/114745
* gm2-compiler/M2Code.mod (DumpLangDecl): Replace with ...
(GetDumpDecl): ... this.
(DumpLangGimple): Replace with ...
(GetDumpGimple): ... this.
* gm2-compiler/M2GenGCC.mod:
* gm2-compiler/M2LangDump.mod (GetDumpLangQuadFilename): Replace 
with ...
(GetDumpQuadFilename): ... this.
(GetDumpLangDeclFilename): Replace with ...
(GetDumpDeclFilename): ... this.
(GetDumpLangGimpleFilename): Replace with ...
(GetDumpGimpleFilename): ... this.
* gm2-compiler/M2Options.def (GetDumpLangDeclFilename): New
procedure function.
(GetDumpDeclFilename): Ditto.
(SetDumpLangDeclFilename): New procedure.
(SetDumpDeclFilename): Ditto.
(GetDumpLangQuadFilename): New procedure function.
(GetDumpQuadFilename): Ditto
(SetDumpLangQuadFilename): New procedure.
(SetDumpQuadFilename): Ditto.
(GetDumpLangGimpleFilename): New procedure function.
(GetDumpGimpleFilename): Ditto.
(SetDumpLangGimpleFilename): New procedure.
(SetDumpGimpleFilename): Ditto.
(GetDumpLangGimple): New procedure function.
(SetM2Dump): New procedure.
(GetDumpGimple): New procedure function.
(GetDumpQuad): Ditto.
(GetDumpDecl): Ditto.
* gm2-compiler/M2Options.mod (DumpLangDeclFilename): Remove.
(DumpLangQuadFilename): Ditto.
(DumpLangGimpleFilename): Ditto.
(DumpDeclFilename): New variable.
(DumpQuadFilename): Ditto.
(DumpGimpleFilename): Ditto.
(DebugTraceTree): New variable.
(SetQuadDebugging): Rewrite.
(GetDumpLangDeclFilename): Replace with ...
(GetDumpDeclFilename): ... this.
(SetDumpLangQuadFilename): Replace with ...
(SetDumpQuadFilename): ... this.
(GetDumpLangGimpleFilename): Replace with ...
(GetDumpGimpleFilename): ... this.
(SetDumpLangGimpleFilename): Replace with ...
(SetDumpGimpleFilename): ... this.
(GetDumpLangGimple): Remove.
(MatchDump): New procedure function.
(SetM2Dump): New procedure.
(GetDumpGimple): New procedure function.
(GetDumpQuad): Ditto.
(GetDumpDecl): Ditto.
(GetDumpLangGimple): Ditto.
* gm2-compiler/M2Quads.mod (BreakAtQuad): Assigned to 140.
(BuildTypeCoercion): Add ConstExpr parameter.
Check for const parameter in a const expression.
Create a constant temporary if in a const expression.
(BuildCastFunction): Pass ConstExpr to BuildTypeCoercion.
(BuildFunctionCall): Pass ConstExpr to BuildTypeCoercion.
* gm2-compiler/PCSymBuild.mod (buildConstFunction): Test for Cast
and call InitConvert.
(ErrorConstFunction): Add CAST to the error message.
* gm2-compiler/SymbolTable.mod (GetConstStringContent): Remove
unused procedure.
* gm2-gcc/m2decl.cc (m2decl_DeclareKnownConstant): Copy value
and change type of value.
* gm2-gcc/m2options.h (M2Options_GetDumpLangDeclFilename): Remove.
(M2Options_SetDumpLangDeclFilename): Ditto.
(M2Options_GetDumpLangQuadFilename): Ditto.
(M2Options_SetDumpLangQuadFilename): Ditto.
(M2Options_GetDumpLangGimpleFilename): Ditto.
(M2Options_SetDumpLangGimpleFilename): Ditto.
(M2Options_GetDumpLangGimple): Ditto.
(M2Options_GetDumpDeclFilename): New function.
(M2Options_SetDumpDeclFilename): Ditto.
(M2Options_GetDumpQuadFilename): Ditto.
(M2Options_SetDumpQuadFilename): Ditto.
(M2Options_GetDumpGimpleFilename): Ditto.
(M2Options_SetDumpGimpleFilename): Ditto.
(M2Options_SetM2Dump): Ditto.
(M2Options_GetDumpGimple): Ditto.
* gm2-gcc/m2pp.cc (GM2): New define.
(m2pp_type_lowlevel): Remove linefeed.
(m2pp_identifier): Add type description for const.
(m2pp_assignment): Display lhs/rhs types.
(m2pp_dump_gimple): Replace GetDumpLangGimple with GetDumpGimple.
* gm2-lang.cc (ENABLE_QUAD_DUMP_ALL): Remove.
(ENABLE_M2DUMP_ALL): New define.
(gm2_langhook_handle_option): Remove commented options
   

[gcc r14-10053] PR modula2/112893 full type checking between proctype and procedure not implemented

2024-04-20 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:f9a48fe7032d9894e88d0d121ba6f75b08ea5dcb

commit r14-10053-gf9a48fe7032d9894e88d0d121ba6f75b08ea5dcb
Author: Gaius Mulley 
Date:   Sat Apr 20 14:35:18 2024 +0100

PR modula2/112893 full type checking between proctype and procedure not 
implemented

This patch implements full type checking between proctype and procedures.
The change implements an associated proc type built for each
procedure.  M2Check.mod will request GetProcedureProcType if it encounters
a procedure.  Before this patch a procedure was associated with the type
ADDRESS in the type checking module M2Check.  The
gm2/pim/pass/proccard.mod have been corrected now this assumption has
been removed.

gcc/m2/ChangeLog:

PR modula2/112893
* gm2-compiler/M2Check.mod (GetProcedureProcType): Import.
(getType): Return value using GetProcedureProcType if sym is a
procedure.
* gm2-compiler/M2Range.mod (FoldTypeExpr): Remove quad if
expression is type compatible.
* gm2-compiler/SymbolTable.def (GetProcedureProcType): New
procedure function.
* gm2-compiler/SymbolTable.mod (Procedure): Add ProcedureType.
(MakeProcedure): Initialize ProcedureType.
(PutParam): Call AddProcedureProcTypeParam.
(PutVarParam): Call AddProcedureProcTypeParam.
(AddProcedureProcTypeParam): New procedure.
(GetProcedureProcType): New procedure function.

gcc/testsuite/ChangeLog:

PR modula2/112893
* gm2/pim/pass/another.mod: Correct bug exposed by type checker.
Swap ProcA and ProcB assignments.
* gm2/pim/pass/proccard.mod: Use VAL to convert procedure into a
cardinal.
* gm2/iso/const/fail/castproctype.mod: New test.
* gm2/pim/fail/badproctype.mod: New test.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-compiler/M2Check.mod   |  4 +-
 gcc/m2/gm2-compiler/M2Range.mod   |  3 +-
 gcc/m2/gm2-compiler/SymbolTable.def   |  7 +++
 gcc/m2/gm2-compiler/SymbolTable.mod   | 76 ---
 gcc/testsuite/gm2/iso/const/fail/castproctype.mod | 19 ++
 gcc/testsuite/gm2/pim/fail/badproctype.mod| 37 +++
 gcc/testsuite/gm2/pim/pass/another.mod|  8 +--
 gcc/testsuite/gm2/pim/pass/proccard.mod   |  3 +-
 8 files changed, 141 insertions(+), 16 deletions(-)

diff --git a/gcc/m2/gm2-compiler/M2Check.mod b/gcc/m2/gm2-compiler/M2Check.mod
index 20d463d207b..a4451938b88 100644
--- a/gcc/m2/gm2-compiler/M2Check.mod
+++ b/gcc/m2/gm2-compiler/M2Check.mod
@@ -47,7 +47,7 @@ FROM SymbolTable IMPORT NulSym, IsRecord, IsSet, GetDType, 
GetSType, IsType,
 IsReallyPointer, IsPointer, IsParameter, ModeOfAddr,
 GetMode, GetType, IsUnbounded, IsComposite, 
IsConstructor,
 IsParameter, IsConstString, IsConstLitInternal, 
IsConstLit,
-GetStringLength ;
+GetStringLength, GetProcedureProcType ;
 
 FROM M2GCCDeclare IMPORT GetTypeMin, GetTypeMax ;
 FROM M2System IMPORT Address ;
@@ -1397,7 +1397,7 @@ PROCEDURE getType (sym: CARDINAL) : CARDINAL ;
 BEGIN
IF (sym # NulSym) AND IsProcedure (sym)
THEN
-  RETURN Address
+  RETURN GetProcedureProcType (sym)
ELSIF IsTyped (sym)
THEN
   RETURN GetDType (sym)
diff --git a/gcc/m2/gm2-compiler/M2Range.mod b/gcc/m2/gm2-compiler/M2Range.mod
index 50c2a48fe7f..4b8e5fadfe7 100644
--- a/gcc/m2/gm2-compiler/M2Range.mod
+++ b/gcc/m2/gm2-compiler/M2Range.mod
@@ -1719,7 +1719,8 @@ BEGIN
'expression of type {%1Etad} is 
incompatible with type {%2tad}',
left, right, strict, isin)
   THEN
- SubQuad(q) ;
+ SubQuad(q)
+  ELSE
  setReported (r)
   END
END
diff --git a/gcc/m2/gm2-compiler/SymbolTable.def 
b/gcc/m2/gm2-compiler/SymbolTable.def
index ec48631e43f..d7f0f8d943c 100644
--- a/gcc/m2/gm2-compiler/SymbolTable.def
+++ b/gcc/m2/gm2-compiler/SymbolTable.def
@@ -1394,6 +1394,13 @@ PROCEDURE PutProcedureNoReturn (Sym: CARDINAL; value: 
BOOLEAN) ;
 PROCEDURE IsProcedureNoReturn (Sym: CARDINAL) : BOOLEAN ;
 
 
+(*
+   GetProcedureProcType - returns the proctype matching procedure sym.
+*)
+
+PROCEDURE GetProcedureProcType (sym: CARDINAL) : CARDINAL ;
+
+
 (*
PutModuleStartQuad - Places QuadNumber into the Module symbol, Sym.
 QuadNumber is the start quad of Module,
diff --git a/gcc/m2/gm2-compiler/SymbolTable.mod 
b/gcc/m2/gm2-compiler/SymbolTable.mod
index 13ee1fb6fe3..7543bb52749 100644
--- a/gcc/m2/gm2-compiler/SymbolTable.mod
+++ b/gcc/m2/gm2-compiler/SymbolTable.mod
@@ -407,6 +407,7 @@ TYPE
SavePriority  : BOOLEAN ;(* Does procedure need to save   *)

[gcc r14-10077] PR modula2/114807 badpointer3.mod causes an ICE

2024-04-22 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:b0469e35dbcc9a93a2cb50e3c0445edc3db174be

commit r14-10077-gb0469e35dbcc9a93a2cb50e3c0445edc3db174be
Author: Gaius Mulley 
Date:   Mon Apr 22 18:19:32 2024 +0100

PR modula2/114807 badpointer3.mod causes an ICE

This patch fixes an ICE caused when a constant string
is built and attempted to be passed into a procedure with
an opaque type.

gcc/m2/ChangeLog:

PR modula2/114807
* gm2-compiler/M2Check.mod (checkUnbounded): Remove unused
local variables.
(constCheckMeta): Include check for IsReallyPointer in the
failure case.
* gm2-compiler/M2Quads.mod (MoveWithMode): Remove CopyConstString.
* gm2-compiler/SymbolTable.def (IsHiddenReallyPointer): Export.
* gm2-compiler/SymbolTable.mod (SkipHiddenType): Remove.
(IsReallyPointer): Include IsHiddenReallyPointer test.

gcc/testsuite/ChangeLog:

PR modula2/114807
* gm2/pim/fail/badproctype.mod: Change MYSHORTREAL
to SHORTREAL.
* gm2/pim/fail/badprocbool.mod: New test.
* gm2/pim/fail/badproccard.mod: New test.
* gm2/pim/fail/badprocint.mod: New test.
* gm2/pim/fail/badprocint2.mod: New test.
* gm2/pim/pass/goodproccard2.mod: New test.
* gm2/pim/pass/goodprocint.mod: New test.
* gm2/pim/pass/goodprocint3.mod: New test.
* gm2/pim/run/pass/genconststr.mod: New test.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-compiler/M2Check.mod|  9 
 gcc/m2/gm2-compiler/M2Quads.mod|  3 +--
 gcc/m2/gm2-compiler/SymbolTable.def|  8 +++
 gcc/m2/gm2-compiler/SymbolTable.mod| 29 --
 gcc/testsuite/gm2/pim/fail/badprocbool.mod | 13 
 gcc/testsuite/gm2/pim/fail/badproccard.mod | 13 
 gcc/testsuite/gm2/pim/fail/badprocint.mod  | 17 +++
 gcc/testsuite/gm2/pim/fail/badprocint2.mod | 14 +
 gcc/testsuite/gm2/pim/fail/badproctype.mod |  9 +++-
 gcc/testsuite/gm2/pim/pass/goodproccard2.mod   | 16 ++
 gcc/testsuite/gm2/pim/pass/goodprocint.mod | 13 
 gcc/testsuite/gm2/pim/pass/goodprocint3.mod| 14 +
 gcc/testsuite/gm2/pim/run/pass/genconststr.mod | 23 
 13 files changed, 143 insertions(+), 38 deletions(-)

diff --git a/gcc/m2/gm2-compiler/M2Check.mod b/gcc/m2/gm2-compiler/M2Check.mod
index a4451938b88..1750fe07ecf 100644
--- a/gcc/m2/gm2-compiler/M2Check.mod
+++ b/gcc/m2/gm2-compiler/M2Check.mod
@@ -47,7 +47,8 @@ FROM SymbolTable IMPORT NulSym, IsRecord, IsSet, GetDType, 
GetSType, IsType,
 IsReallyPointer, IsPointer, IsParameter, ModeOfAddr,
 GetMode, GetType, IsUnbounded, IsComposite, 
IsConstructor,
 IsParameter, IsConstString, IsConstLitInternal, 
IsConstLit,
-GetStringLength, GetProcedureProcType ;
+GetStringLength, GetProcedureProcType, IsHiddenType,
+IsHiddenReallyPointer ;
 
 FROM M2GCCDeclare IMPORT GetTypeMin, GetTypeMax ;
 FROM M2System IMPORT Address ;
@@ -264,9 +265,6 @@ END checkSubrange ;
 *)
 
 PROCEDURE checkUnbounded (result: status; tinfo: tInfo; unbounded, right: 
CARDINAL) : status ;
-VAR
-   lLow,  rLow,
-   lHigh, rHigh: CARDINAL ;
 BEGIN
(* Firstly check to see if we have resolved this as false.  *)
IF isFalse (result)
@@ -683,7 +681,8 @@ BEGIN
  THEN
 RETURN result
  ELSIF IsSet (typeRight) OR IsEnumeration (typeRight) OR
-   IsProcedure (typeRight) OR IsRecord (typeRight)
+   IsProcedure (typeRight) OR IsRecord (typeRight) OR
+   IsReallyPointer (typeRight)
  THEN
 RETURN false
  ELSIF IsArray (typeRight)
diff --git a/gcc/m2/gm2-compiler/M2Quads.mod b/gcc/m2/gm2-compiler/M2Quads.mod
index 68b91201702..8a9a23013b2 100644
--- a/gcc/m2/gm2-compiler/M2Quads.mod
+++ b/gcc/m2/gm2-compiler/M2Quads.mod
@@ -73,7 +73,7 @@ FROM SymbolTable IMPORT ModeOfAddr, GetMode, PutMode, 
GetSymName, IsUnknown,
 GetModuleQuads, GetProcedureQuads,
 GetModuleCtors,
 MakeProcedure,
-CopyConstString, PutConstStringKnown,
+PutConstStringKnown,
 PutModuleStartQuad, PutModuleEndQuad,
 PutModuleFinallyStartQuad, PutModuleFinallyEndQuad,
 PutProcedureStartQuad, PutProcedureEndQuad,
@@ -3454,7 +3454,6 @@ BEGIN
THEN
   GenQuadOtok (tokno, BecomesOp, Des, NulSym, Exp, TRUE,
destok, UnknownTokenNo, exptok) ;
-  CopyConstString (tokno, Des, Exp)
ELSE
   IF GetMode(Des)=RightValue
   THEN
diff --git a

[gcc r14-10080] PR modula2/114811 string set incl ICE bugfix

2024-04-22 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:b909daa5b67317e46543a7b2ed76e82298645cf6

commit r14-10080-gb909daa5b67317e46543a7b2ed76e82298645cf6
Author: Gaius Mulley 
Date:   Mon Apr 22 20:34:11 2024 +0100

PR modula2/114811 string set incl ICE bugfix

This patch corrects gm2-torture.exp to recognize an ICE
in the fail case as a negative result.  The patch also fixes
FoldBinarySet so that the types are only checked once the operands
have been resolved.  Without this patch
gcc/testsuite/gm2/iso/fail/badexpression2.mod would cause an ICE.

gcc/m2/ChangeLog:

PR modula2/114811
* gm2-compiler/M2GenGCC.mod (FoldBinarySet): Add condition
checking to ensure op2 and op3 are fully resolved before
type checking is performed.

gcc/testsuite/ChangeLog:

PR modula2/114811
* lib/gm2-torture.exp: Correct regexp checking for internal
compiler error strings in compiler output.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-compiler/M2GenGCC.mod  | 43 +--
 gcc/testsuite/lib/gm2-torture.exp |  7 ---
 2 files changed, 27 insertions(+), 23 deletions(-)

diff --git a/gcc/m2/gm2-compiler/M2GenGCC.mod b/gcc/m2/gm2-compiler/M2GenGCC.mod
index da52c924974..26ed399b24c 100644
--- a/gcc/m2/gm2-compiler/M2GenGCC.mod
+++ b/gcc/m2/gm2-compiler/M2GenGCC.mod
@@ -5000,29 +5000,32 @@ BEGIN
TryDeclareConstant(tokenno, op3) ;
location := TokenToLocation(tokenno) ;
 
-   IF CheckBinaryExpressionTypes (quad, p)
+   IF GccKnowsAbout(op2) AND GccKnowsAbout(op3)
THEN
-  IF IsConst(op2) AND IsConstSet(op2) AND
- IsConst(op3) AND IsConstSet(op3) AND
- IsConst(op1)
+  IF CheckBinaryExpressionTypes (quad, p)
   THEN
- IF IsValueSolved(op2) AND IsValueSolved(op3)
+ IF IsConst(op2) AND IsConstSet(op2) AND
+IsConst(op3) AND IsConstSet(op3) AND
+IsConst(op1)
  THEN
-Assert(MixTypes(FindType(op3), FindType(op2), tokenno)#NulSym) ;
-PutConst(op1, MixTypes(FindType(op3), FindType(op2), tokenno)) ;
-PushValue(op2) ;
-PushValue(op3) ;
-op(tokenno) ;
-PopValue(op1) ;
-PushValue(op1) ;
-PutConstSet(op1) ;
-AddModGcc(op1,
-  DeclareKnownConstant(location,
-   Mod2Gcc(GetType(op3)),
-   PopSetTree(tokenno))) ;
-p(op1) ;
-NoChange := FALSE ;
-SubQuad(quad)
+IF IsValueSolved(op2) AND IsValueSolved(op3)
+THEN
+   Assert(MixTypes(FindType(op3), FindType(op2), tokenno)#NulSym) ;
+   PutConst(op1, MixTypes(FindType(op3), FindType(op2), tokenno)) ;
+   PushValue(op2) ;
+   PushValue(op3) ;
+   op(tokenno) ;
+   PopValue(op1) ;
+   PushValue(op1) ;
+   PutConstSet(op1) ;
+   AddModGcc(op1,
+ DeclareKnownConstant(location,
+  Mod2Gcc(GetType(op3)),
+  PopSetTree(tokenno))) ;
+   p(op1) ;
+   NoChange := FALSE ;
+   SubQuad(quad)
+END
  END
   END
END
diff --git a/gcc/testsuite/lib/gm2-torture.exp 
b/gcc/testsuite/lib/gm2-torture.exp
index 090929954ca..c29b0b4d1a0 100644
--- a/gcc/testsuite/lib/gm2-torture.exp
+++ b/gcc/testsuite/lib/gm2-torture.exp
@@ -138,7 +138,7 @@ proc gm2-torture-compile { src option } {
 
 proc gm2_check_compile_fail {testcase option objname gcc_output} {
 global tool;
-set fatal_signal "*cc: Internal compiler error: program*got fatal signal"
+set fatal_signal "*nternal compiler error: program*got fatal signal"
 
 if [string match "$fatal_signal 6" $gcc_output] then {
${tool}_fail $testcase "Got Signal 6, $option"
@@ -170,8 +170,9 @@ proc gm2_check_compile_fail {testcase option objname 
gcc_output} {
 regsub -all -- "\[\r\n\]*" $gcc_output "" gcc_output
 
 # check for any internal error
-if { [string match "internal error" $gcc_output] ||
-[string match "internal compiler error" $gcc_output] } then {
+if { [string match "*internal error*" $gcc_output] ||
+[string match "*internal compiler error*" $gcc_output] } then {
+   puts stderr "ICE: "
${tool}_fail $testcase $option
return 0
 }


[gcc r14-10121] modula2: issue the parameter incompatibility error message based on dialect

2024-04-25 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:070dd5c883ec2c0be542f448bd82d0f7f0ead390

commit r14-10121-g070dd5c883ec2c0be542f448bd82d0f7f0ead390
Author: Gaius Mulley 
Date:   Thu Apr 25 15:19:30 2024 +0100

modula2: issue the parameter incompatibility error message based on dialect

This tiny patch improves the parameter incompatibility error message by
having a different message for the dialect chosen mentioning the specific
violation.  PIM uses assignment rules for pass by value and expression
rules for pass by reference.  ISO uses expression type checking for
pass by value and pass by reference.

gcc/m2/ChangeLog:

* gm2-compiler/M2FileName.def (CalculateFileName): Remove
quoted string in comment.
* gm2-compiler/M2Range.mod (FoldTypeParam): Generate dialect
specific parameter incompatibility error message.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-compiler/M2FileName.def |  2 +-
 gcc/m2/gm2-compiler/M2Range.mod| 32 +++-
 2 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/gcc/m2/gm2-compiler/M2FileName.def 
b/gcc/m2/gm2-compiler/M2FileName.def
index 02413593003..01acb9b48d5 100644
--- a/gcc/m2/gm2-compiler/M2FileName.def
+++ b/gcc/m2/gm2-compiler/M2FileName.def
@@ -39,7 +39,7 @@ EXPORT QUALIFIED CalculateFileName, CalculateStemName, 
ExtractExtension ;
given a module and an extension. This file name
length will be operating system specific.
String, Extension, is concatenated onto
-   Module and thus it is safe to `Mark' the extension
+   Module and thus it is safe to Mark the extension
for garbage collection.
 *)
 
diff --git a/gcc/m2/gm2-compiler/M2Range.mod b/gcc/m2/gm2-compiler/M2Range.mod
index 4b8e5fadfe7..7686620a247 100644
--- a/gcc/m2/gm2-compiler/M2Range.mod
+++ b/gcc/m2/gm2-compiler/M2Range.mod
@@ -56,7 +56,7 @@ FROM M2Debug IMPORT Assert ;
 FROM Indexing IMPORT Index, InitIndex, InBounds, PutIndice, GetIndice ;
 FROM Storage IMPORT ALLOCATE ;
 FROM M2ALU IMPORT PushIntegerTree, PushInt, ConvertToInt, Equ, Gre, Less, 
GreEqu ;
-FROM M2Options IMPORT VariantValueChecking, CaseEnumChecking ;
+FROM M2Options IMPORT VariantValueChecking, CaseEnumChecking, GetPIM ;
 
 FROM M2Error IMPORT Error, InternalError, ErrorFormat0, ErrorFormat1, 
ErrorFormat2, FlushErrors,
 GetAnnounceScope ;
@@ -1693,14 +1693,36 @@ END FoldTypeAssign ;
 
 
 (*
-   FoldTypeParam -
+   FoldTypeParam - performs a parameter check between actual and formal.
+   The quad is removed if the check succeeds.
 *)
 
 PROCEDURE FoldTypeParam (q: CARDINAL; tokenNo: CARDINAL; formal, actual, 
procedure: CARDINAL; paramNo: CARDINAL) ;
+VAR
+   compatible: BOOLEAN ;
 BEGIN
-   IF ParameterTypeCompatible (tokenNo,
-   '{%4EN} parameter type failure between actual 
parameter type {%3ad} and the formal type {%2ad}',
-   procedure, formal, actual, paramNo, IsVarParam 
(procedure, paramNo))
+   compatible := FALSE ;
+   IF IsVarParam (procedure, paramNo)
+   THEN
+  (* Expression type compatibility rules for pass by reference parameters. 
 *)
+  compatible := ParameterTypeCompatible (tokenNo,
+ '{%4EN} parameter failure due to 
expression incompatibility ' +
+ 'between actual parameter {%3ad} 
and the {%4N} formal {%2ad} parameter in procedure {%1ad}',
+ procedure, formal, actual, 
paramNo, TRUE)
+   ELSIF GetPIM ()
+   THEN
+  (* Assignment type compatibility rules for pass by value PIM parameters. 
 *)
+  compatible := ParameterTypeCompatible (tokenNo,
+ '{%4EN} parameter failure due to 
assignment incompatibility ' +
+ 'between actual parameter {%3ad} 
and the {%4N} formal {%2ad} parameter in procedure {%1ad}',
+ procedure, formal, actual, 
paramNo, FALSE)
+   ELSE
+  compatible := ParameterTypeCompatible (tokenNo,
+ '{%4EN} parameter failure due to 
parameter incompatibility ' +
+ 'between actual parameter {%3ad} 
and the {%4N} formal {%2ad} parameter in procedure {%1ad}',
+ procedure, formal, actual, 
paramNo, FALSE)
+   END ;
+   IF compatible
THEN
   SubQuad(q)
END


[gcc r14-10124] PR modula2/114836 Avoid concatenation of error strings to aid error locale translation

2024-04-25 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:d0e1e1291b10372d71ad3d6cb66b333ea91097e7

commit r14-10124-gd0e1e1291b10372d71ad3d6cb66b333ea91097e7
Author: Gaius Mulley 
Date:   Thu Apr 25 18:31:55 2024 +0100

PR modula2/114836 Avoid concatenation of error strings to aid error locale 
translation

This patch avoids a concatenation of error strings making locale
translation of the error message easier.

gcc/m2/ChangeLog:

PR modula2/114836
* gm2-compiler/M2Range.mod (FoldTypeAssign): Avoid error
string concatenation.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-compiler/M2Range.mod | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/gcc/m2/gm2-compiler/M2Range.mod b/gcc/m2/gm2-compiler/M2Range.mod
index 7686620a247..a8e572eff50 100644
--- a/gcc/m2/gm2-compiler/M2Range.mod
+++ b/gcc/m2/gm2-compiler/M2Range.mod
@@ -1706,20 +1706,17 @@ BEGIN
THEN
   (* Expression type compatibility rules for pass by reference parameters. 
 *)
   compatible := ParameterTypeCompatible (tokenNo,
- '{%4EN} parameter failure due to 
expression incompatibility ' +
- 'between actual parameter {%3ad} 
and the {%4N} formal {%2ad} parameter in procedure {%1ad}',
+ '{%4EN} parameter failure due to 
expression incompatibility between actual parameter {%3ad} and the {%4N} formal 
{%2ad} parameter in procedure {%1ad}',
  procedure, formal, actual, 
paramNo, TRUE)
ELSIF GetPIM ()
THEN
   (* Assignment type compatibility rules for pass by value PIM parameters. 
 *)
   compatible := ParameterTypeCompatible (tokenNo,
- '{%4EN} parameter failure due to 
assignment incompatibility ' +
- 'between actual parameter {%3ad} 
and the {%4N} formal {%2ad} parameter in procedure {%1ad}',
+ '{%4EN} parameter failure due to 
assignment incompatibility between actual parameter {%3ad} and the {%4N} formal 
{%2ad} parameter in procedure {%1ad}',
  procedure, formal, actual, 
paramNo, FALSE)
ELSE
   compatible := ParameterTypeCompatible (tokenNo,
- '{%4EN} parameter failure due to 
parameter incompatibility ' +
- 'between actual parameter {%3ad} 
and the {%4N} formal {%2ad} parameter in procedure {%1ad}',
+ '{%4EN} parameter failure due to 
parameter incompatibility between actual parameter {%3ad} and the {%4N} formal 
{%2ad} parameter in procedure {%1ad}',
  procedure, formal, actual, 
paramNo, FALSE)
END ;
IF compatible


[gcc r15-110] PR modula2/113836 gm2 does not dump gimple or quadruples to a file

2024-05-02 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:43dc4302b4181535d24e83759514b774ae4dbfcc

commit r15-110-g43dc4302b4181535d24e83759514b774ae4dbfcc
Author: Gaius Mulley 
Date:   Thu May 2 13:16:07 2024 +0100

PR modula2/113836 gm2 does not dump gimple or quadruples to a file

This patch completes the implementation of dumping the intermediate forms
to file.  It implements the filtering on symbol rules.  Filtering can be
performed through the full text name (given to the GCC tree) or qualified
modula-2 symbol or filename:qualident.

gcc/ChangeLog:

PR modula2/113836
* doc/gm2.texi (Compiler options): Add -fm2-debug-trace=,
-fm2-dump, -fm2-dump-decl=, -fm2-dump-gimple=, -fm2-dump-quad=
and -fm2-dump-filter=.

gcc/m2/ChangeLog:

PR modula2/113836
* gm2-compiler/M2AsmUtil.def: Remove export qualified and
unused import.
* gm2-compiler/M2LangDump.mod (AddRuleTextDump): New procedure.
(AddRuleScopeQualidentDump): Add warning check against unmatched
rule.
(GenQualidentSymString): New procedure function.
(IdentQualidentMatch): New procedure function.
(IsRuleFilenameMatch): New procedure function.
(CheckRuleMatch): New procedure function.
(AddRuleFilenameDump): New procedure function.
* gm2-gcc/m2misc.cc (m2misc_warning_m2_dump_filter): New function.
* gm2-gcc/m2misc.def (warning_m2_dump_filter): New procedure.
* gm2-gcc/m2misc.h (m2misc_warning_m2_dump_filter): New prototype.
* gm2-gcc/m2pp.cc (VERBOSE_TYPE_DESC): New define.
(m2pp_identifier): Define out verbose type info.
(m2pp_constructor): Define out verbose type info.
(m2pp_assignment): Define out verbose type info.
* gm2-lang.cc (ENABLE_M2DUMP_ALL): Remove.
* lang.opt (fm2-dump): Add.
(fm2-dump-decl=): Add.
(fm2-dump-gimple=): Add.
(fm2-dump-quad=): Add.
(fm2-dump-filter=): Add.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/doc/gm2.texi   |  39 --
 gcc/m2/gm2-compiler/M2AsmUtil.def  |   2 -
 gcc/m2/gm2-compiler/M2LangDump.mod | 150 +++--
 gcc/m2/gm2-gcc/m2misc.cc   |  10 +++
 gcc/m2/gm2-gcc/m2misc.def  |   3 +-
 gcc/m2/gm2-gcc/m2misc.h|   1 +
 gcc/m2/gm2-gcc/m2pp.cc |  21 +-
 gcc/m2/gm2-lang.cc |   4 -
 gcc/m2/lang.opt|  20 +
 9 files changed, 225 insertions(+), 25 deletions(-)

diff --git a/gcc/doc/gm2.texi b/gcc/doc/gm2.texi
index 19b864573c1..b38d6a15de0 100644
--- a/gcc/doc/gm2.texi
+++ b/gcc/doc/gm2.texi
@@ -466,10 +466,39 @@ this option forces the use of the static version.
 @c Modula-2 Joined
 @c set all location values to a specific value (internal switch)
 
-@c fm2-debug-trace=
-@c Modula-2 Joined
-@c turn on trace debugging using a comma separated list:
-@c line,token,quad,all.
+@item -fm2-debug-trace=
+turn on trace debugging using a comma separated list:
+@samp{line,token,quad,all}.  This is an internal command line option.
+
+@item -fm2-dump=
+enable dumping of modula-2 internal representation of data structures
+using a comma separated list.  The list can contain:
+@samp{quad,gimple,decl,all}.
+
+@item -fm2-dump-decl=@file{filestem}
+dump the modula-2 representation of a symbol to the @file{filestem}
+specified.  This option only takes effect if the
+@samp{-fm2-dump-filter} is specified.
+
+@item -fm2-dump-gimple=@file{filestem}
+dump modula-2 gimple representation to the @file{filestem} specified.
+
+@item -fm2-dump-quad=@file{filestem}
+dump quadruple representation to the @file{filestem} specified.
+
+@item -fm2-dump-filter=@samp{rules}
+filter the language dumps @samp{-fdump-lang-decl},
+@samp{-fdump-lang-gimple} and@samp{-fdump-lang-quad}
+on @samp{rules}.  @samp{rules} must be a comma
+separated list which can take three forms: the full decl textual name
+of a procedure, @samp{[libname.]module.ident} or
+@samp{[filename:]module.ident}.  This is an internal command line
+option.  Currently it only filters on procedure names and regexp
+matching is not implemented.  Three examples of its use following
+the previous forms could be:
+@code{-fm2-dump-filter=_M2_hello_init},
+@code{-fm2-dump-filter=m2pim.StrIO.WriteString} and
+@code{-fm2-dump-filter=StrLib.mod:StrIO.WriteString}.
 
 @item -fm2-g
 improve the debugging experience for new programmers at the expense
@@ -487,7 +516,7 @@ specify the module mangled prefix name for all modules in 
the
 following include paths.
 
 @item -fm2-pathnameI
-for internal use only: used by the driver to copy the user facing -I
+for internal use only: used by the driver to copy the user facing @samp{-I}
 option.
 
 @item -fm2-plugin
diff --git a/gcc/m2/gm2-compiler/M2AsmUtil.def 
b/gcc/m2/gm2-compiler/M2AsmUtil.def

[gcc r15-113] modula2: Regenerate libgm2 Makefile.ins using correct include order

2024-05-02 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:67e66c973ce31e375caa9611b2db290fbfc1904d

commit r15-113-g67e66c973ce31e375caa9611b2db290fbfc1904d
Author: Gaius Mulley 
Date:   Thu May 2 14:38:51 2024 +0100

modula2: Regenerate libgm2 Makefile.ins using correct include order

Regenerated libgm2/Makefile.in (and subdir Makefile.in) using
aclocal -I .. -I ../config (or autoreconf).

libgm2/ChangeLog:

* Makefile.in: Regenerate.
* libm2cor/Makefile.in: Ditto.
* libm2iso/Makefile.in: Ditto.
* libm2log/Makefile.in: Ditto.
* libm2min/Makefile.in: Ditto.
* libm2pim/Makefile.in: Ditto.
* aclocal.m4: Ditto.

Signed-off-by: Gaius Mulley 

Diff:
---
 libgm2/Makefile.in  | 10 +-
 libgm2/aclocal.m4   | 10 +-
 libgm2/libm2cor/Makefile.in | 10 +-
 libgm2/libm2iso/Makefile.in | 10 +-
 libgm2/libm2log/Makefile.in | 10 +-
 libgm2/libm2min/Makefile.in | 10 +-
 libgm2/libm2pim/Makefile.in | 10 +-
 7 files changed, 35 insertions(+), 35 deletions(-)

diff --git a/libgm2/Makefile.in b/libgm2/Makefile.in
index f259df7842c..9cd79824a53 100644
--- a/libgm2/Makefile.in
+++ b/libgm2/Makefile.in
@@ -90,15 +90,15 @@ host_triplet = @host@
 target_triplet = @target@
 subdir = .
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/../libtool.m4 \
-   $(top_srcdir)/../ltoptions.m4 $(top_srcdir)/../ltsugar.m4 \
-   $(top_srcdir)/../ltversion.m4 $(top_srcdir)/../lt~obsolete.m4 \
-   $(top_srcdir)/../config/acx.m4 \
+am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
$(top_srcdir)/../config/depstand.m4 \
$(top_srcdir)/../config/lead-dot.m4 \
$(top_srcdir)/../config/multi.m4 \
$(top_srcdir)/../config/no-executables.m4 \
-   $(top_srcdir)/../config/override.m4 $(top_srcdir)/acinclude.m4 \
+   $(top_srcdir)/../config/override.m4 \
+   $(top_srcdir)/../libtool.m4 $(top_srcdir)/../ltoptions.m4 \
+   $(top_srcdir)/../ltsugar.m4 $(top_srcdir)/../ltversion.m4 \
+   $(top_srcdir)/../lt~obsolete.m4 $(top_srcdir)/acinclude.m4 \
$(top_srcdir)/../config/gc++filt.m4 \
$(top_srcdir)/../config/tls.m4 $(top_srcdir)/../config/gthr.m4 \
$(top_srcdir)/../config/cet.m4 $(top_srcdir)/configure.ac
diff --git a/libgm2/aclocal.m4 b/libgm2/aclocal.m4
index bee67b05dee..19cfb0d1eb2 100644
--- a/libgm2/aclocal.m4
+++ b/libgm2/aclocal.m4
@@ -1187,15 +1187,15 @@ AC_SUBST([am__tar])
 AC_SUBST([am__untar])
 ]) # _AM_PROG_TAR
 
-m4_include([../libtool.m4])
-m4_include([../ltoptions.m4])
-m4_include([../ltsugar.m4])
-m4_include([../ltversion.m4])
-m4_include([../lt~obsolete.m4])
 m4_include([../config/acx.m4])
 m4_include([../config/depstand.m4])
 m4_include([../config/lead-dot.m4])
 m4_include([../config/multi.m4])
 m4_include([../config/no-executables.m4])
 m4_include([../config/override.m4])
+m4_include([../libtool.m4])
+m4_include([../ltoptions.m4])
+m4_include([../ltsugar.m4])
+m4_include([../ltversion.m4])
+m4_include([../lt~obsolete.m4])
 m4_include([acinclude.m4])
diff --git a/libgm2/libm2cor/Makefile.in b/libgm2/libm2cor/Makefile.in
index 63299388dd8..f9952cff71a 100644
--- a/libgm2/libm2cor/Makefile.in
+++ b/libgm2/libm2cor/Makefile.in
@@ -108,15 +108,15 @@ target_triplet = @target@
 @BUILD_CORLIB_TRUE@@ENABLE_DARWIN_AT_RPATH_TRUE@am__append_1 = 
-nodefaultrpaths -Wl,-rpath,@loader_path/
 subdir = libm2cor
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/../libtool.m4 \
-   $(top_srcdir)/../ltoptions.m4 $(top_srcdir)/../ltsugar.m4 \
-   $(top_srcdir)/../ltversion.m4 $(top_srcdir)/../lt~obsolete.m4 \
-   $(top_srcdir)/../config/acx.m4 \
+am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
$(top_srcdir)/../config/depstand.m4 \
$(top_srcdir)/../config/lead-dot.m4 \
$(top_srcdir)/../config/multi.m4 \
$(top_srcdir)/../config/no-executables.m4 \
-   $(top_srcdir)/../config/override.m4 $(top_srcdir)/acinclude.m4 \
+   $(top_srcdir)/../config/override.m4 \
+   $(top_srcdir)/../libtool.m4 $(top_srcdir)/../ltoptions.m4 \
+   $(top_srcdir)/../ltsugar.m4 $(top_srcdir)/../ltversion.m4 \
+   $(top_srcdir)/../lt~obsolete.m4 $(top_srcdir)/acinclude.m4 \
$(top_srcdir)/../config/gc++filt.m4 \
$(top_srcdir)/../config/tls.m4 $(top_srcdir)/../config/gthr.m4 \
$(top_srcdir)/../config/cet.m4 $(top_srcdir)/configure.ac
diff --git a/libgm2/libm2iso/Makefile.in b/libgm2/libm2iso/Makefile.in
index 964c6da8527..370837f15b8 100644
--- a/libgm2/libm2iso/Makefile.in
+++ b/libgm2/libm2iso/Makefile.in
@@ -108,15 +108,15 @@ target_triplet = @target@
 @BUILD_ISOLIB_TRUE@@ENABLE_DARWIN_AT_RPATH_TRUE@am__append_1 = 
-nodefaultrpaths -Wl,-rpath,@loader_path/
 subdir = libm2iso
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/../libtool.m4 \
-   $(top_srcdir)/../ltoptions.m4 $(top_s

[gcc r15-819] modula2: fix xref fourth parameter in documentation, change from gm2 to m2

2024-05-24 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:5833e5b8ef40367764325f4f3c80cfa129fbe1da

commit r15-819-g5833e5b8ef40367764325f4f3c80cfa129fbe1da
Author: Gaius Mulley 
Date:   Fri May 24 13:42:58 2024 +0100

modula2: fix xref fourth parameter in documentation, change from gm2 to m2

This patch corrects the gm2.texi xref for the modula-2 documentation.

gcc/ChangeLog:

* doc/gm2.texi: Replace all occurrences of xref {, , , gm2}
with xref {, , , m2}.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/doc/gm2.texi | 26 +-
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/gcc/doc/gm2.texi b/gcc/doc/gm2.texi
index b38d6a15de0..7e580400fb9 100644
--- a/gcc/doc/gm2.texi
+++ b/gcc/doc/gm2.texi
@@ -291,7 +291,7 @@ This manual only documents the options specific to 
@command{gm2}.
 
 This section describes how to compile and link a simple hello world
 program.  It provides a few examples of using the different options
-mentioned in @pxref{Compiler options, , ,gm2}.  Assuming that you have
+mentioned in @pxref{Compiler options, , ,m2}.  Assuming that you have
 a file called @file{hello.mod} in your current directory which
 contains:
 
@@ -442,7 +442,7 @@ turn on ISO standard features.  Currently this enables the 
ISO
 @code{SYSTEM} module and alters the default library search path so
 that the ISO libraries are searched before the PIM libraries.  It also
 effects the behavior of @code{DIV} and @code{MOD} operators.
-@xref{Dialect, , ,gm2}.
+@xref{Dialect, , ,m2}.
 
 @item -flibs=
 modifies the default library search path.  The libraries supplied are:
@@ -558,30 +558,30 @@ turn on PIM standard features.  Currently this enables 
the PIM
 @code{SYSTEM} module and determines which identifiers are pervasive
 (declared in the base module).  If no other @samp{-fpim[234]} switch is
 used then division and modulus operators behave as defined in PIM4.
-@xref{Dialect, , ,gm2}.
+@xref{Dialect, , ,m2}.
 
 @item -fpim2
 turn on PIM-2 standard features.  Currently this removes @code{SIZE}
 from being a pervasive identifier (declared in the base module).  It
 places @code{SIZE} in the @code{SYSTEM} module.  It also effects the
 behavior of @code{DIV} and @code{MOD} operators.
-@xref{Dialect, , ,gm2}.
+@xref{Dialect, , ,m2}.
 
 @item -fpim3
 turn on PIM-3 standard features.  Currently this only effects the
 behavior of @code{DIV} and @code{MOD} operators.
-@xref{Dialect, , ,gm2}.
+@xref{Dialect, , ,m2}.
 
 @item -fpim4
 turn on PIM-4 standard features.  Currently this only effects the
 behavior of @code{DIV} and @code{MOD} operators.
-@xref{Dialect, , ,gm2}.
+@xref{Dialect, , ,m2}.
 
 @item -fpositive-mod-floor-div
 forces the @code{DIV} and @code{MOD} operators to behave as defined by PIM4.
 All modulus results are positive and the results from the division are
 rounded to the floor.
-@xref{Dialect, , ,gm2}.
+@xref{Dialect, , ,m2}.
 
 @item -fpthread
 link against the pthread library.  By default this option is on.  It
@@ -876,8 +876,8 @@ LONGCOMPLEX   complex long double
 
 Note that GNU Modula-2 also supports fixed sized data types which are
 exported from the @code{SYSTEM} module.
-@xref{The PIM system module, , ,gm2}.
-@xref{The ISO system module, , ,gm2}.
+@xref{The PIM system module, , ,m2}.
+@xref{The ISO system module, , ,m2}.
 
 @node Standard procedures, High procedure function, Elementary data types, 
Using
 @section Permanently accessible base procedures.
@@ -1628,7 +1628,7 @@ This section introduces the GNU Modula-2 language 
extensions.
 The GNU Modula-2 compiler allows abstract data types to be any type,
 not just restricted to a pointer type providing the
 @samp{-fextended-opaque} option is supplied
-@xref{Compiler options, , ,gm2}.
+@xref{Compiler options, , ,m2}.
 
 Declarations can be made in any order, whether they are
 types, constants, procedures, nested modules or variables.
@@ -1829,8 +1829,8 @@ program module.
 
 GNU Modula-2 also provides additional fixed sized data types which
 are all exported from the @code{SYSTEM} module.
-@xref{The PIM system module, , ,gm2}.
-@xref{The ISO system module, , ,gm2}.
+@xref{The PIM system module, , ,m2}.
+@xref{The ISO system module, , ,m2}.
 
 @node Type compatibility, Unbounded by reference, Extensions, Using
 @section Type compatibility
@@ -2205,7 +2205,7 @@ $ python3 testnum.py
 1234 x 2 = 2468
 @end example
 
-@xref{Producing a Python module, , ,gm2} for another example which
+@xref{Producing a Python module, , ,m2} for another example which
 uses the @code{UNQUALIFIED} keyword to reduce the module name clutter
 from the viewport of Python3.


[gcc r15-852] modula2: simplify xref usage in documentation, remove external ref to gm2.

2024-05-27 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:a209f219b862def8fed166b31984b8c6c3bb74a0

commit r15-852-ga209f219b862def8fed166b31984b8c6c3bb74a0
Author: Gaius Mulley 
Date:   Mon May 27 18:06:59 2024 +0100

modula2: simplify xref usage in documentation, remove external ref to gm2.

This patch simplifies all the xref usage for gm2 nodes in the
modula-2 documentation.

gcc/ChangeLog:

* doc/gm2.texi: Replace all occurrences of xref
{foo, , , gm2} with xref {foo}.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/doc/gm2.texi | 26 +-
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/gcc/doc/gm2.texi b/gcc/doc/gm2.texi
index d553131e1bd..8661fcb8728 100644
--- a/gcc/doc/gm2.texi
+++ b/gcc/doc/gm2.texi
@@ -291,7 +291,7 @@ This manual only documents the options specific to 
@command{gm2}.
 
 This section describes how to compile and link a simple hello world
 program.  It provides a few examples of using the different options
-mentioned in @pxref{Compiler options, , ,m2}.  Assuming that you have
+mentioned in @pxref{Compiler options}.  Assuming that you have
 a file called @file{hello.mod} in your current directory which
 contains:
 
@@ -442,7 +442,7 @@ turn on ISO standard features.  Currently this enables the 
ISO
 @code{SYSTEM} module and alters the default library search path so
 that the ISO libraries are searched before the PIM libraries.  It also
 effects the behavior of @code{DIV} and @code{MOD} operators.
-@xref{Dialect, , ,m2}.
+@xref{Dialect}.
 
 @item -flibs=
 modifies the default library search path.  The libraries supplied are:
@@ -558,30 +558,30 @@ turn on PIM standard features.  Currently this enables 
the PIM
 @code{SYSTEM} module and determines which identifiers are pervasive
 (declared in the base module).  If no other @samp{-fpim[234]} switch is
 used then division and modulus operators behave as defined in PIM4.
-@xref{Dialect, , ,m2}.
+@xref{Dialect}.
 
 @item -fpim2
 turn on PIM-2 standard features.  Currently this removes @code{SIZE}
 from being a pervasive identifier (declared in the base module).  It
 places @code{SIZE} in the @code{SYSTEM} module.  It also effects the
 behavior of @code{DIV} and @code{MOD} operators.
-@xref{Dialect, , ,m2}.
+@xref{Dialect}.
 
 @item -fpim3
 turn on PIM-3 standard features.  Currently this only effects the
 behavior of @code{DIV} and @code{MOD} operators.
-@xref{Dialect, , ,m2}.
+@xref{Dialect}.
 
 @item -fpim4
 turn on PIM-4 standard features.  Currently this only effects the
 behavior of @code{DIV} and @code{MOD} operators.
-@xref{Dialect, , ,m2}.
+@xref{Dialect}.
 
 @item -fpositive-mod-floor-div
 forces the @code{DIV} and @code{MOD} operators to behave as defined by PIM4.
 All modulus results are positive and the results from the division are
 rounded to the floor.
-@xref{Dialect, , ,m2}.
+@xref{Dialect}.
 
 @item -fpthread
 link against the pthread library.  By default this option is on.  It
@@ -876,8 +876,8 @@ LONGCOMPLEX   complex long double
 
 Note that GNU Modula-2 also supports fixed sized data types which are
 exported from the @code{SYSTEM} module.
-@xref{The PIM system module, , ,m2}.
-@xref{The ISO system module, , ,m2}.
+@xref{The PIM system module}.
+@xref{The ISO system module}.
 
 @node Standard procedures, High procedure function, Elementary data types, 
Using
 @section Permanently accessible base procedures.
@@ -1628,7 +1628,7 @@ This section introduces the GNU Modula-2 language 
extensions.
 The GNU Modula-2 compiler allows abstract data types to be any type,
 not just restricted to a pointer type providing the
 @samp{-fextended-opaque} option is supplied
-@xref{Compiler options, , ,m2}.
+@xref{Compiler options}.
 
 Declarations can be made in any order, whether they are
 types, constants, procedures, nested modules or variables.
@@ -1829,8 +1829,8 @@ program module.
 
 GNU Modula-2 also provides additional fixed sized data types which
 are all exported from the @code{SYSTEM} module.
-@xref{The PIM system module, , ,m2}.
-@xref{The ISO system module, , ,m2}.
+@xref{The PIM system module}.
+@xref{The ISO system module}.
 
 @node Type compatibility, Unbounded by reference, Extensions, Using
 @section Type compatibility
@@ -2205,7 +2205,7 @@ $ python3 testnum.py
 1234 x 2 = 2468
 @end example
 
-@xref{Producing a Python module, , ,m2} for another example which
+@xref{Producing a Python module} for another example which
 uses the @code{UNQUALIFIED} keyword to reduce the module name clutter
 from the viewport of Python3.


[gcc r15-909] PR modula2/115276 bugfix libgm2 wraptime.InitTM returns NIL

2024-05-29 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:d1a1f7e9f0bedea55c558ab95127679bc3e9ff72

commit r15-909-gd1a1f7e9f0bedea55c558ab95127679bc3e9ff72
Author: Gaius Mulley 
Date:   Wed May 29 17:26:59 2024 +0100

PR modula2/115276 bugfix libgm2 wraptime.InitTM returns NIL

This patch fixes libgm2/libm2iso/wraptime.cc:InitTM so that
it does not always return NULL.  The incorrect autoconf macro
was used (inside InitTM) and the function short circuited
to return NULL.  The fix is to use HAVE_SYS_TIME_H and use
AC_HEADER_TIME in libgm2/configure.ac.

libgm2/ChangeLog:

PR modula2/115276
* config.h.in: Regenerate.
* configure: Regenerate.
* configure.ac: Use AC_HEADER_TIME.
* libm2iso/wraptime.cc (InitTM): Check HAVE_SYS_TIME_H
before using struct tm to obtain the size.

gcc/testsuite/ChangeLog:

PR modula2/115276
* gm2/isolib/run/pass/testinittm.mod: New test.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/testsuite/gm2/isolib/run/pass/testinittm.mod | 17 +++
 libgm2/config.h.in   |  3 ++
 libgm2/configure | 39 ++--
 libgm2/configure.ac  |  1 +
 libgm2/libm2iso/wraptime.cc  |  2 +-
 5 files changed, 59 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/gm2/isolib/run/pass/testinittm.mod 
b/gcc/testsuite/gm2/isolib/run/pass/testinittm.mod
new file mode 100644
index 000..dfe041140f1
--- /dev/null
+++ b/gcc/testsuite/gm2/isolib/run/pass/testinittm.mod
@@ -0,0 +1,17 @@
+MODULE testinittm ;
+
+FROM wraptime IMPORT InitTM, tm ;
+FROM libc IMPORT printf, exit ;
+
+VAR
+   m: tm ;
+BEGIN
+   m := InitTM () ;
+   IF m = NIL
+   THEN
+  printf ("InitTM failed\n");
+  exit (1)
+   ELSE
+  printf ("InitTM passed\n")
+   END
+END testinittm.
diff --git a/libgm2/config.h.in b/libgm2/config.h.in
index 7426cb26cf8..321ef3b807f 100644
--- a/libgm2/config.h.in
+++ b/libgm2/config.h.in
@@ -335,6 +335,9 @@
 /* Define to 1 if you have the ANSI C header files. */
 #undef STDC_HEADERS
 
+/* Define to 1 if you can safely include both  and . */
+#undef TIME_WITH_SYS_TIME
+
 /* Enable extensions on AIX 3, Interix.  */
 #ifndef _ALL_SOURCE
 # undef _ALL_SOURCE
diff --git a/libgm2/configure b/libgm2/configure
index 13861f0ff93..c36fd7d4cac 100755
--- a/libgm2/configure
+++ b/libgm2/configure
@@ -6837,6 +6837,41 @@ $as_echo "#define HAVE_SYS_WAIT_H 1" >>confdefs.h
 
 fi
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether time.h and 
sys/time.h may both be included" >&5
+$as_echo_n "checking whether time.h and sys/time.h may both be included... " 
>&6; }
+if ${ac_cv_header_time+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include 
+#include 
+#include 
+
+int
+main ()
+{
+if ((struct tm *) 0)
+return 0;
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_header_time=yes
+else
+  ac_cv_header_time=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_time" >&5
+$as_echo "$ac_cv_header_time" >&6; }
+if test $ac_cv_header_time = yes; then
+
+$as_echo "#define TIME_WITH_SYS_TIME 1" >>confdefs.h
+
+fi
+
 ac_fn_c_check_header_mongrel "$LINENO" "math.h" "ac_cv_header_math_h" 
"$ac_includes_default"
 if test "x$ac_cv_header_math_h" = xyes; then :
 
@@ -14544,7 +14579,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 14547 "configure"
+#line 14582 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -14650,7 +14685,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 14653 "configure"
+#line 14688 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
diff --git a/libgm2/configure.ac b/libgm2/configure.ac
index 9563831ddc5..1e6b82305ff 100644
--- a/libgm2/configure.ac
+++ b/libgm2/configure.ac
@@ -88,6 +88,7 @@ AC_ARG_WITH(cross-host,
 # Checks for header files.
 AC_HEADER_STDC
 AC_HEADER_SYS_WAIT
+AC_HEADER_TIME
 AC_CHECK_HEADER([math.h],
   [AC_DEFINE([HAVE_MATH_H], [1], [have math.h])])
 
diff --git a/libgm2/libm2iso/wraptime.cc b/libgm2/libm2iso/wraptime.cc
index 158086b75cc..4bbd5f9701d 100644
--- a/libgm2/libm2iso/wraptime.cc
+++ b/libgm2/libm2iso/wraptime.cc
@@ -113,7 +113,7 @@ EXPORT(KillTimezone) (struct timezone *tv)
 
 /* InitTM - returns a newly created opaque type.  */
 
-#if defined(HAVE_STRUCT_TM) && defined(HAVE_MALLOC_H)
+#if defined(HAVE_SYS_TIME_H) && defined(HAVE_MALLOC_H)
 extern "C" struct tm *
 EXPORT(InitTM) (void)
 {


[gcc r15-1078] modula2: Simplify REAL/LONGREAL/SHORTREAL node creation.

2024-06-06 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:30ce9dfcc665b6088e5898cfa766b57556ebb90e

commit r15-1078-g30ce9dfcc665b6088e5898cfa766b57556ebb90e
Author: Gaius Mulley 
Date:   Thu Jun 6 19:27:56 2024 +0100

modula2: Simplify REAL/LONGREAL/SHORTREAL node creation.

This patch simplifies the real type build functions by using
the default float_type_node, double_type_node rather than create
new nodes.  It also uses the default GCC long_double_type_node
or float128_type_nodes for longreal.

gcc/m2/ChangeLog:

* gm2-gcc/m2type.cc (build_m2_short_real_node): Rewrite
to use the default float_type_node.
(build_m2_real_node): Rewrite to use the default
double_type_node.
(build_m2_long_real_node): Rewrite to use the default
long_double_type_node or float128_type_node.

Co-Authored-By: Kewen.Lin  
Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-gcc/m2type.cc | 30 +++---
 1 file changed, 7 insertions(+), 23 deletions(-)

diff --git a/gcc/m2/gm2-gcc/m2type.cc b/gcc/m2/gm2-gcc/m2type.cc
index 571923c08ef..5773a5cbd19 100644
--- a/gcc/m2/gm2-gcc/m2type.cc
+++ b/gcc/m2/gm2-gcc/m2type.cc
@@ -1415,45 +1415,29 @@ build_m2_char_node (void)
 static tree
 build_m2_short_real_node (void)
 {
-  tree c;
-
-  /* Define `REAL'.  */
-
-  c = make_node (REAL_TYPE);
-  TYPE_PRECISION (c) = FLOAT_TYPE_SIZE;
-  layout_type (c);
-  return c;
+  /* Define `SHORTREAL'.  */
+  ASSERT_CONDITION (TYPE_PRECISION (float_type_node) == FLOAT_TYPE_SIZE);
+  return float_type_node;
 }
 
 static tree
 build_m2_real_node (void)
 {
-  tree c;
-
   /* Define `REAL'.  */
-
-  c = make_node (REAL_TYPE);
-  TYPE_PRECISION (c) = DOUBLE_TYPE_SIZE;
-  layout_type (c);
-  return c;
+  ASSERT_CONDITION (TYPE_PRECISION (double_type_node) == DOUBLE_TYPE_SIZE);  
+  return double_type_node;
 }
 
 static tree
 build_m2_long_real_node (void)
 {
   tree longreal;
-
+  
   /* Define `LONGREAL'.  */
-  if (M2Options_GetIBMLongDouble ())
-{
-  longreal = make_node (REAL_TYPE);
-  TYPE_PRECISION (longreal) = LONG_DOUBLE_TYPE_SIZE;
-}
-  else if (M2Options_GetIEEELongDouble ())
+  if (M2Options_GetIEEELongDouble ())
 longreal = float128_type_node;
   else
 longreal = long_double_type_node;
-  layout_type (longreal);
   return longreal;
 }


[gcc r15-1618] PR modula2/115536 Expression is evaluated incorrectly when encountering relops and indirection

2024-06-25 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:9f168b412f44781013401492acfedf22afe7741b

commit r15-1618-g9f168b412f44781013401492acfedf22afe7741b
Author: Gaius Mulley 
Date:   Tue Jun 25 18:35:22 2024 +0100

PR modula2/115536 Expression is evaluated incorrectly when encountering 
relops and indirection

This fix ensures that we only call BuildRelOpFromBoolean if we are
inside a constant expression (where no indirection can be used).
The fix creates a temporary variable when a boolean is created from
a relop in other cases.
The previous pattern implementation would not work if the operands required
dereferencing during non const expressions.  Comparison of relop results
in a constant expression are resolved by constant propagation, basic
block analysis and dead code removal.  After the quadruples have been
optimized only one assignment to the boolean variable will remain for
const expressions.  All quadruple pattern checking for boolean
expressions is removed by the patch.  Thus the implementation becomes
more generic.

gcc/m2/ChangeLog:

PR modula2/115536
* gm2-compiler/M2BasicBlock.def (GetBasicBlockScope): New procedure.
(GetBasicBlockStart): Ditto.
(GetBasicBlockEnd): Ditto.
(IsBasicBlockFirst): New procedure function.
* gm2-compiler/M2BasicBlock.mod (ConvertQuads2BasicBlock): Allow
conditional boolean quads to be removed.
(GetBasicBlockScope): Implement new procedure.
(GetBasicBlockStart): Ditto.
(GetBasicBlockEnd): Ditto.
(IsBasicBlockFirst): Implement new procedure function.
* gm2-compiler/M2GCCDeclare.def (FoldConstants): New parameter
declaration.
* gm2-compiler/M2GCCDeclare.mod (FoldConstants): New parameter
declaration.
(DeclareTypesConstantsProceduresInRange): Recreate basic blocks
after resolving constant expressions.
(CodeBecomes): Guard IsVariableSSA with IsVar.
* gm2-compiler/M2GenGCC.def (ResolveConstantExpressions): New
parameter declaration.
* gm2-compiler/M2GenGCC.mod (FoldIfLess): Remove relop pattern
detection.
(FoldIfGre): Ditto.
(FoldIfLessEqu): Ditto.
(FoldIfGreEqu): Ditto.
(FoldIfIn): Ditto.
(FoldIfNotIn): Ditto.
(FoldIfEqu): Ditto.
(FoldIfNotEqu): Ditto.
(FoldBecomes): Add BasicBlock parameter and allow conditional
boolean becomes to be folded in the first basic block.
(ResolveConstantExpressions): Reimplement.
* gm2-compiler/M2Quads.def (IsConstQuad): New procedure function.
(IsConditionalBooleanQuad): Ditto.
* gm2-compiler/M2Quads.mod (IsConstQuad): Implement new procedure 
function.
(IsConditionalBooleanQuad): Ditto.
(MoveWithMode): Use GenQuadOTypetok.
(IsInitialisingConst): Rewrite using OpUsesOp1.
(OpUsesOp1): New procedure function.
(doBuildAssignment): Mark des as a VarConditional.
(ConvertBooleanToVariable): Call PutVarConditional.
(DumpQuadSummary): New procedure.
(BuildRelOpFromBoolean): Updated debugging and improved comments.
(BuildRelOp): Only call BuildRelOpFromBoolean if we are in a const
expression and both operands are boolean relops.
(GenQuadOTypeUniquetok): New procedure.
(BackPatch): Correct comment.
* gm2-compiler/SymbolTable.def (PutVarConditional): New procedure.
(IsVarConditional): New procedure function.
* gm2-compiler/SymbolTable.mod (PutVarConditional): Implement new
procedure.
(IsVarConditional): Implement new procedure function.
(SymConstVar): New field IsConditional.
(SymVar): New field IsConditional.
(MakeVar): Initialize IsConditional field.
(MakeConstVar): Initialize IsConditional field.
* gm2-compiler/M2Swig.mod (DoBasicBlock): Change parameters to
use BasicBlock.
* gm2-compiler/M2Code.mod (SecondDeclareAndOptimize): Use iterator
to FoldConstants over basic block list.
* gm2-compiler/M2SymInit.mod (AppendEntry): Replace parameters
with BasicBlock.
* gm2-compiler/P3Build.bnf (Relation): Call RecordOp for #, <> and 
=.

gcc/testsuite/ChangeLog:

PR modula2/115536
* gm2/iso/const/pass/constbool4.mod: New test.
* gm2/iso/const/pass/constbool5.mod: New test.
* gm2/iso/run/pass/condtest2.mod: New test.
* gm2/iso/run/pass/condtest3.mod: New test.
* gm2/iso/run/pass/condtest4.mod: New test.
* gm2/iso/run/pass/condtest5.mod: New test.
* gm2/iso/run/pass/constbool4.

[gcc r15-1623] PR modula2/115540 gcc/m2/mc-boot-ch/Gtermios.cc error return-statement with a value

2024-06-25 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:d16355c72c7f7b54ecf06371d14d7ad309ea4c34

commit r15-1623-gd16355c72c7f7b54ecf06371d14d7ad309ea4c34
Author: Gaius Mulley 
Date:   Tue Jun 25 21:37:44 2024 +0100

PR modula2/115540 gcc/m2/mc-boot-ch/Gtermios.cc error return-statement with 
a value

This patch fixes three occurrences of cfmakeraw use in the hand built
m2 support libraries which incorrectly attempt to return a void
result.

gcc/m2/ChangeLog:

PR modula2/115540
* gm2-libs-ch/termios.c (cfmakeraw): Remove return.
* mc-boot-ch/Gtermios.cc (cfmakeraw): Remove return.
* pge-boot/Gtermios.cc (cfmakeraw): Remove return.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-libs-ch/termios.c  | 2 +-
 gcc/m2/mc-boot-ch/Gtermios.cc | 2 +-
 gcc/m2/pge-boot/Gtermios.cc   | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/m2/gm2-libs-ch/termios.c b/gcc/m2/gm2-libs-ch/termios.c
index 472a4c022e8..fe7403b3dee 100644
--- a/gcc/m2/gm2-libs-ch/termios.c
+++ b/gcc/m2/gm2-libs-ch/termios.c
@@ -281,7 +281,7 @@ int EXPORT (tcsetattr) (int fd, int option, struct termios 
*t)
 void EXPORT (cfmakeraw) (struct termios *t)
 {
 #if defined(HAVE_CFMAKERAW)
-  return cfmakeraw (t);
+  cfmakeraw (t);
 #endif
 }
 
diff --git a/gcc/m2/mc-boot-ch/Gtermios.cc b/gcc/m2/mc-boot-ch/Gtermios.cc
index a11065a6725..0ef5c8ba803 100644
--- a/gcc/m2/mc-boot-ch/Gtermios.cc
+++ b/gcc/m2/mc-boot-ch/Gtermios.cc
@@ -289,7 +289,7 @@ void
 EXPORT (cfmakeraw) (struct termios *t)
 {
 #if defined(HAVE_CFMAKERAW)
-  return cfmakeraw (t);
+  cfmakeraw (t);
 #endif
 }
 
diff --git a/gcc/m2/pge-boot/Gtermios.cc b/gcc/m2/pge-boot/Gtermios.cc
index 4f3557619db..5f966403b19 100644
--- a/gcc/m2/pge-boot/Gtermios.cc
+++ b/gcc/m2/pge-boot/Gtermios.cc
@@ -289,7 +289,7 @@ void
 EXPORT (cfmakeraw) (struct termios *t)
 {
 #if defined(HAVE_CFMAKERAW)
-  return cfmakeraw (t);
+  cfmakeraw (t);
 #endif
 }


[gcc r15-1627] modula2: tidyup remove unused procedures and unused parameters

2024-06-25 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:038144534a683d4248c9b98a7110a59b305f124a

commit r15-1627-g038144534a683d4248c9b98a7110a59b305f124a
Author: Gaius Mulley 
Date:   Tue Jun 25 23:11:29 2024 +0100

modula2: tidyup remove unused procedures and unused parameters

This patch removes M2GenGCC.mod:QuadCondition and
M2Quads.mod:GenQuadOTypeUniquetok.  It also removes unused parameter
WalkAction for all FoldIf procedures.

gcc/m2/ChangeLog:

* gm2-compiler/M2GenGCC.mod (QuadCondition): Remove.
(FoldIfEqu): Remove WalkAction parameter.
(FoldIfNotEqu): Ditto.
(FoldIfGreEqu): Ditto.
(FoldIfLessEqu): Ditto.
(FoldIfGre): Ditto.
(FoldIfLess): Ditto.
(FoldIfIn): Ditto.
(FoldIfNotIn): Ditto.
* gm2-compiler/M2Quads.mod (GenQuadOTypeUniquetok): Remove.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-compiler/M2GenGCC.mod | 77 +---
 gcc/m2/gm2-compiler/M2Quads.mod  | 52 ---
 2 files changed, 16 insertions(+), 113 deletions(-)

diff --git a/gcc/m2/gm2-compiler/M2GenGCC.mod b/gcc/m2/gm2-compiler/M2GenGCC.mod
index c59695a3779..fc3fa204ac0 100644
--- a/gcc/m2/gm2-compiler/M2GenGCC.mod
+++ b/gcc/m2/gm2-compiler/M2GenGCC.mod
@@ -637,14 +637,14 @@ BEGIN
  CastOp : FoldCast (tokenno, p, quad, op1, op2, op3) |
  InclOp : FoldIncl (tokenno, p, quad, op1, op3) |
  ExclOp : FoldExcl (tokenno, p, quad, op1, op3) |
- IfEquOp: FoldIfEqu (tokenno, p, quad, op1, op2, op3) |
- IfNotEquOp : FoldIfNotEqu (tokenno, p, quad, op1, op2, op3) |
- IfLessOp   : FoldIfLess (tokenno, p, quad, op1, op2, op3) |
- IfLessEquOp: FoldIfLessEqu (tokenno, p, quad, op1, op2, op3) |
- IfGreOp: FoldIfGre (tokenno, p, quad, op1, op2, op3) |
- IfGreEquOp : FoldIfGreEqu (tokenno, p, quad, op1, op2, op3) |
- IfInOp : FoldIfIn (tokenno, p, quad, op1, op2, op3) |
- IfNotInOp  : FoldIfNotIn (tokenno, p, quad, op1, op2, op3) |
+ IfEquOp: FoldIfEqu (tokenno, quad, op1, op2, op3) |
+ IfNotEquOp : FoldIfNotEqu (tokenno, quad, op1, op2, op3) |
+ IfLessOp   : FoldIfLess (tokenno, quad, op1, op2, op3) |
+ IfLessEquOp: FoldIfLessEqu (tokenno, quad, op1, op2, op3) |
+ IfGreOp: FoldIfGre (tokenno, quad, op1, op2, op3) |
+ IfGreEquOp : FoldIfGreEqu (tokenno, quad, op1, op2, op3) |
+ IfInOp : FoldIfIn (tokenno, quad, op1, op2, op3) |
+ IfNotInOp  : FoldIfNotIn (tokenno, quad, op1, op2, op3) |
  LogicalShiftOp : FoldSetShift(tokenno, p, quad, op1, op2, op3) |
  LogicalRotateOp: FoldSetRotate (tokenno, p, quad, op1, op2, op3) |
  ParamOp: FoldBuiltinFunction (tokenno, p, quad, op1, op2, 
op3) |
@@ -5332,7 +5332,7 @@ END FoldIncl ;
 if op1 < op2 then goto op3.
 *)
 
-PROCEDURE FoldIfLess (tokenno: CARDINAL; p: WalkAction;
+PROCEDURE FoldIfLess (tokenno: CARDINAL;
   quad: CARDINAL; left, right, destQuad: CARDINAL) ;
 BEGIN
(* Firstly ensure that constant literals are declared.  *)
@@ -5357,57 +5357,12 @@ BEGIN
 END FoldIfLess ;
 
 
-(*
-   QuadCondition - Pre-condition:  left, right operands are constants
-   which have been resolved.
-   Post-condition: return TRUE if the condition at
-   quad is TRUE.
-*)
-
-PROCEDURE QuadCondition (quad: CARDINAL) : BOOLEAN ;
-VAR
-   left, right, dest, combined,
-   leftpos, rightpos, destpos : CARDINAL ;
-   constExpr, overflow: BOOLEAN ;
-   op : QuadOperator ;
-BEGIN
-   GetQuadOtok (quad, combined, op,
-left, right, dest, overflow,
-constExpr,
-leftpos, rightpos, destpos) ;
-   CASE op OF
-
-   IfInOp :  PushValue (right) ;
- RETURN SetIn (left, combined) |
-   IfNotInOp  :  PushValue (right) ;
- RETURN NOT SetIn (left, combined)
-
-   ELSE
-   END ;
-   PushValue (left) ;
-   PushValue (right) ;
-   CASE op OF
-
-   IfGreOp:  RETURN Gre (combined) |
-   IfLessOp   :  RETURN Less (combined) |
-   IfLessEquOp:  RETURN LessEqu (combined) |
-   IfGreEquOp :  RETURN GreEqu (combined) |
-   IfEquOp:  RETURN GreEqu (combined) |
-   IfNotEquOp :  RETURN NotEqu (combined)
-
-   ELSE
-  InternalError ('unrecognized comparison operator')
-   END ;
-   RETURN FALSE
-END QuadCondition ;
-
-
 (*
FoldIfGre - check to see if it is possible to evaluate
if op1 > op2 then goto op3.
 *)
 
-PROCEDURE FoldIfGre (tokenno: CARDINAL; p: WalkAction;
+PROCEDURE FoldIfGre (tokenno: CARDINAL;
  quad: CARDINAL;
  lef

[gcc r15-2876] PR modula2/116181 fix ODR warnings for C/m2 interface library modules

2024-08-11 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:9f3b5c2314239e1d3b6e1722e676ea1935bc2836

commit r15-2876-g9f3b5c2314239e1d3b6e1722e676ea1935bc2836
Author: Gaius Mulley 
Date:   Mon Aug 12 01:27:13 2024 +0100

PR modula2/116181 fix ODR warnings for C/m2 interface library modules

This patch fixes many ODR warnings which appear when compiling the
interface files found in gcc/m2/*-ch/ and gcc/m2/{pge,mc}-boot
directories.

gcc/m2/ChangeLog:

PR modula2/116181
* gm2-compiler/ppg.mod (FindStr): Initialize j.
* gm2-libs-ch/UnixArgs.cc (_M2_UnixArgs_ctor): Replace
M2RTS_RegisterModule with M2RTS_RegisterModule_Cstr.
* gm2-libs-ch/dtoa.cc (_M2_dtoa_ctor): Ditto.
* gm2-libs-ch/ldtoa.cc (ldtoa_strtold): Cast parameter s
for strtod.
(_M2_ldtoa_ctor): Replace M2RTS_RegisterModule with
M2RTS_RegisterModule_Cstr.
* gm2-libs-ch/m2rts.h (M2RTS_RegisterModule_Cstr): New
define.
(M2RTS_RegisterModule): Remove const.
* mc-boot-ch/GSelective.c (Selective_FdIsSet): Return bool
rather than int.
* mc-boot-ch/Gldtoa.cc (ldtoa_strtold): Change const char to
void.
Cast s before passing as a parameter to strtod.
* mc-boot-ch/Glibc.c (tracedb_open): Replace const char with const
void.
(libc_perror): Replace char with const char.
(libc_printf): Replace char with void.
(libc_snprintf): Replace char with void.
Add const_cast for parameter to index.
Add reinterpret_cast for parameter to vsnprintf.
(libc_open): Replace first paramter type char with void.
Add vararg for the third parameter.
* mc-boot-ch/Gm2rtsdummy.cc (M2RTS_RequestDependant): Remove #if 0 
code.
(m2pim_M2RTS_RegisterModule): Change const char parameters to void
(M2RTS_RegisterModule): Ditto.
(_M2_M2RTS_init): Remove #if 0 code.
(M2RTS_ConstructModules): Ditto.
(M2RTS_Terminate): Ditto.
(M2RTS_DeconstructModules): Ditto.
(M2RTS_Halt): Ditto.
* mc-boot-ch/Gtermios.cc (SetFlag): Return bool.
* mc-boot-ch/m2rts.h (M2RTS_RegisterModule_Cstr): New define.
(M2RTS_RegisterModule): Change const char parameters to void.
* mc-boot/Gdecl.cc: Regenerate.
* mc/decl.mod (getNextConstExp): Reimplement.
* pge-boot/GDynamicStrings.cc: Regenerate.
* pge-boot/GDynamicStrings.h: Ditto.
* pge-boot/GM2RTS.h (M2RTS_RegisterModule_Cstr): New function.
(M2RTS_RegisterModule): Reformat.
* pge-boot/GSymbolKey.cc: Regenerate.
* pge-boot/GSysExceptions.cc (_M2_SysExceptions_init): Add correct 
parameters.
(_M2_SysExceptions_fini): Ditto.
* pge-boot/GUnixArgs.cc (_M2_UnixArgs_ctor::_M2_UnixArgs_ctor):
Replace call to M2RTS_RegisterModule with M2RTS_RegisterModuleCstr.
* pge-boot/Gerrno.cc (_M2_errno_init): Add correct parameters.
(_M2_errno_fini): Ditto.
* pge-boot/Gldtoa.cc (ldtoa_strtold): Replace const char with
void.
Use reinterpret_cast when passing s to strtod.
Replace true with TRUE.
* pge-boot/Gldtoa.h (ldtoa_strtold): Tidy up.
* pge-boot/Glibc.cc (libc_read): Use size_t as the return type.
(libc_write): Ditto.
(libc_strlen): Ditto.
(libc_perror): Replace char with const char.
(libc_printf): Replace char to const char.
Cast parameter to index using const_cast.
(libc_snprintf): Replace char with void.
Cast parameter to index using const_cast.
(libc_malloc): Replace parameter type with size_t.
(libc_memcpy): Replace third parameter type with size_t.
(libc_open): Use varargs.
* pge-boot/Glibc.h (libc_perror): Add _string_high parameter.
* pge-boot/Gpge.cc: Regenerate.
* pge-boot/Gtermios.cc (SetFlag): Replace return type with bool.
(_M2_termios_init): Add correct parameters.
(_M2_termios_fini): Ditto.
* pge-boot/m2rts.h (M2RTS_RegisterModule_Cstr): New define.
(M2RTS_RegisterModule): Replace const char with void.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-compiler/ppg.mod|   1 +
 gcc/m2/gm2-libs-ch/UnixArgs.cc |   4 +-
 gcc/m2/gm2-libs-ch/dtoa.cc |   4 +-
 gcc/m2/gm2-libs-ch/ldtoa.cc|  10 +-
 gcc/m2/gm2-libs-ch/m2rts.h |   7 +-
 gcc/m2/mc-boot-ch/GSelective.c |   2 +-
 gcc/m2/mc-boot-ch/Gldtoa.cc|   8 +-
 gcc/m2/mc-boot-ch/Glibc.c  |  22 +-
 gcc/m2/mc-boot-ch/Gm2rtsdummy.cc   |  25 +-
 gcc/m2/mc-boot-ch/Gtermios.cc  |   4 +-
 gcc/m2/mc-boot-ch/m2rts.h

[gcc r15-2949] PR modula2/116378 m2 bootstrap fails on x86_64-darwin

2024-08-16 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:9cdde72d1cefdf252ad2eec1ff465dccb3ab

commit r15-2949-g9cdde72d1cefdf252ad2eec1ff465dccb3ab
Author: Gaius Mulley 
Date:   Fri Aug 16 12:41:11 2024 +0100

PR modula2/116378 m2 bootstrap fails on x86_64-darwin

This patch fixes m2 bootstrap failure on x86_64-darwin.  libc_open
is defined with three parameters the last of which is an int for
portability (rather than a vararg).  This avoids portability
problems by promoting mode_t to an int.  In the future it could
be tidied up by using the m2 optarg extension.

gcc/m2/ChangeLog:

PR modula2/116378
* gm2-libs-iso/TermFile.mod (termOpen): Add third argument
for open.
* gm2-libs/libc.def (open): Remove vararg and use INTEGER for
mode parameter three.
* mc-boot-ch/Glibc.c (tracedb_open): Replace mode_t with int.
(libc_open): Rewrite without varargs.
* mc-boot/Glibc.h (libc_open): Replace varargs with int mode.
* pge-boot/Glibc.cc (libc_open): Rewrite.
* pge-boot/Glibc.h (libc_open): Replace varargs with int mode.

gcc/testsuite/ChangeLog:

PR modula2/116378
* gm2/extensions/run/pass/testopen.mod: Add third argument
for open.
* gm2/isolib/run/pass/openlibc.mod: Ditto.
* gm2/pim/run/pass/testaddr3.mod: Ditto.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-libs-iso/TermFile.mod   | 2 +-
 gcc/m2/gm2-libs/libc.def   | 2 +-
 gcc/m2/mc-boot-ch/Glibc.c  | 8 ++--
 gcc/m2/mc-boot/Glibc.h | 2 +-
 gcc/m2/pge-boot/Glibc.cc   | 9 ++---
 gcc/m2/pge-boot/Glibc.h| 2 +-
 gcc/testsuite/gm2/extensions/run/pass/testopen.mod | 2 +-
 gcc/testsuite/gm2/isolib/run/pass/openlibc.mod | 2 +-
 gcc/testsuite/gm2/pim/run/pass/testaddr3.mod   | 2 +-
 9 files changed, 11 insertions(+), 20 deletions(-)

diff --git a/gcc/m2/gm2-libs-iso/TermFile.mod b/gcc/m2/gm2-libs-iso/TermFile.mod
index a3ad58ceba0..3347bdd4e86 100644
--- a/gcc/m2/gm2-libs-iso/TermFile.mod
+++ b/gcc/m2/gm2-libs-iso/TermFile.mod
@@ -503,7 +503,7 @@ BEGIN
   THEN
  fd := libc.open(ADR("/dev/tty"), O_WRONLY, 0600B)
   ELSE
- fd := libc.open(ADR("/dev/tty"), O_RDONLY)
+ fd := libc.open(ADR("/dev/tty"), O_RDONLY, 0)
   END ;
   IF tcgetattr(fd, new)=0
   THEN
diff --git a/gcc/m2/gm2-libs/libc.def b/gcc/m2/gm2-libs/libc.def
index f28f8b5f2bc..a314b59e43f 100644
--- a/gcc/m2/gm2-libs/libc.def
+++ b/gcc/m2/gm2-libs/libc.def
@@ -211,7 +211,7 @@ PROCEDURE close (d: INTEGER) : [ INTEGER ] ;
open - open the file, filename with flag and mode.
 *)
 
-PROCEDURE open (filename: ADDRESS; oflag: INTEGER; ...) : INTEGER ;
+PROCEDURE open (filename: ADDRESS; oflag: INTEGER; mode: INTEGER) : INTEGER ;
 
 
 (*
diff --git a/gcc/m2/mc-boot-ch/Glibc.c b/gcc/m2/mc-boot-ch/Glibc.c
index 492f17f6bdc..5ad1711bc64 100644
--- a/gcc/m2/mc-boot-ch/Glibc.c
+++ b/gcc/m2/mc-boot-ch/Glibc.c
@@ -67,7 +67,7 @@ tracedb (const char *format, ...)
 
 static
 void
-tracedb_open (const void *p, int flags, mode_t mode)
+tracedb_open (const void *p, int flags, int mode)
 {
 #if defined(BUILD_MC_LIBC_TRACE)
   bool item_written = false;
@@ -343,15 +343,11 @@ libc_creat (char *p, mode_t mode)
 
 EXTERN
 int
-libc_open (void *p, int oflag, ...)
+libc_open (void *p, int oflag, int mode)
 {
-  va_list arg;
-  va_start (arg, oflag);
-  mode_t mode = va_arg (arg, mode_t);
   tracedb_open (p, oflag, mode);
   int result = open (reinterpret_cast  (p), oflag, mode);
   tracedb_result (result);
-  va_end (arg);
   return result;
 }
 
diff --git a/gcc/m2/mc-boot/Glibc.h b/gcc/m2/mc-boot/Glibc.h
index 2f7fac46d77..957232345f5 100644
--- a/gcc/m2/mc-boot/Glibc.h
+++ b/gcc/m2/mc-boot/Glibc.h
@@ -178,7 +178,7 @@ EXTERN int libc_close (int d);
open - open the file, filename with flag and mode.
 */
 
-EXTERN int libc_open (void * filename, int oflag, ...);
+EXTERN int libc_open (void * filename, int oflag, int mode);
 
 /*
creat - creates a new file
diff --git a/gcc/m2/pge-boot/Glibc.cc b/gcc/m2/pge-boot/Glibc.cc
index a63b328ed60..7ea40d0f0c1 100644
--- a/gcc/m2/pge-boot/Glibc.cc
+++ b/gcc/m2/pge-boot/Glibc.cc
@@ -224,14 +224,9 @@ libc_creat (char *p, mode_t mode)
 
 EXTERN
 int
-libc_open (void *p, int oflag, ...)
+libc_open (void *p, int oflag, int mode)
 {
-  va_list arg;
-  va_start (arg, oflag);
-  mode_t mode = va_arg (arg, mode_t);
-  int result = open (reinterpret_cast  (p), oflag, mode);
-  va_end (arg);
-  return result;
+  return open (reinterpret_cast  (p), oflag, mode);
 }
 
 EXTERN
diff --git a/gcc/m2/pge-boot/Glibc.h b/gcc/m2/pge-boot/Glibc.h
index a5558932348..0a5481ef523 100644
--- a/gcc/m2/pge-boot/Glibc.h
+++ b/gcc/m2/pge-boot/Glibc.h
@@ -178,7 +178,7 @@ EXTERN int libc_close (int d);

[gcc r15-2953] Fix using keywords as identifiers to prevent warnings during build

2024-08-16 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:6738e9afa36a82a59869ced03a759a3a9e5a81b6

commit r15-2953-g6738e9afa36a82a59869ced03a759a3a9e5a81b6
Author: Gaius Mulley 
Date:   Fri Aug 16 16:09:53 2024 +0100

Fix using keywords as identifiers to prevent warnings during build

m2pim/DynamicStrings.mod:1358:27: note: In procedure ‘Slice’: the symbol
name ‘end’ is legal as an identifier, however as such it might cause
confusion and is considered bad programming practice
 1358 |start, end, o: INTEGER ;

m2pim/DynamicStrings.mod:1358:27: note: either the identifier has the
same name as a keyword or alternatively a keyword has the wrong case
(‘END’ and ‘end’).

gcc/m2/ChangeLog:

* gm2-libs/DynamicStrings.mod (Slice): Rename end to stop.

Signed-off-by: Wilken Gottwalt 

Diff:
---
 gcc/m2/gm2-libs/DynamicStrings.mod | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/gcc/m2/gm2-libs/DynamicStrings.mod 
b/gcc/m2/gm2-libs/DynamicStrings.mod
index b53f0f285b5..982284d3629 100644
--- a/gcc/m2/gm2-libs/DynamicStrings.mod
+++ b/gcc/m2/gm2-libs/DynamicStrings.mod
@@ -1354,8 +1354,8 @@ END Mult ;
 
 PROCEDURE Slice (s: String; low, high: INTEGER) : String ;
 VAR
-   d, t : String ;
-   start, end, o: INTEGER ;
+   d, t  : String ;
+   start, stop, o: INTEGER ;
 BEGIN
IF PoisonOn
THEN
@@ -1390,7 +1390,7 @@ BEGIN
 ELSE
start := low - o
 END ;
-end := Max (Min (MaxBuf, high - o), 0) ;
+stop := Max (Min (MaxBuf, high - o), 0) ;
 WHILE t^.contents.len = MaxBuf DO
IF t^.contents.next = NIL
THEN
@@ -1408,7 +1408,7 @@ BEGIN
t := t^.contents.next
 END ;
 ConcatContentsAddress (t^.contents,
-   ADR (s^.contents.buf[start]), end - start) ;
+   ADR (s^.contents.buf[start]), stop - start) 
;
 INC (o, s^.contents.len) ;
 s := s^.contents.next
  END


[gcc r15-2954] modula2: change identifier names to avoid build warnings

2024-08-16 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:b584f387bf74df9ba2cbbc07d00a05a105757329

commit r15-2954-gb584f387bf74df9ba2cbbc07d00a05a105757329
Author: Gaius Mulley 
Date:   Fri Aug 16 16:28:55 2024 +0100

modula2: change identifier names to avoid build warnings

This fix avoids the following warnings: In implementation module
‘StdChans’: either the identifier has the same name as a keyword or
alternatively a keyword has the wrong case (‘IN’ and ‘in’)
   54 |stdnull: ChanId ;

the symbol name ‘in’ is legal as an identifier, however as such it
might cause confusion and is considered bad programming practice.

gcc/m2/ChangeLog:

* gm2-libs-iso/StdChans.mod (in): Rename to ...
(inch): ... this.
(out): Rename to ...
(outch): ... this.
(err): Rename to ...
(errch): ... this.

Signed-off-by: Wilken Gottwalt 

Diff:
---
 gcc/m2/gm2-libs-iso/StdChans.mod | 24 
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/gcc/m2/gm2-libs-iso/StdChans.mod b/gcc/m2/gm2-libs-iso/StdChans.mod
index fbefbde4b10..e15d4ef9580 100644
--- a/gcc/m2/gm2-libs-iso/StdChans.mod
+++ b/gcc/m2/gm2-libs-iso/StdChans.mod
@@ -45,9 +45,9 @@ FROM RTgen IMPORT ChanDev, DeviceType,
 
 
 VAR
-   in,
-   out,
-   err,
+   inch,
+   outch,
+   errch,
stdin,
stdout,
stderr,
@@ -169,21 +169,21 @@ END NullChan ;
 PROCEDURE InChan () : ChanId ;
   (* Returns the identity of the current default input channel. *)
 BEGIN
-   RETURN( in )
+   RETURN( inch )
 END InChan ;
 
 
 PROCEDURE OutChan () : ChanId ;
   (* Returns the identity of the current default output channel. *)
 BEGIN
-   RETURN( out )
+   RETURN( outch )
 END OutChan ;
 
 
 PROCEDURE ErrChan () : ChanId ;
   (* Returns the identity of the current default error message channel. *)
 BEGIN
-   RETURN( err )
+   RETURN( errch )
 END ErrChan ;
 
   (* The following procedures allow for redirection of the default channels *)
@@ -191,21 +191,21 @@ END ErrChan ;
 PROCEDURE SetInChan (cid: ChanId) ;
   (* Sets the current default input channel to that identified by cid. *)
 BEGIN
-   in := cid
+   inch := cid
 END SetInChan ;
 
 
 PROCEDURE SetOutChan (cid: ChanId) ;
   (* Sets the current default output channel to that identified by cid. *)
 BEGIN
-   out := cid
+   outch := cid
 END SetOutChan ;
 
 
 PROCEDURE SetErrChan (cid: ChanId) ;
   (* Sets the current default error channel to that identified by cid. *)
 BEGIN
-   err := cid
+   errch := cid
 END SetErrChan ;
 
 
@@ -303,9 +303,9 @@ END Init ;
 BEGIN
Init
 FINALLY
-   SafeClose(in) ;
-   SafeClose(out) ;
-   SafeClose(err) ;
+   SafeClose(inch) ;
+   SafeClose(outch) ;
+   SafeClose(errch) ;
SafeClose(stdin) ;
SafeClose(stdout) ;
SafeClose(stderr)


[gcc r15-122] PR modula2/114929 for loop fails to iterate down to zero when using a cardinal type

2024-05-02 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:a561dc0f6c7085e102fe9e9b6abd7f2138512576

commit r15-122-ga561dc0f6c7085e102fe9e9b6abd7f2138512576
Author: Gaius Mulley 
Date:   Fri May 3 01:22:10 2024 +0100

PR modula2/114929 for loop fails to iterate down to zero when using a 
cardinal type

There is a bug in the for loop control code which is exposed when an
unsigned type is used in the iterator variable.  See
gm2/pim/run/pass/testforloopzero[234].mod.  The bug is in the
calculation of the last iterator value.  The bug fix is to avoid using
negative expressions when calculating the last iterator value with a
negative step value.  This patch detects if e1, e2, step value are all
constant, in which case the ztype is used internally and there is no
overflow.  If the last iterator value is held in a variable then it
uses a different method to calculate the last iterator depending upon
the sign of the step value.

gcc/m2/ChangeLog:

PR modula2/114929
* gm2-compiler/M2LangDump.mod (GenQualidentSymString): Add
missing return result into identstr.
* gm2-compiler/M2Quads.mod (ForLoopLastIteratorVariable): New
procedure.
(ForLoopLastIteratorConstant): Ditto.
(ForLoopLastIterator): Ditto.
(BuildForToByDo): Remove LastIterator calculation and call
ForLoopLastIterator instead.
(FinalValue): Replace with ...
(LastIterator): ... this.

gcc/testsuite/ChangeLog:

PR modula2/114929
* gm2/pim/run/pass/testforloopzero.mod: New test.
* gm2/pim/run/pass/testforloopzero2.mod: New test.
* gm2/pim/run/pass/testforloopzero3.mod: New test.
* gm2/pim/run/pass/testforloopzero4.mod: New test.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-compiler/M2LangDump.mod |   2 +-
 gcc/m2/gm2-compiler/M2Quads.mod| 191 +
 gcc/testsuite/gm2/pim/run/pass/testforloopzero.mod |  33 
 .../gm2/pim/run/pass/testforloopzero2.mod  |  35 
 .../gm2/pim/run/pass/testforloopzero3.mod  |  32 
 .../gm2/pim/run/pass/testforloopzero4.mod  |  32 
 6 files changed, 290 insertions(+), 35 deletions(-)

diff --git a/gcc/m2/gm2-compiler/M2LangDump.mod 
b/gcc/m2/gm2-compiler/M2LangDump.mod
index e65f5b040a5..2ce77a03d14 100644
--- a/gcc/m2/gm2-compiler/M2LangDump.mod
+++ b/gcc/m2/gm2-compiler/M2LangDump.mod
@@ -260,7 +260,7 @@ BEGIN
WHILE GetScope (sym) # NulSym DO
   sym := GetScope (sym) ;
   identstr := InitStringCharStar (KeyToCharStar (GetSymName (sym))) ;
-  ConCatChar (identstr, '.') ;
+  identstr := ConCatChar (identstr, '.') ;
   qualidentstr := ConCat (identstr, Mark (qualidentstr))
END ;
RETURN qualidentstr
diff --git a/gcc/m2/gm2-compiler/M2Quads.mod b/gcc/m2/gm2-compiler/M2Quads.mod
index 8a9a23013b2..3f414e186b2 100644
--- a/gcc/m2/gm2-compiler/M2Quads.mod
+++ b/gcc/m2/gm2-compiler/M2Quads.mod
@@ -4583,6 +4583,144 @@ BEGIN
 END BuildForLoopToRangeCheck ;
 
 
+(*
+   ForLoopLastIteratorVariable - assigns the last value of the index variable 
to
+ symbol LastIterator.
+ The For Loop is regarded:
+
+ For ident := e1 To e2 By BySym Do
+
+ End
+*)
+
+PROCEDURE ForLoopLastIteratorVariable (LastIterator, e1, e2, BySym, ByType: 
CARDINAL ;
+   e1tok, e2tok, bytok: CARDINAL) ;
+VAR
+   PBType,
+   PositiveBy,
+   ElseQuad,
+   t, f  : CARDINAL ;
+BEGIN
+   Assert (IsVar (LastIterator)) ;
+   (* If By > 0 then.  *)
+   (* q+1 if >=  by0  q+3.  *)
+   (* q+2 GotoOp  q+else.   *)
+   PushTFtok (BySym, ByType, bytok) ;  (* BuildRelOp  1st parameter *)
+   PushT (GreaterEqualTok) ;   (* 2nd parameter *)
+   (* 3rd parameter *)
+   PushZero (bytok, ByType) ;
+   BuildRelOp (e2tok) ;   (* Choose final expression position.  *)
+   PopBool (t, f) ;
+   BackPatch (t, NextQuad) ;
+
+   (* LastIterator := ((e2-e1) DIV By) * By + e1.  *)
+   PushTF (LastIterator, GetSType (LastIterator)) ;
+   PushTFtok (e2, GetSType (e2), e2tok) ;
+   PushT (MinusTok) ;
+   PushTFtok (e1, GetSType (e1), e1tok) ;
+   doBuildBinaryOp (TRUE, FALSE) ;
+   PushT (DivideTok) ;
+   PushTFtok (BySym, ByType, bytok) ;
+   doBuildBinaryOp (FALSE, FALSE) ;
+   PushT (TimesTok) ;
+   PushTFtok (BySym, ByType, bytok) ;
+   doBuildBinaryOp (FALSE, FALSE) ;
+   PushT (ArithPlusTok) ;
+   PushTFtok (e1, GetSType (e1), e1tok) ;
+   doBuildBinaryOp (FALSE, FALSE) ;
+   BuildForLoopToRangeCheck ;
+   BuildAssignmentWithoutBounds (e1tok, FALSE, FALSE) ;
+   GenQuad (GotoOp, NulSym, NulSym, 0) ;
+   ElseQuad := NextQuad-1 ;
+
+   (* Else.  *)
+
+   BackPatch (f, NextQuad) ;
+
+   PushTtok

[gcc r15-137] PR modula2/114929 extra for loop iteration count regression tests

2024-05-03 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:c943d7b5c40f447b12431df9ad27a47dad95026d

commit r15-137-gc943d7b5c40f447b12431df9ad27a47dad95026d
Author: Gaius Mulley 
Date:   Fri May 3 20:48:01 2024 +0100

PR modula2/114929 extra for loop iteration count regression tests

This patch introduces three more for loop tests checking the iteration
count using the CHAR and enumeration data types.

gcc/testsuite/ChangeLog:

PR modula2/114929
* gm2/pim/run/pass/testforloopchar.mod: New test.
* gm2/pim/run/pass/testforloopchar2.mod: New test.
* gm2/pim/run/pass/testforloopenum.mod: New test.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/testsuite/gm2/pim/run/pass/testforloopchar.mod | 27 +++
 .../gm2/pim/run/pass/testforloopchar2.mod  | 27 +++
 gcc/testsuite/gm2/pim/run/pass/testforloopenum.mod | 30 ++
 3 files changed, 84 insertions(+)

diff --git a/gcc/testsuite/gm2/pim/run/pass/testforloopchar.mod 
b/gcc/testsuite/gm2/pim/run/pass/testforloopchar.mod
new file mode 100644
index 000..be26ecb7149
--- /dev/null
+++ b/gcc/testsuite/gm2/pim/run/pass/testforloopchar.mod
@@ -0,0 +1,27 @@
+MODULE testforloopchar ;
+
+FROM libc IMPORT printf, exit ;
+
+PROCEDURE test ;
+VAR
+   ch   : CHAR ;
+   count: CARDINAL ;
+BEGIN
+   count := 0 ;
+   FOR ch := 'a' TO 'z' DO
+  INC (count) ;
+  printf ("ch = %c, count = %d\n", ch, count)
+   END ;
+   IF count = 26
+   THEN
+  printf ("passed\n")
+   ELSE
+  printf ("failed\n") ;
+  exit (1)
+   END
+END test ;
+
+
+BEGIN
+   test
+END testforloopchar.
diff --git a/gcc/testsuite/gm2/pim/run/pass/testforloopchar2.mod 
b/gcc/testsuite/gm2/pim/run/pass/testforloopchar2.mod
new file mode 100644
index 000..05478b2d5f2
--- /dev/null
+++ b/gcc/testsuite/gm2/pim/run/pass/testforloopchar2.mod
@@ -0,0 +1,27 @@
+MODULE testforloopchar2 ;
+
+FROM libc IMPORT printf, exit ;
+
+PROCEDURE test ;
+VAR
+   ch   : CHAR ;
+   count: CARDINAL ;
+BEGIN
+   count := 0 ;
+   FOR ch := 'a' TO 'z' BY CHR (2) DO
+  INC (count) ;
+  printf ("ch = %c, count = %d\n", ch, count)
+   END ;
+   IF count = 13
+   THEN
+  printf ("passed\n")
+   ELSE
+  printf ("failed\n") ;
+  exit (1)
+   END
+END test ;
+
+
+BEGIN
+   test
+END testforloopchar2.
diff --git a/gcc/testsuite/gm2/pim/run/pass/testforloopenum.mod 
b/gcc/testsuite/gm2/pim/run/pass/testforloopenum.mod
new file mode 100644
index 000..3855cae0012
--- /dev/null
+++ b/gcc/testsuite/gm2/pim/run/pass/testforloopenum.mod
@@ -0,0 +1,30 @@
+MODULE testforloopenum ;
+
+FROM libc IMPORT printf, exit ;
+
+TYPE
+   colour = (red, green, blue, yellow) ;
+
+PROCEDURE test ;
+VAR
+   c: colour ;
+   count: CARDINAL ;
+BEGIN
+   count := 0 ;
+   FOR c := red TO blue BY colour (2) DO
+  INC (count) ;
+  printf ("c = %d, count = %d\n", c, count)
+   END ;
+   IF count = 2
+   THEN
+  printf ("passed\n")
+   ELSE
+  printf ("failed\n") ;
+  exit (1)
+   END
+END test ;
+
+
+BEGIN
+   test
+END testforloopenum.


[gcc r14-10166] [PATCH] PR modula2/114929 for loop fails to iterate down to zero

2024-05-03 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:d811080341adf9d805e3f79a8fd9be2e13bd9848

commit r14-10166-gd811080341adf9d805e3f79a8fd9be2e13bd9848
Author: Gaius Mulley 
Date:   Fri May 3 22:58:11 2024 +0100

[PATCH] PR modula2/114929 for loop fails to iterate down to zero

There is a bug in the for loop control code which is exposed when an
unsigned type is used in the iterator variable.  See
gm2/pim/run/pass/testforloopzero[234].mod.  The bug is in the
calculation of the last iterator value.  The bug fix is to avoid using
negative expressions when calculating the last iterator value with a
negative step value.  This patch detects if e1, e2, step value are all
constant, in which case the ztype is used internally and there is no
overflow.  If the last iterator value is held in a variable then it
uses a different method to calculate the last iterator depending upon
the sign of the step value.

gcc/m2/ChangeLog:

PR modula2/114929
* gm2-compiler/M2Quads.mod (ForLoopLastIteratorVariable): New
procedure.
(ForLoopLastIteratorConstant): Ditto.
(ForLoopLastIterator): Ditto.
(BuildForToByDo): Remove LastIterator calculation and call
ForLoopLastIterator instead.
(FinalValue): Replace with ...
(LastIterator): ... this.

gcc/testsuite/ChangeLog:

PR modula2/114929
* gm2/pim/run/pass/testforloopzero.mod: New test.
* gm2/pim/run/pass/testforloopzero2.mod: New test.
* gm2/pim/run/pass/testforloopzero3.mod: New test.
* gm2/pim/run/pass/testforloopzero4.mod: New test.

(cherry picked from commit a561dc0f6c7085e102fe9e9b6abd7f2138512576)

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-compiler/M2Quads.mod| 191 +
 gcc/testsuite/gm2/pim/run/pass/testforloopzero.mod |  33 
 .../gm2/pim/run/pass/testforloopzero2.mod  |  35 
 .../gm2/pim/run/pass/testforloopzero3.mod  |  32 
 .../gm2/pim/run/pass/testforloopzero4.mod  |  32 
 5 files changed, 289 insertions(+), 34 deletions(-)

diff --git a/gcc/m2/gm2-compiler/M2Quads.mod b/gcc/m2/gm2-compiler/M2Quads.mod
index 8a9a23013b2..3f414e186b2 100644
--- a/gcc/m2/gm2-compiler/M2Quads.mod
+++ b/gcc/m2/gm2-compiler/M2Quads.mod
@@ -4583,6 +4583,144 @@ BEGIN
 END BuildForLoopToRangeCheck ;
 
 
+(*
+   ForLoopLastIteratorVariable - assigns the last value of the index variable 
to
+ symbol LastIterator.
+ The For Loop is regarded:
+
+ For ident := e1 To e2 By BySym Do
+
+ End
+*)
+
+PROCEDURE ForLoopLastIteratorVariable (LastIterator, e1, e2, BySym, ByType: 
CARDINAL ;
+   e1tok, e2tok, bytok: CARDINAL) ;
+VAR
+   PBType,
+   PositiveBy,
+   ElseQuad,
+   t, f  : CARDINAL ;
+BEGIN
+   Assert (IsVar (LastIterator)) ;
+   (* If By > 0 then.  *)
+   (* q+1 if >=  by0  q+3.  *)
+   (* q+2 GotoOp  q+else.   *)
+   PushTFtok (BySym, ByType, bytok) ;  (* BuildRelOp  1st parameter *)
+   PushT (GreaterEqualTok) ;   (* 2nd parameter *)
+   (* 3rd parameter *)
+   PushZero (bytok, ByType) ;
+   BuildRelOp (e2tok) ;   (* Choose final expression position.  *)
+   PopBool (t, f) ;
+   BackPatch (t, NextQuad) ;
+
+   (* LastIterator := ((e2-e1) DIV By) * By + e1.  *)
+   PushTF (LastIterator, GetSType (LastIterator)) ;
+   PushTFtok (e2, GetSType (e2), e2tok) ;
+   PushT (MinusTok) ;
+   PushTFtok (e1, GetSType (e1), e1tok) ;
+   doBuildBinaryOp (TRUE, FALSE) ;
+   PushT (DivideTok) ;
+   PushTFtok (BySym, ByType, bytok) ;
+   doBuildBinaryOp (FALSE, FALSE) ;
+   PushT (TimesTok) ;
+   PushTFtok (BySym, ByType, bytok) ;
+   doBuildBinaryOp (FALSE, FALSE) ;
+   PushT (ArithPlusTok) ;
+   PushTFtok (e1, GetSType (e1), e1tok) ;
+   doBuildBinaryOp (FALSE, FALSE) ;
+   BuildForLoopToRangeCheck ;
+   BuildAssignmentWithoutBounds (e1tok, FALSE, FALSE) ;
+   GenQuad (GotoOp, NulSym, NulSym, 0) ;
+   ElseQuad := NextQuad-1 ;
+
+   (* Else.  *)
+
+   BackPatch (f, NextQuad) ;
+
+   PushTtok (MinusTok, bytok) ;
+   PushTFtok (BySym, ByType, bytok) ;
+   BuildUnaryOp ;
+   PopTF (PositiveBy, PBType) ;  (* PositiveBy := - BySym.  *)
+
+   (* LastIterator := e1 - ((e1-e2) DIV PositiveBy) * PositiveBy.  *)
+   PushTF (LastIterator, GetSType (LastIterator)) ;
+   PushTFtok (e1, GetSType (e1), e1tok) ;
+   PushT (MinusTok) ;
+   PushTFtok (e1, GetSType (e1), e1tok) ;
+   PushT (MinusTok) ;
+   PushTFtok (e2, GetSType (e2), e2tok) ;
+   doBuildBinaryOp (TRUE, FALSE) ;
+   PushT (DivideTok) ;
+   PushTFtok (PositiveBy, ByType, bytok) ;
+   doBuildBinaryOp (FALSE, FALSE) ;
+   PushT (TimesTok) ;
+   PushTFtok (PositiveBy, ByType, bytok) ;
+   doBuildBinaryOp (FAL

[gcc r15-300] PR modula2/114133 bugfix constants must be cast prior to vararg call

2024-05-07 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:76e591200f54226290ddb49b8ac6231a694bf882

commit r15-300-g76e591200f54226290ddb49b8ac6231a694bf882
Author: Gaius Mulley 
Date:   Tue May 7 19:24:08 2024 +0100

PR modula2/114133 bugfix constants must be cast prior to vararg call

This bug fix corrects the test codes below by converting the constant
literals to the type required by C.  In the testcases below the values, 1
etc were converted into the INTEGER type before being passed to a C
vararg function.  By default in modula2 constant literal ordinals are
represented as the ZTYPE (the largest GCC integer type node).

gcc/testsuite/ChangeLog:

PR modula2/114133
* gm2/extensions/run/pass/callingc10.mod: Convert constant
literal numbers into INTEGER.
* gm2/extensions/run/pass/callingc11.mod: Ditto.
* gm2/extensions/run/pass/vararg2.mod: Ditto.
* gm2/iso/run/pass/packed.mod: Emit a printf as a runtime
diagnostic.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/testsuite/gm2/extensions/run/pass/callingc10.mod | 6 +++---
 gcc/testsuite/gm2/extensions/run/pass/callingc11.mod | 6 +++---
 gcc/testsuite/gm2/extensions/run/pass/vararg2.mod| 6 +++---
 gcc/testsuite/gm2/iso/run/pass/packed.mod| 2 ++
 4 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/gcc/testsuite/gm2/extensions/run/pass/callingc10.mod 
b/gcc/testsuite/gm2/extensions/run/pass/callingc10.mod
index 3a2d3e210dcc..0c26fedf8453 100644
--- a/gcc/testsuite/gm2/extensions/run/pass/callingc10.mod
+++ b/gcc/testsuite/gm2/extensions/run/pass/callingc10.mod
@@ -4,13 +4,13 @@ FROM cvararg IMPORT funcptr ;
 FROM SYSTEM IMPORT ADR ;
 
 BEGIN
-   IF funcptr (1, "hello", 5) = 1
+   IF funcptr (INTEGER (1), "hello", INTEGER (5)) = INTEGER (1)
THEN
END ;
-   IF funcptr (1, "hello" + " ", 6) = 1
+   IF funcptr (INTEGER (1), "hello" + " ", INTEGER (6)) = INTEGER (1)
THEN
END ;
-   IF funcptr (1, "hello" + " " + "world", 11) = 1
+   IF funcptr (INTEGER (1), "hello" + " " + "world", INTEGER (11)) = INTEGER 
(1)
THEN
END
 END callingc10.
diff --git a/gcc/testsuite/gm2/extensions/run/pass/callingc11.mod 
b/gcc/testsuite/gm2/extensions/run/pass/callingc11.mod
index 9b8cb82d645f..d71026ee35df 100644
--- a/gcc/testsuite/gm2/extensions/run/pass/callingc11.mod
+++ b/gcc/testsuite/gm2/extensions/run/pass/callingc11.mod
@@ -5,13 +5,13 @@ FROM SYSTEM IMPORT ADR ;
 FROM strconst IMPORT WORLD ;
 
 BEGIN
-   IF funcptr (1, "hello", 5) = 1
+   IF funcptr (INTEGER (1), "hello", INTEGER (5)) = INTEGER (1)
THEN
END ;
-   IF funcptr (1, "hello" + " ", 6) = 1
+   IF funcptr (INTEGER (1), "hello" + " ", INTEGER (6)) = INTEGER (1)
THEN
END ;
-   IF funcptr (1, "hello" + " " + WORLD, 11) = 1
+   IF funcptr (INTEGER (1), "hello" + " " + WORLD, INTEGER (11)) = INTEGER (1)
THEN
END
 END callingc11.
diff --git a/gcc/testsuite/gm2/extensions/run/pass/vararg2.mod 
b/gcc/testsuite/gm2/extensions/run/pass/vararg2.mod
index e26ed096fb84..05f7074a459d 100644
--- a/gcc/testsuite/gm2/extensions/run/pass/vararg2.mod
+++ b/gcc/testsuite/gm2/extensions/run/pass/vararg2.mod
@@ -21,13 +21,13 @@ FROM cvararg IMPORT funcptr ;
 FROM SYSTEM IMPORT ADR ;
 
 BEGIN
-   IF funcptr(1, ADR("hello world"), 11)=1
+   IF funcptr(INTEGER (1), ADR("hello world"), INTEGER (11))=INTEGER (1)
THEN
END ;
-   IF funcptr(1, ADR("hello"), 5)=1
+   IF funcptr(INTEGER (1), ADR("hello"), INTEGER (5))=INTEGER (1)
THEN
END ;
-   IF funcptr(1, ADR("/etc/passwd"), 11)=1
+   IF funcptr(INTEGER (1), ADR("/etc/passwd"), INTEGER (11))=INTEGER (1)
THEN
END
 END vararg2.
diff --git a/gcc/testsuite/gm2/iso/run/pass/packed.mod 
b/gcc/testsuite/gm2/iso/run/pass/packed.mod
index 401a6998f71a..3dad71e60a13 100644
--- a/gcc/testsuite/gm2/iso/run/pass/packed.mod
+++ b/gcc/testsuite/gm2/iso/run/pass/packed.mod
@@ -38,7 +38,9 @@ PROCEDURE test ;
 VAR
v: CARDINAL ;
 BEGIN
+   printf ("testing to see BITSET{0} = CARDINAL (1)...");
Assert(CAST(CARDINAL, BITSET{0}) = VAL(CARDINAL, 1), __FILE__, __LINE__) ;
+   printf ("yes\n");
v := MAX(CARDINAL)-1 ;
WHILE v>0 DO
   Assert(CAST(CARDINAL, SHIFT(CAST(BITSET, v), -1)) = v DIV 2, __FILE__, 
__LINE__) ;


[gcc r14-10179] [PR modula2/113768][PR modula2/114133] bugfix constants must be cast prior to vararg call

2024-05-07 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:07dab3f6b56c711dcd737d856cf01a597a2e1626

commit r14-10179-g07dab3f6b56c711dcd737d856cf01a597a2e1626
Author: Gaius Mulley 
Date:   Tue May 7 19:51:08 2024 +0100

[PR modula2/113768][PR modula2/114133] bugfix constants must be cast prior 
to vararg call

This bug fix corrects the test codes below by converting the constant
literals to the type required by C.  In the testcases below the values, 1
etc were converted into the INTEGER type before being passed to a C
vararg function.  By default in modula2 constant literal ordinals are
represented as the ZTYPE (the largest GCC integer type node).

gcc/testsuite/ChangeLog:

PR modula2/113768
PR modula2/114133
* gm2/extensions/run/pass/callingc10.mod: Convert constant literal
numbers into INTEGER.
* gm2/extensions/run/pass/callingc11.mod: Ditto.
* gm2/extensions/run/pass/vararg2.mod: Ditto.
* gm2/iso/run/pass/packed.mod: Emit a printf as a runtime
diagnostic.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/testsuite/gm2/extensions/run/pass/callingc10.mod | 6 +++---
 gcc/testsuite/gm2/extensions/run/pass/callingc11.mod | 6 +++---
 gcc/testsuite/gm2/extensions/run/pass/vararg2.mod| 6 +++---
 gcc/testsuite/gm2/iso/run/pass/packed.mod| 2 ++
 4 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/gcc/testsuite/gm2/extensions/run/pass/callingc10.mod 
b/gcc/testsuite/gm2/extensions/run/pass/callingc10.mod
index 3a2d3e210dcc..0c26fedf8453 100644
--- a/gcc/testsuite/gm2/extensions/run/pass/callingc10.mod
+++ b/gcc/testsuite/gm2/extensions/run/pass/callingc10.mod
@@ -4,13 +4,13 @@ FROM cvararg IMPORT funcptr ;
 FROM SYSTEM IMPORT ADR ;
 
 BEGIN
-   IF funcptr (1, "hello", 5) = 1
+   IF funcptr (INTEGER (1), "hello", INTEGER (5)) = INTEGER (1)
THEN
END ;
-   IF funcptr (1, "hello" + " ", 6) = 1
+   IF funcptr (INTEGER (1), "hello" + " ", INTEGER (6)) = INTEGER (1)
THEN
END ;
-   IF funcptr (1, "hello" + " " + "world", 11) = 1
+   IF funcptr (INTEGER (1), "hello" + " " + "world", INTEGER (11)) = INTEGER 
(1)
THEN
END
 END callingc10.
diff --git a/gcc/testsuite/gm2/extensions/run/pass/callingc11.mod 
b/gcc/testsuite/gm2/extensions/run/pass/callingc11.mod
index 9b8cb82d645f..d71026ee35df 100644
--- a/gcc/testsuite/gm2/extensions/run/pass/callingc11.mod
+++ b/gcc/testsuite/gm2/extensions/run/pass/callingc11.mod
@@ -5,13 +5,13 @@ FROM SYSTEM IMPORT ADR ;
 FROM strconst IMPORT WORLD ;
 
 BEGIN
-   IF funcptr (1, "hello", 5) = 1
+   IF funcptr (INTEGER (1), "hello", INTEGER (5)) = INTEGER (1)
THEN
END ;
-   IF funcptr (1, "hello" + " ", 6) = 1
+   IF funcptr (INTEGER (1), "hello" + " ", INTEGER (6)) = INTEGER (1)
THEN
END ;
-   IF funcptr (1, "hello" + " " + WORLD, 11) = 1
+   IF funcptr (INTEGER (1), "hello" + " " + WORLD, INTEGER (11)) = INTEGER (1)
THEN
END
 END callingc11.
diff --git a/gcc/testsuite/gm2/extensions/run/pass/vararg2.mod 
b/gcc/testsuite/gm2/extensions/run/pass/vararg2.mod
index e26ed096fb84..05f7074a459d 100644
--- a/gcc/testsuite/gm2/extensions/run/pass/vararg2.mod
+++ b/gcc/testsuite/gm2/extensions/run/pass/vararg2.mod
@@ -21,13 +21,13 @@ FROM cvararg IMPORT funcptr ;
 FROM SYSTEM IMPORT ADR ;
 
 BEGIN
-   IF funcptr(1, ADR("hello world"), 11)=1
+   IF funcptr(INTEGER (1), ADR("hello world"), INTEGER (11))=INTEGER (1)
THEN
END ;
-   IF funcptr(1, ADR("hello"), 5)=1
+   IF funcptr(INTEGER (1), ADR("hello"), INTEGER (5))=INTEGER (1)
THEN
END ;
-   IF funcptr(1, ADR("/etc/passwd"), 11)=1
+   IF funcptr(INTEGER (1), ADR("/etc/passwd"), INTEGER (11))=INTEGER (1)
THEN
END
 END vararg2.
diff --git a/gcc/testsuite/gm2/iso/run/pass/packed.mod 
b/gcc/testsuite/gm2/iso/run/pass/packed.mod
index 401a6998f71a..3dad71e60a13 100644
--- a/gcc/testsuite/gm2/iso/run/pass/packed.mod
+++ b/gcc/testsuite/gm2/iso/run/pass/packed.mod
@@ -38,7 +38,9 @@ PROCEDURE test ;
 VAR
v: CARDINAL ;
 BEGIN
+   printf ("testing to see BITSET{0} = CARDINAL (1)...");
Assert(CAST(CARDINAL, BITSET{0}) = VAL(CARDINAL, 1), __FILE__, __LINE__) ;
+   printf ("yes\n");
v := MAX(CARDINAL)-1 ;
WHILE v>0 DO
   Assert(CAST(CARDINAL, SHIFT(CAST(BITSET, v), -1)) = v DIV 2, __FILE__, 
__LINE__) ;


[gcc r15-349] PR modula2/115003 exporting a symbol to outer scope with a name clash causes ICE

2024-05-09 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:bc5afdf14ccf8375f7fb3de2be1121aaf550f8aa

commit r15-349-gbc5afdf14ccf8375f7fb3de2be1121aaf550f8aa
Author: Gaius Mulley 
Date:   Thu May 9 19:35:20 2024 +0100

PR modula2/115003 exporting a symbol to outer scope with a name clash 
causes ICE

An ICE will occur if an unknown symbol is exported and causes a name
clash.  The error mechanism attempts to find the scope of an unknown
symbol.  This patch adds a missing case clause to GetScope and returns
NulSym if the scope is an unknown symbol.

gcc/m2/ChangeLog:

PR modula2/115003
* gm2-compiler/SymbolTable.mod (GetScope): Add UndefinedSym
case clause and return NulSym.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-compiler/SymbolTable.mod | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/m2/gm2-compiler/SymbolTable.mod 
b/gcc/m2/gm2-compiler/SymbolTable.mod
index f5890ec684fe..f206a47dff78 100644
--- a/gcc/m2/gm2-compiler/SymbolTable.mod
+++ b/gcc/m2/gm2-compiler/SymbolTable.mod
@@ -12449,6 +12449,7 @@ BEGIN
   ConstLitSym: RETURN( ConstLit.Scope ) |
   ConstStringSym : RETURN( ConstString.Scope ) |
   ConstVarSym: RETURN( ConstVar.Scope ) |
+  UndefinedSym   : RETURN( NulSym ) |
   PartialUnboundedSym: InternalError ('should not be requesting the scope 
of a PartialUnbounded symbol')
 
   ELSE


[gcc r15-516] PR modula2/115057 TextIO.ReadRestLine raises an exception when buffer is exceeded

2024-05-15 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:680af0e1e90d4b80260d173636dfe15654fd470d

commit r15-516-g680af0e1e90d4b80260d173636dfe15654fd470d
Author: Gaius Mulley 
Date:   Wed May 15 16:58:21 2024 +0100

PR modula2/115057 TextIO.ReadRestLine raises an exception when buffer is 
exceeded

TextIO.ReadRestLine will raise an "attempting to read beyond end of file"
exception if the buffer is exceeded.  This bug is caused by the
TextIO.ReadRestLine calling IOChan.Skip without a preceeding IOChan.Look.
The Look procedure will update the status result whereas
Skip always sets read result to allRight.

gcc/m2/ChangeLog:

PR modula2/115057
* gm2-libs-iso/TextIO.mod (ReadRestLine): Use ReadChar to
skip unwanted characters as this calls IOChan.Look and updates
the cid result status.  A Skip without a Look does not update
the status.  Skip always sets read result to allRight.
* gm2-libs-iso/TextUtil.def (SkipSpaces): Improve comments.
(CharAvailable): Improve comments.
* gm2-libs-iso/TextUtil.mod (SkipSpaces): Improve comments.
(CharAvailable): Improve comments.

gcc/testsuite/ChangeLog:

PR modula2/115057
* gm2/isolib/run/pass/testrestline.mod: New test.
* gm2/isolib/run/pass/testrestline2.mod: New test.
* gm2/isolib/run/pass/testrestline3.mod: New test.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-libs-iso/TextIO.mod  | 13 -
 gcc/m2/gm2-libs-iso/TextUtil.def|  6 +-
 gcc/m2/gm2-libs-iso/TextUtil.mod|  6 +-
 gcc/testsuite/gm2/isolib/run/pass/testrestline.mod  | 20 
 gcc/testsuite/gm2/isolib/run/pass/testrestline2.mod | 17 +
 gcc/testsuite/gm2/isolib/run/pass/testrestline3.mod | 16 
 6 files changed, 71 insertions(+), 7 deletions(-)

diff --git a/gcc/m2/gm2-libs-iso/TextIO.mod b/gcc/m2/gm2-libs-iso/TextIO.mod
index 78d67187b799..5204467b1921 100644
--- a/gcc/m2/gm2-libs-iso/TextIO.mod
+++ b/gcc/m2/gm2-libs-iso/TextIO.mod
@@ -114,13 +114,19 @@ PROCEDURE ReadRestLine (cid: IOChan.ChanId; VAR s: ARRAY 
OF CHAR);
   *)
 VAR
i, h: CARDINAL ;
+   ignore  : CHAR ;
finished: BOOLEAN ;
 BEGIN
h := HIGH(s) ;
i := 0 ;
finished := FALSE ;
-   WHILE (i<=h) AND CharAvailable (cid) AND (NOT finished) DO
-  ReadChar (cid, s[i]) ;
+   WHILE CharAvailable (cid) AND (NOT finished) DO
+  IF i <= h
+  THEN
+ ReadChar (cid, s[i])
+  ELSE
+ ReadChar (cid, ignore)
+  END ;
   IF EofOrEoln (cid)
   THEN
  finished := TRUE
@@ -128,9 +134,6 @@ BEGIN
  INC (i)
   END
END ;
-   WHILE CharAvailable (cid) DO
-  IOChan.Skip (cid)
-   END ;
SetNul (cid, i, s, TRUE)
 END ReadRestLine ;
 
diff --git a/gcc/m2/gm2-libs-iso/TextUtil.def b/gcc/m2/gm2-libs-iso/TextUtil.def
index ead045617233..7e6b3ed07dce 100644
--- a/gcc/m2/gm2-libs-iso/TextUtil.def
+++ b/gcc/m2/gm2-libs-iso/TextUtil.def
@@ -45,11 +45,15 @@ IMPORT IOChan ;
 PROCEDURE SkipSpaces (cid: IOChan.ChanId) ;
 
 
-(* The following procedures do not read past line marks.  *)
+(* CharAvailable returns TRUE if IOChan.ReadResult is notKnown or
+   allRight.  *)
 
 PROCEDURE CharAvailable (cid: IOChan.ChanId) : BOOLEAN ;
 
 
+(* EofOrEoln returns TRUE if IOChan.ReadResult is endOfLine or
+   endOfInput.  *)
+
 PROCEDURE EofOrEoln (cid: IOChan.ChanId) : BOOLEAN ;
 
 
diff --git a/gcc/m2/gm2-libs-iso/TextUtil.mod b/gcc/m2/gm2-libs-iso/TextUtil.mod
index 44dbd1c69f8b..ad5786ca2fb2 100644
--- a/gcc/m2/gm2-libs-iso/TextUtil.mod
+++ b/gcc/m2/gm2-libs-iso/TextUtil.mod
@@ -23,7 +23,8 @@ BEGIN
 END SkipSpaces ;
 
 
-(* The following procedures do not read past line marks.  *)
+(* CharAvailable returns TRUE if IOChan.ReadResult is notKnown or
+   allRight.  *)
 
 PROCEDURE CharAvailable (cid: IOChan.ChanId) : BOOLEAN ;
 BEGIN
@@ -32,6 +33,9 @@ BEGIN
 END CharAvailable ;
 
 
+(* EofOrEoln returns TRUE if IOChan.ReadResult is endOfLine or
+   endOfInput.  *)
+
 PROCEDURE EofOrEoln (cid: IOChan.ChanId) : BOOLEAN ;
 BEGIN
RETURN( (IOChan.ReadResult (cid) = IOConsts.endOfLine) OR
diff --git a/gcc/testsuite/gm2/isolib/run/pass/testrestline.mod 
b/gcc/testsuite/gm2/isolib/run/pass/testrestline.mod
new file mode 100644
index ..7702e88bdd95
--- /dev/null
+++ b/gcc/testsuite/gm2/isolib/run/pass/testrestline.mod
@@ -0,0 +1,20 @@
+MODULE testrestline ;
+
+IMPORT SeqFile, TextIO ;
+
+VAR
+   chan: SeqFile.ChanId ;
+   line: ARRAY [0..5] OF CHAR ;
+   results : SeqFile.OpenResults ;
+BEGIN
+   SeqFile.OpenWrite (chan, "test.input", SeqFile.write, results) ;
+   TextIO.WriteString (chan, "a line of text exceeding 6 chars") ;
+   TextIO.WriteLn (chan) ;
+   TextIO.WriteString (chan, "a second lineline of text exceeding 6 chars") ;
+   TextIO.WriteLn (chan) ;
+   SeqFile.Close (chan

[gcc r15-700] PR modula2/115164 initial test code highlighting the problem

2024-05-20 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:d642b66a298ece7394e786a6a2d14a4f0b561d9a

commit r15-700-gd642b66a298ece7394e786a6a2d14a4f0b561d9a
Author: Gaius Mulley 
Date:   Tue May 21 01:11:48 2024 +0100

PR modula2/115164 initial test code highlighting the problem

This patch includes some trivial testcode which highlights
PR 115164.  Expect future test code to perform runtime checks
for a series of trailing zeros.

gcc/testsuite/ChangeLog:

PR modula2/115164
* gm2/isolib/run/pass/testlowread.mod: New test.
* gm2/isolib/run/pass/testwritereal.mod: New test.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/testsuite/gm2/isolib/run/pass/testlowread.mod   | 9 +
 gcc/testsuite/gm2/isolib/run/pass/testwritereal.mod | 9 +
 2 files changed, 18 insertions(+)

diff --git a/gcc/testsuite/gm2/isolib/run/pass/testlowread.mod 
b/gcc/testsuite/gm2/isolib/run/pass/testlowread.mod
new file mode 100644
index ..fefbcb0b3720
--- /dev/null
+++ b/gcc/testsuite/gm2/isolib/run/pass/testlowread.mod
@@ -0,0 +1,9 @@
+MODULE testlowread ;
+
+FROM LowReal IMPORT places ;
+FROM STextIO IMPORT WriteString, WriteLn ;
+FROM SWholeIO IMPORT WriteCard ;
+
+BEGIN
+   WriteString ('value of places = ') ; WriteCard (places, 0) ; WriteLn
+END testlowread.
diff --git a/gcc/testsuite/gm2/isolib/run/pass/testwritereal.mod 
b/gcc/testsuite/gm2/isolib/run/pass/testwritereal.mod
new file mode 100644
index ..025d684175c5
--- /dev/null
+++ b/gcc/testsuite/gm2/isolib/run/pass/testwritereal.mod
@@ -0,0 +1,9 @@
+MODULE testwritereal ;
+
+FROM STextIO IMPORT WriteString, WriteLn ;
+FROM SRealIO IMPORT WriteFloat ;
+FROM RealMath IMPORT pi ;
+
+BEGIN
+   WriteString ('value of pi = ') ; WriteFloat (pi, 0, 0) ; WriteLn
+END testwritereal.


[gcc r15-754] modula2: Pass --destdir for dir index during install of m2.info.

2024-05-21 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:232a86f9640cde6908d0875b8df52c36030c5b5e

commit r15-754-g232a86f9640cde6908d0875b8df52c36030c5b5e
Author: Sam James 
Date:   Tue May 21 12:31:47 2024 +0100

modula2: Pass --destdir for dir index during install of m2.info.

This patch adds DESTDIR to the infodir when installing m2.info.

gcc/m2/ChangeLog

* Make-lang.in (m2.install-info): Pass --destdir for dir index.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/Make-lang.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/m2/Make-lang.in b/gcc/m2/Make-lang.in
index 0abd8ce1455..da4226123df 100644
--- a/gcc/m2/Make-lang.in
+++ b/gcc/m2/Make-lang.in
@@ -425,7 +425,7 @@ m2.install-info: installdirs
else true; fi
-if [ -f gm2$(exeext) ] && [ -f $(DESTDIR)$(infodir)/m2.info ]; then \
  if $(SHELL) -c 'install-info --version' >/dev/null 2>&1; then \
-   install-info --dir-file=$(infodir)/dir 
$(DESTDIR)$(infodir)/m2.info; \
+   install-info --dir-file=$(DESTDIR)$(infodir)/dir 
$(DESTDIR)$(infodir)/m2.info; \
  else true; fi; \
else true; fi


[gcc r15-756] modula2: use groups in the type resolver of the bootstrap tool mc

2024-05-21 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:20e6f36771df7e3a8857628dd367eecfe77ba4fc

commit r15-756-g20e6f36771df7e3a8857628dd367eecfe77ba4fc
Author: Gaius Mulley 
Date:   Tue May 21 15:46:46 2024 +0100

modula2: use groups in the type resolver of the bootstrap tool mc

This patch introduces groups to maintain the lists used when resolving
types in the bootstrap tool mc.  The groups and type resolver are very
similar to that used in cc1gm2.  Specifically the resolver uses the group
to detect any change to any element in any list within a group.  This is
much cleaner and safer than the previous list length comparisons.

gcc/m2/ChangeLog:

* Make-lang.in (MC_EXTENDED_OPAQUE): New definition.
* mc-boot/GDynamicStrings.cc: Rebuild.
* mc-boot/GDynamicStrings.h: Rebuild.
* mc-boot/Galists.cc: Rebuild.
* mc-boot/Galists.h: Rebuild.
* mc-boot/Gdecl.cc: Rebuild.
* mc/alists.def (equalList): New procedure.
* mc/alists.mod (equalList): New procedure implementation.
* mc/decl.mod (group): New type.
(freeGroup): New variable.
(globalGroup): Ditto.
(todoQ): Remove declaration and prefix all occurances with 
globalGroup^.
(partialQ): Ditto.
(doneQ): Ditto.
(newGroup): New procedure.
(initGroup): Ditto.
(killGroup): Ditto.
(dupGroup): Ditto.
(equalGroup): Ditto.
(topologicallyOut): Rewrite.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/Make-lang.in   |   5 +-
 gcc/m2/mc-boot/GDynamicStrings.cc |  74 -
 gcc/m2/mc-boot/GDynamicStrings.h  |  17 +-
 gcc/m2/mc-boot/Galists.cc |  43 +
 gcc/m2/mc-boot/Galists.h  |   6 +
 gcc/m2/mc-boot/Gdecl.cc   | 319 +++---
 gcc/m2/mc/alists.def  |   7 +
 gcc/m2/mc/alists.mod  |  28 
 gcc/m2/mc/decl.mod| 218 ++
 9 files changed, 552 insertions(+), 165 deletions(-)

diff --git a/gcc/m2/Make-lang.in b/gcc/m2/Make-lang.in
index da4226123df..83d592f35d8 100644
--- a/gcc/m2/Make-lang.in
+++ b/gcc/m2/Make-lang.in
@@ -505,6 +505,7 @@ MC_ARGS= --olang=c++ \
  $(MC_COPYRIGHT) \
  --gcc-config-system
 
+MC_EXTENDED_OPAQUE=--extended-opaque
 MCDEPS=m2/boot-bin/mc$(exeext)
 
 MC=m2/boot-bin/mc$(exeext) $(MC_ARGS)
@@ -1539,7 +1540,7 @@ m2/gm2-libs-boot/SysStorage.o: 
$(srcdir)/m2/gm2-libs/SysStorage.mod $(MCDEPS) $(
 
 m2/gm2-compiler-boot/M2GCCDeclare.o: 
$(srcdir)/m2/gm2-compiler/M2GCCDeclare.mod $(MCDEPS) $(BUILD-BOOT-H)
-test -d $(@D)/$(DEPDIR) || $(mkinstalldirs) $(@D)/$(DEPDIR)
-   $(MC) --extended-opaque -o=m2/gm2-compiler-boot/M2GCCDeclare.c $<
+   $(MC) $(MC_EXTENDED_OPAQUE) -o=m2/gm2-compiler-boot/M2GCCDeclare.c $<
$(COMPILER) $(CM2DEP) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(GM2GCC) 
\
 -I. -I$(srcdir)/../include -I$(srcdir) \
 -I. -Im2/gm2-libs-boot -Im2/gm2-compiler-boot \
@@ -1548,7 +1549,7 @@ m2/gm2-compiler-boot/M2GCCDeclare.o: 
$(srcdir)/m2/gm2-compiler/M2GCCDeclare.mod
 
 m2/gm2-compiler-boot/M2Error.o: $(srcdir)/m2/gm2-compiler/M2Error.mod 
$(MCDEPS) $(BUILD-BOOT-H)
-test -d $(@D)/$(DEPDIR) || $(mkinstalldirs) $(@D)/$(DEPDIR)
-   $(MC) --extended-opaque -o=m2/gm2-compiler-boot/M2Error.c $<
+   $(MC) $(MC_EXTENDED_OPAQUE) -o=m2/gm2-compiler-boot/M2Error.c $<
$(COMPILER) $(CM2DEP) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(GM2GCC) 
\
 -I. -I$(srcdir)/../include -I$(srcdir) \
 -I. -Im2/gm2-libs-boot -Im2/gm2-compiler-boot \
diff --git a/gcc/m2/mc-boot/GDynamicStrings.cc 
b/gcc/m2/mc-boot/GDynamicStrings.cc
index 7f61778af64..a1cb88c03b7 100644
--- a/gcc/m2/mc-boot/GDynamicStrings.cc
+++ b/gcc/m2/mc-boot/GDynamicStrings.cc
@@ -255,12 +255,25 @@ extern "C" int DynamicStrings_Index 
(DynamicStrings_String s, char ch, unsigned
 
 /*
RIndex - returns the indice of the last occurance of, ch,
-in String, s. The search starts at position, o.
--1 is returned if, ch, is not found.
+in String, s.  The search starts at position, o.
+-1 is returned if, ch, is not found.  The search
+is performed left to right.
 */
 
 extern "C" int DynamicStrings_RIndex (DynamicStrings_String s, char ch, 
unsigned int o);
 
+/*
+   ReverseIndex - returns the indice of the last occurance of ch
+  in String s.  The search starts at position o
+  and searches from right to left.  The start position
+  may be indexed negatively from the right (-1 is the
+  last index).
+  The return value if ch is found will always be positive.
+  -1 is returned if ch is not found.
+*/
+
+extern "C" int DynamicStrings_ReverseIndex (DynamicStrings_String s, char ch, 
int o);
+
 /

[gcc r15-3156] modula2: Export all string to integral and fp number conversion functions

2024-08-24 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:ecc999b0224db06c1a7d8a4128bfa2ed162e2a61

commit r15-3156-gecc999b0224db06c1a7d8a4128bfa2ed162e2a61
Author: Gaius Mulley 
Date:   Sat Aug 24 22:43:55 2024 +0100

modula2: Export all string to integral and fp number conversion functions

Export all string to integral and floating point number conversion functions
(atof, atoi, atol, atoll, strtod, strtof, strtold, strtol, strtoll, strtoul
and strtoull).

gcc/m2/ChangeLog:

* gm2-libs/libc.def (atof): Export unqualified.
(atoi): Ditto.
(atol): Ditto.
(atoll): Ditto.
(strtod): Ditto.
(strtof): Ditto.
(strtold): Ditto.
(strtol): Ditto.
(strtoll): Ditto.
(strtoul): Ditto.
(strtoull): Ditto.

Signed-off-by: Wilken Gottwalt 

Diff:
---
 gcc/m2/gm2-libs/libc.def | 84 
 1 file changed, 84 insertions(+)

diff --git a/gcc/m2/gm2-libs/libc.def b/gcc/m2/gm2-libs/libc.def
index a314b59e43f1..e278617c2d86 100644
--- a/gcc/m2/gm2-libs/libc.def
+++ b/gcc/m2/gm2-libs/libc.def
@@ -29,6 +29,8 @@ DEFINITION MODULE FOR "C" libc ;
 FROM SYSTEM IMPORT ADDRESS, CSIZE_T, CSSIZE_T ;
 
 EXPORT UNQUALIFIED time_t, timeb, tm, ptrToTM,
+   atof, atoi, atol, atoll,
+   strtod, strtof, strtold, strtol, strtoll, strtoul, strtoull,
write, read,
system, abort,
malloc, free,
@@ -75,6 +77,88 @@ TYPE
exitP = PROCEDURE () : INTEGER ;
 
 
+(*
+ double atof(const char *nptr)
+*)
+
+PROCEDURE atof (nptr: ADDRESS) : REAL ;
+
+
+(*
+ int atoi(const char *nptr)
+*)
+
+PROCEDURE atoi (nptr: ADDRESS) : INTEGER ;
+
+
+(*
+ long atol(const char *nptr);
+*)
+
+PROCEDURE atol (nptr: ADDRESS) : CSSIZE_T ;
+
+
+(*
+ long long atoll(const char *nptr);
+*)
+
+PROCEDURE atoll (nptr: ADDRESS) : LONGINT ;
+
+
+(*
+ double strtod(const char *restrict nptr, char **_Nullable restrict endptr)
+*)
+
+PROCEDURE strtod (nptr, endptr: ADDRESS) : REAL ;
+
+
+(*
+ float strtof(const char *restrict nptr, char **_Nullable restrict endptr)
+*)
+
+PROCEDURE strtof (nptr, endptr: ADDRESS) : SHORTREAL ;
+
+
+(*
+ long double strtold(const char *restrict nptr,
+ char **_Nullable restrict endptr)
+*)
+
+PROCEDURE strtold (nptr, endptr: ADDRESS) : LONGREAL ;
+
+
+(*
+ long strtol(const char *restrict nptr, char **_Nullable restrict endptr,
+ int base)
+*)
+
+PROCEDURE strtol (nptr, endptr: ADDRESS; base: INTEGER) : CSSIZE_T ;
+
+
+(*
+ long long strtoll(const char *restrict nptr,
+   char **_Nullable restrict endptr, int base)
+*)
+
+PROCEDURE strtoll (nptr, endptr: ADDRESS; base: INTEGER) : LONGINT ;
+
+
+(*
+ unsigned long strtoul(const char *restrict nptr,
+   char **_Nullable restrict endptr, int base)
+*)
+
+PROCEDURE strtoul (nptr, endptr: ADDRESS; base: INTEGER) : CSIZE_T ;
+
+
+(*
+ unsigned long long strtoull(const char *restrict nptr,
+ char **_Nullable restrict endptr, int base)
+*)
+
+PROCEDURE strtoull (nptr, endptr: ADDRESS; base: INTEGER) : LONGCARD ;
+
+
 (*
  ssize_t write (int d, void *buf, size_t nbytes)
 *)


[gcc r15-3158] modula2 testsuite: new libc unit test

2024-08-25 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:91f549537caa8dff2621c22ef2cdd48c55b0ad19

commit r15-3158-g91f549537caa8dff2621c22ef2cdd48c55b0ad19
Author: Gaius Mulley 
Date:   Sun Aug 25 10:14:49 2024 +0100

modula2 testsuite: new libc unit test

This patch provides a simple unit test for snprintf and atof against
the libc definition module.

gcc/testsuite/ChangeLog:

* gm2/calling-c/libc/run/pass/calling-c-libc-run-pass.exp: New test.
* gm2/calling-c/libc/run/pass/testlibcstr.mod: New test.

Signed-off-by: Gaius Mulley 

Diff:
---
 .../libc/run/pass/calling-c-libc-run-pass.exp  | 36 
 .../gm2/calling-c/libc/run/pass/testlibcstr.mod| 39 ++
 2 files changed, 75 insertions(+)

diff --git 
a/gcc/testsuite/gm2/calling-c/libc/run/pass/calling-c-libc-run-pass.exp 
b/gcc/testsuite/gm2/calling-c/libc/run/pass/calling-c-libc-run-pass.exp
new file mode 100644
index ..a7973d9c020d
--- /dev/null
+++ b/gcc/testsuite/gm2/calling-c/libc/run/pass/calling-c-libc-run-pass.exp
@@ -0,0 +1,36 @@
+# Copyright (C) 2024 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# .
+
+# This file was written by Gaius Mulley (gaiusm...@gmail.com)
+# for GNU Modula-2.
+
+if $tracelevel then {
+strace $tracelevel
+}
+
+# load support procs
+load_lib gm2-torture.exp
+
+gm2_init_pim "${srcdir}/gm2/cslling-c/libc/run/pass"
+
+foreach testcase [lsort [glob -nocomplain $srcdir/$subdir/*.mod]] {
+# If we're only testing specific files and this isn't one of them, skip it.
+if ![runtest_file_p $runtests $testcase] then {
+   continue
+}
+
+gm2-torture-execute $testcase "" "pass"
+}
diff --git a/gcc/testsuite/gm2/calling-c/libc/run/pass/testlibcstr.mod 
b/gcc/testsuite/gm2/calling-c/libc/run/pass/testlibcstr.mod
new file mode 100644
index ..9d90d7599517
--- /dev/null
+++ b/gcc/testsuite/gm2/calling-c/libc/run/pass/testlibcstr.mod
@@ -0,0 +1,39 @@
+MODULE testlibcstr ;
+
+FROM SYSTEM IMPORT ADDRESS, ADR ;
+FROM Storage IMPORT ALLOCATE, DEALLOCATE ;
+FROM libc IMPORT strtod, atof, printf, exit, snprintf ;
+FROM DynamicStrings IMPORT String,
+   InitString, InitStringCharStar, Equal, Slice,
+   KillString ;
+
+(*
+   runtest -
+*)
+
+PROCEDURE runtest ;
+CONST
+   BufSpace = 100 ;
+VAR
+   s: String ;
+   r: REAL ;
+   a: ADDRESS ;
+BEGIN
+   r := atof (ADR ("3.14159")) ;
+   ALLOCATE (a, BufSpace) ;
+   snprintf (a, BufSpace, "%f", r) ;
+   s := InitStringCharStar (a) ;
+   IF NOT Equal (InitString ("3.14159"), Slice (s, 0, 7))
+   THEN
+  printf ("failed to convert 3.14159 to a REAL or string\n") ;
+  exit (1)
+   END ;
+   DEALLOCATE (a, BufSpace) ;
+   s := KillString (s)
+END runtest ;
+
+
+BEGIN
+   runtest ;
+   printf ("all tests passed!\n")
+END testlibcstr.


[gcc r15-3318] PR modula2/116181: m2rts fix -Wodr warning

2024-08-30 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:87ce8172f0bf649a8a79ef7481fb3bf35882083f

commit r15-3318-g87ce8172f0bf649a8a79ef7481fb3bf35882083f
Author: Gaius Mulley 
Date:   Fri Aug 30 14:22:01 2024 +0100

PR modula2/116181: m2rts fix -Wodr warning

This patch fixes the -Wodr warning seen in pge-boot/m2rts.h
when building pge.

gcc/m2/ChangeLog:

PR modula2/116181
* pge-boot/GM2RTS.h: Regenerate.
* pge-boot/m2rts.h: Ditto.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/pge-boot/GM2RTS.h | 10 +-
 gcc/m2/pge-boot/m2rts.h  | 28 ++--
 2 files changed, 7 insertions(+), 31 deletions(-)

diff --git a/gcc/m2/pge-boot/GM2RTS.h b/gcc/m2/pge-boot/GM2RTS.h
index 4186c8f25e44..055cc95675ba 100644
--- a/gcc/m2/pge-boot/GM2RTS.h
+++ b/gcc/m2/pge-boot/GM2RTS.h
@@ -54,11 +54,6 @@ typedef struct M2RTS_ArgCVEnvP_p M2RTS_ArgCVEnvP;
 typedef void (*M2RTS_ArgCVEnvP_t) (int, void *, void *);
 struct M2RTS_ArgCVEnvP_p { M2RTS_ArgCVEnvP_t proc; };
 
-#define M2RTS_RegisterModule_Cstr(MODNAME,LIBNAME,init,fini,dep) \
-  M2RTS_RegisterModule (reinterpret_cast  (const_cast  
(MODNAME)), \
-   reinterpret_cast  (const_cast  
(LIBNAME)), \
-   init, fini, dep)
-
 EXTERN void M2RTS_ConstructModules (void * applicationmodule, void * libname, 
void * overrideliborder, int argc, void * argv, void * envp);
 EXTERN void M2RTS_DeconstructModules (void * applicationmodule, void * 
libname, int argc, void * argv, void * envp);
 
@@ -68,10 +63,7 @@ EXTERN void M2RTS_DeconstructModules (void * 
applicationmodule, void * libname,
 explored to determine initialization order.
 */
 
-EXTERN void M2RTS_RegisterModule (void *name, void *libname,
- M2RTS_ArgCVEnvP init,
- M2RTS_ArgCVEnvP fini,
- PROC dependencies);
+EXTERN void M2RTS_RegisterModule (void * name, void * libname, M2RTS_ArgCVEnvP 
init, M2RTS_ArgCVEnvP fini, PROC dependencies);
 
 /*
RequestDependant - used to specify that modulename is dependant upon
diff --git a/gcc/m2/pge-boot/m2rts.h b/gcc/m2/pge-boot/m2rts.h
index d8bac68fe6bd..df6cbcb2c8d6 100644
--- a/gcc/m2/pge-boot/m2rts.h
+++ b/gcc/m2/pge-boot/m2rts.h
@@ -24,31 +24,15 @@ a copy of the GCC Runtime Library Exception along with this 
program;
 see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 .  */
 
-#ifdef M2_MC
-/* These type definitions match those used by mc, they are defined differently
-   to satisfy -Wodr when building from the mc translated versions of m2
-   source.  */
 #include "GM2RTS.h"
-#else
-/* These type definitions match those used by cc1gm2, they will be the same
-   sizeof as those above (and also for all their dependants).  */
-typedef void (*M2RTS_ArgCVEnvP) (int, char **, char **);
-typedef void (*PROC) (void);
-#endif
 
+#ifdef MC_M2
+/* mc sources do not register their init fini functions as they are
+   initialized by a static scaffold (called by main).  */
+#define M2RTS_RegisterModule_Cstr(MODNAME,LIBNAME,init,fini,dep)
+#else
 #define M2RTS_RegisterModule_Cstr(MODNAME,LIBNAME,init,fini,dep) \
   M2RTS_RegisterModule (reinterpret_cast  (const_cast  
(MODNAME)), \
reinterpret_cast  (const_cast  
(LIBNAME)), \
init, fini, dep)
-
-extern "C" void M2RTS_RequestDependant (const void *modulename, const void 
*dependancy);
-extern "C" void M2RTS_RegisterModule (void *modulename, void *libname,
- M2RTS_ArgCVEnvP init, M2RTS_ArgCVEnvP 
fini, PROC dependencies);
-extern "C" void _M2_M2RTS_init (void);
-
-extern "C" void M2RTS_ConstructModules (const void *,
-   int argc, char *argv[], char *envp[]);
-extern "C" void M2RTS_Terminate (void);
-extern "C" void M2RTS_DeconstructModules (void);
-
-extern "C" void M2RTS_Halt (const char *, const char *, const char *, int) 
__attribute__ ((noreturn));
+#endif


[gcc r15-3380] PR modula2/116557 Remove physical address from the GPL header comment

2024-09-02 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:78dc2e2575c602c62d50a9522ea976020a5bf7aa

commit r15-3380-g78dc2e2575c602c62d50a9522ea976020a5bf7aa
Author: Gaius Mulley 
Date:   Mon Sep 2 13:29:25 2024 +0100

PR modula2/116557 Remove physical address from the GPL header comment

This patch removes the physical address from all the header comments
in the m2 subdirectory.  The physical address is replaced with the
text "You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3.  If not see
." instead.

gcc/m2/ChangeLog:

PR modula2/116557
* gm2-lang.cc: Replace physical address with URL in GPL header.
* gm2-lang.h: Ditto.
* images/LICENSE.IMG: Ditto.
* m2-tree.def: Ditto.
* mc-boot/GIndexing.cc: Ditto.
* mc-boot/Gkeyc.cc: Ditto.
* mc-boot/Glists.cc: Ditto.
* mc-boot/GmcComp.cc: Ditto.
* mc-boot/GmcDebug.cc: Ditto.
* mc-boot/GmcFileName.cc: Ditto.
* mc-boot/GmcMetaError.cc: Ditto.
* mc-boot/GmcOptions.cc: Ditto.
* mc-boot/GmcPreprocess.cc: Ditto.
* mc-boot/GmcPretty.cc: Ditto.
* mc-boot/GmcPrintf.cc: Ditto.
* mc-boot/GmcQuiet.cc: Ditto.
* mc-boot/GmcReserved.cc: Ditto.
* mc-boot/GmcSearch.cc: Ditto.
* mc-boot/GmcStack.cc: Ditto.
* mc/Indexing.mod: Ditto.
* mc/keyc.mod: Ditto.
* mc/lists.mod: Ditto.
* mc/mcComp.mod: Ditto.
* mc/mcDebug.mod: Ditto.
* mc/mcFileName.mod: Ditto.
* mc/mcMetaError.mod: Ditto.
* mc/mcOptions.mod: Ditto.
* mc/mcPreprocess.mod: Ditto.
* mc/mcPretty.mod: Ditto.
* mc/mcPrintf.mod: Ditto.
* mc/mcQuiet.mod: Ditto.
* mc/mcReserved.mod: Ditto.
* mc/mcSearch.mod: Ditto.
* mc/mcStack.mod: Ditto.
* tools-src/buildpg: Ditto.
* tools-src/calcpath: Ditto.
* tools-src/checkmeta.py: Ditto.
* tools-src/def2doc.py: Ditto.
* tools-src/makeSystem: Ditto.
* tools-src/tidydates.py: Ditto.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-lang.cc  | 5 ++---
 gcc/m2/gm2-lang.h   | 6 +++---
 gcc/m2/images/LICENSE.IMG   | 5 ++---
 gcc/m2/m2-tree.def  | 5 ++---
 gcc/m2/mc-boot/GIndexing.cc | 9 -
 gcc/m2/mc-boot/Gkeyc.cc | 7 +++
 gcc/m2/mc-boot/Glists.cc| 7 +++
 gcc/m2/mc-boot/GmcComp.cc   | 6 +++---
 gcc/m2/mc-boot/GmcDebug.cc  | 6 +++---
 gcc/m2/mc-boot/GmcFileName.cc   | 6 +++---
 gcc/m2/mc-boot/GmcMetaError.cc  | 8 
 gcc/m2/mc-boot/GmcOptions.cc| 7 +++
 gcc/m2/mc-boot/GmcPreprocess.cc | 6 +++---
 gcc/m2/mc-boot/GmcPretty.cc | 9 -
 gcc/m2/mc-boot/GmcPrintf.cc | 6 +++---
 gcc/m2/mc-boot/GmcQuiet.cc  | 6 +++---
 gcc/m2/mc-boot/GmcReserved.cc   | 7 +++
 gcc/m2/mc-boot/GmcSearch.cc | 6 +++---
 gcc/m2/mc-boot/GmcStack.cc  | 7 +++
 gcc/m2/mc/Indexing.mod  | 7 +++
 gcc/m2/mc/keyc.mod  | 7 +++
 gcc/m2/mc/lists.mod | 7 +++
 gcc/m2/mc/mcComp.mod| 6 +++---
 gcc/m2/mc/mcDebug.mod   | 6 +++---
 gcc/m2/mc/mcFileName.mod| 6 +++---
 gcc/m2/mc/mcMetaError.mod   | 6 +++---
 gcc/m2/mc/mcOptions.mod | 7 +++
 gcc/m2/mc/mcPreprocess.mod  | 6 +++---
 gcc/m2/mc/mcPretty.mod  | 7 +++
 gcc/m2/mc/mcPrintf.mod  | 6 +++---
 gcc/m2/mc/mcQuiet.mod   | 6 +++---
 gcc/m2/mc/mcReserved.mod| 7 +++
 gcc/m2/mc/mcSearch.mod  | 6 +++---
 gcc/m2/mc/mcStack.mod   | 7 +++
 gcc/m2/tools-src/buildpg| 5 ++---
 gcc/m2/tools-src/calcpath   | 6 +++---
 gcc/m2/tools-src/checkmeta.py   | 5 ++---
 gcc/m2/tools-src/def2doc.py | 5 ++---
 gcc/m2/tools-src/makeSystem | 6 +++---
 gcc/m2/tools-src/tidydates.py   | 5 ++---
 40 files changed, 116 insertions(+), 137 deletions(-)

diff --git a/gcc/m2/gm2-lang.cc b/gcc/m2/gm2-lang.cc
index b3c3c017cc96..ac5d0890f91d 100644
--- a/gcc/m2/gm2-lang.cc
+++ b/gcc/m2/gm2-lang.cc
@@ -16,9 +16,8 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
GNU
 General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with GNU Modula-2; see the file COPYING.  If not, write to the
-Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301, USA.  */
+along with GCC; see the file COPYING3.  If not see
+.  */
 
 #define INCLUDE_VECTOR
 #include "gm2-gcc/gcc-consolidation.h"
diff --git a/gcc/m2/gm2-lang.h b/gcc/m2/gm2-lang.h
index 224ea99dea6f..4ba46c924484 100644
--- a/gcc/m2/gm2-lang.h
+++ b/gcc/m2/gm2-lang.h
@@ -15,9 +15,9 @@ MERCHA