public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/modula-2] Bugfix constant overflow detection and improved error messages.
@ 2022-09-05 14:42 Gaius Mulley
  0 siblings, 0 replies; only message in thread
From: Gaius Mulley @ 2022-09-05 14:42 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:589b0719a232c74b8cd55bda97465030e6eef4fd

commit 589b0719a232c74b8cd55bda97465030e6eef4fd
Author: Gaius Mulley <gaiusmod2@gmail.com>
Date:   Mon Sep 5 15:41:42 2022 +0100

    Bugfix constant overflow detection and improved error messages.
    
    Detect constant overflow (or whether the constant requires unsigned
    int or long int or long unsigned int).  Also further tidying up of
    mc/decl.mod and m2/Make-lang.in.
    
    gcc/m2/ChangeLog:
    
            * gcc/m2/Make-lang.in (m2/mc-boot/main.o): Avoid temporary file.
            (m2/gm2-compiler/%.o) Remove $(objdir) from the rule target.
            (m2/gm2-compiler/%.mod) Remove $(objdir) from the rule target.
            (m2/gm2-compiler/%.mod) Remove $(objdir) from the rule target.
            (m2/gm2-compiler-boot/%.mod) Remove $(objdir) from the rule
            target.
            * gm2-compiler/M2ALU.def (PushString): Add tokenno as a parameter.
            * gm2-compiler/M2ALU.mod (PushString): Add tokenno as a parameter.
            Call BuildConstLiteralNumber with extra parameter location.
            * gm2-compiler/M2Options.def: Remove CppProg.
            * gm2-compiler/SymbolTable.mod: Import location_t, TokenToLineNo.
            (MakeConstLit) Pass tok to GetConstLitType and PushString.
            (GetConstLitType) Add tok parameter.  Call DetermineSizeOfConstant
            with location as a parameter.
            * gm2-gcc/m2decl.cc (DetermineSizeOfConstant): Add location
            parameter.  (BuildConstLiteralNumber) Add location parameter.
            (BuildConstLiteralNumber) use error_at with a quoted string.
            * gm2-gcc/m2decl.def (DetermineSizeOfConstant): Add location
            parameter.  (BuildConstLiteralNumber) Add location parameter.
            * gm2-gcc/m2decl.h (DetermineSizeOfConstant): Add location
            parameter.  (BuildConstLiteralNumber) Add location parameter.
            * gm2-gcc/m2expr.cc (interpret_integer): Added space.
            (append_m2_digit) Pass extra parameter needsUnsigned.
            Detect whether the constant will fit if an unsigned int or
            unsigned long int is used.  (interpret_m2_integer)
            extra parameters needsLong and needsUnsigned.  Function rewritten.
            * gm2-gcc/m2expr.h (interpret_m2_integer): Declared with two
            extra parameters; needsLong and needsUnsigned.
            * mc/decl.mod (visitIntrinsicFunction): Refactored case statement.
    
    Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>

Diff:
---
 gcc/m2/Make-lang.in                  |  9 +++----
 gcc/m2/gm2-compiler/M2ALU.def        |  2 +-
 gcc/m2/gm2-compiler/M2ALU.mod        | 49 ++++++++++++++++++++----------------
 gcc/m2/gm2-compiler/M2GCCDeclare.mod |  3 ++-
 gcc/m2/gm2-compiler/M2Options.def    |  9 +------
 gcc/m2/gm2-compiler/SymbolTable.mod  | 21 ++++++++++------
 gcc/m2/gm2-gcc/m2decl.cc             | 24 +++++++-----------
 gcc/m2/gm2-gcc/m2decl.def            |  6 +++--
 gcc/m2/gm2-gcc/m2decl.h              |  6 +++--
 gcc/m2/gm2-gcc/m2expr.cc             | 35 ++++++++++++++++++--------
 gcc/m2/gm2-gcc/m2expr.h              |  3 ++-
 gcc/m2/mc/decl.mod                   |  5 +---
 12 files changed, 93 insertions(+), 79 deletions(-)

diff --git a/gcc/m2/Make-lang.in b/gcc/m2/Make-lang.in
index fea6c5cd4ca..fb8d98a934f 100644
--- a/gcc/m2/Make-lang.in
+++ b/gcc/m2/Make-lang.in
@@ -1282,8 +1282,7 @@ m2/mc-boot-ch/$(SRC_PREFIX)%.o: m2/mc-boot-ch/$(SRC_PREFIX)%.cc m2/gm2-libs/gm2-
 	$(CXX) -DHAVE_CONFIG_H -g -c -I. -Im2/gm2-libs -I$(srcdir)/../include -I$(srcdir) $(INCLUDES) -Im2/gm2-libs $< -o $@
 
 m2/mc-boot/main.o: $(M2LINK) $(srcdir)/m2/init/mcinit
-	unset CC ; $(M2LINK) -s --langc++ --exit --name mainmcinit.c $(srcdir)/m2/init/mcinit
-	mv mainmcinit.c m2/mc-boot/main.c
+	unset CC ; $(M2LINK) -s --langc++ --exit --name m2/mc-boot/main.c $(srcdir)/m2/init/mcinit
 	$(CXX) -g -c -I. -I$(srcdir)/../include -I$(srcdir) $(INCLUDES) m2/mc-boot/main.c -o $@
 
 mcflex.o: mcflex.c
@@ -1406,7 +1405,7 @@ m2/gm2-compiler/m2flex.o: m2/gm2-compiler/m2flex.c m2/gm2-libs/gm2-libs-host.h $
 	$(COMPILER) -c -g $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
           $(GM2GCC) -Im2/gm2-compiler-boot -Im2/gm2-libs-boot $< -o $@
 
-m2/gm2-compiler/%.o: $(objdir)/m2/gm2-compiler/%.mod
+m2/gm2-compiler/%.o: m2/gm2-compiler/%.mod
 	$(GM2_1) $(GM2_FLAGS) -c -I$(srcdir)/m2/gm2-compiler -I$(srcdir)/m2/gm2-libs -I$(srcdir)/m2/gm2-gcc -I$(srcdir)/m2/gm2-libiberty $< -o $@
 
 m2/gm2-compiler/M2Version.mod:
@@ -1519,10 +1518,10 @@ m2/gm2-auto/%.o: m2/gm2-auto/%.mod $(MCDEPS)
 m2/gm2-compiler-boot/$(SRC_PREFIX)%.h: $(srcdir)/m2/gm2-compiler-boot/%.def $(MCDEPS)
 	$(MC) --quiet -o=$@ $(srcdir)/m2/gm2-compiler-boot/$*.def
 
-$(objdir)/m2/gm2-compiler/%.mod: $(srcdir)/m2/gm2-compiler/%.bnf $(PGE)
+m2/gm2-compiler/%.mod: $(srcdir)/m2/gm2-compiler/%.bnf $(PGE)
 	$(PGE) -k -l $< -o $@
 
-$(objdir)/m2/gm2-compiler-boot/%.mod: $(srcdir)/m2/gm2-compiler/%.bnf $(PGE)
+m2/gm2-compiler-boot/%.mod: $(srcdir)/m2/gm2-compiler/%.bnf $(PGE)
 	$(PGE) -k -l $< -o $@
 
 check-m2: check-gm2
diff --git a/gcc/m2/gm2-compiler/M2ALU.def b/gcc/m2/gm2-compiler/M2ALU.def
index 28533dcb5e6..c4369e9994f 100644
--- a/gcc/m2/gm2-compiler/M2ALU.def
+++ b/gcc/m2/gm2-compiler/M2ALU.def
@@ -264,7 +264,7 @@ PROCEDURE PushChar (c: CHAR) ;
    PushString - pushes the numerical value of the string onto the stack.
 *)
 
-PROCEDURE PushString (s: Name) ;
+PROCEDURE PushString (tokenno: CARDINAL; s: Name) ;
 
 
 (*
diff --git a/gcc/m2/gm2-compiler/M2ALU.mod b/gcc/m2/gm2-compiler/M2ALU.mod
index 986af1d1b3e..47943754f79 100644
--- a/gcc/m2/gm2-compiler/M2ALU.mod
+++ b/gcc/m2/gm2-compiler/M2ALU.mod
@@ -1171,49 +1171,54 @@ END IsReal ;
    PushString - pushes the numerical value of the string onto the stack.
 *)
 
-PROCEDURE PushString (s: Name) ;
+PROCEDURE PushString (tokenno: CARDINAL; s: Name) ;
 VAR
-   ch    : CHAR ;
-   a, b  : DynamicStrings.String ;
-   length: CARDINAL ;
+   ch      : CHAR ;
+   a, b    : DynamicStrings.String ;
+   length  : CARDINAL ;
+   location: location_t ;
 BEGIN
-   a := DynamicStrings.InitStringCharStar(KeyToCharStar(s)) ;
+   a := DynamicStrings.InitStringCharStar (KeyToCharStar (s)) ;
    b := NIL ;
-   length := DynamicStrings.Length(a) ;
+   length := DynamicStrings.Length (a) ;
    IF length>0
    THEN
-      DEC(length) ;
-      ch := DynamicStrings.char(a, length) ;
+      DEC (length) ;
+      ch := DynamicStrings.char (a, length) ;
+      location := TokenToLocation (tokenno) ;
       CASE ch OF
 
       'H': (* hexadecimal *)
-           b := DynamicStrings.Slice(a, 0, -1) ;
-           PushIntegerTree(BuildConstLiteralNumber(DynamicStrings.string(b),
-                                                   16)) |
+           b := DynamicStrings.Slice (a, 0, -1) ;
+           PushIntegerTree (BuildConstLiteralNumber (location,
+                                                     DynamicStrings.string (b),
+                                                     16)) |
       'A': (* binary *)
-           b := DynamicStrings.Slice(a, 0, -1) ;
-           PushIntegerTree(BuildConstLiteralNumber(DynamicStrings.string(b),
-                                                   2)) |
+           b := DynamicStrings.Slice (a, 0, -1) ;
+           PushIntegerTree (BuildConstLiteralNumber (location,
+                                                     DynamicStrings.string (b),
+                                                     2)) |
       'C', (* --fixme-- question:
               should we type this as a char rather than an int? *)
       'B': (* octal *)
-           b := DynamicStrings.Slice(a, 0, -1) ;
-           PushIntegerTree(BuildConstLiteralNumber(DynamicStrings.string(b),
-                                                   8))
+           b := DynamicStrings.Slice (a, 0, -1) ;
+           PushIntegerTree (BuildConstLiteralNumber (location,
+                                                     DynamicStrings.string (b),
+                                                     8))
 
       ELSE
-         IF IsReal(a)
+         IF IsReal (a)
          THEN
-            PushRealTree(RealToTree(KeyToCharStar(s)))
+            PushRealTree (RealToTree (KeyToCharStar (s)))
          ELSE
-            PushIntegerTree(BuildConstLiteralNumber(KeyToCharStar(s), 10))
+            PushIntegerTree (BuildConstLiteralNumber (location, KeyToCharStar (s), 10))
          END
       END
    ELSE
       InternalError ('expecting constant literal')
    END ;
-   a := DynamicStrings.KillString(a) ;
-   b := DynamicStrings.KillString(b)
+   a := DynamicStrings.KillString (a) ;
+   b := DynamicStrings.KillString (b)
 END PushString ;
 
 
diff --git a/gcc/m2/gm2-compiler/M2GCCDeclare.mod b/gcc/m2/gm2-compiler/M2GCCDeclare.mod
index 60419cb6c92..e0e84562ed7 100644
--- a/gcc/m2/gm2-compiler/M2GCCDeclare.mod
+++ b/gcc/m2/gm2-compiler/M2GCCDeclare.mod
@@ -401,7 +401,7 @@ BEGIN
 
       tobesolvedbyquads :  doInclude(ToBeSolvedByQuads, "symbol %d -> ToBeSolvedByQuads\n", sym) |
       fullydeclared     :  doInclude(FullyDeclared, "symbol %d -> FullyDeclared\n", sym) ;
-                           IF sym=449
+                           IF sym=1265
                            THEN
                               mystop
                            END |
@@ -2782,6 +2782,7 @@ PROCEDURE StartDeclareScope (scope: CARDINAL) ;
 VAR
    n: Name ;
 BEGIN
+   (* AddSymToWatch (1265) ;  *)
    (* AddSymToWatch (1157) ;  *)  (* watch goes here *)
    (* AddSymToWatch(TryFindSymbol('IOLink', 'DeviceId')) ; *)
    (* AddSymToWatch(819) ; *)
diff --git a/gcc/m2/gm2-compiler/M2Options.def b/gcc/m2/gm2-compiler/M2Options.def
index 12086ecc909..5f2490e7cd9 100644
--- a/gcc/m2/gm2-compiler/M2Options.def
+++ b/gcc/m2/gm2-compiler/M2Options.def
@@ -83,7 +83,7 @@ EXPORT QUALIFIED SetReturnCheck, SetNilCheck, SetCaseCheck,
                  DebugBuiltins, setdefextension, setmodextension,
                  SetStatistics, SetWall, SetSaveTemps, SetSaveTempsDir,
                  SaveTemps, GenModuleList,
-                 CppProg, CppArg, CppCommandLine, CppRemember,
+                 CppArg, CppCommandLine, CppRemember,
 		 SetDebugFunctionLineNumbers, DebugFunctionLineNumbers,
 		 SetGenerateStatementNote, GenerateStatementNote,
                  ScaffoldDynamic, ScaffoldStatic,
@@ -667,13 +667,6 @@ PROCEDURE SetStatistics (on: BOOLEAN) ;
 PROCEDURE SetVerbose (value: BOOLEAN) : BOOLEAN ;
 
 
-(*
-   CppProg - sets the cpp program to be, program.
-*)
-
-PROCEDURE CppProg (program: ADDRESS) ;
-
-
 (*
    CppArg - sets the option and arg in the cpp command line.
 *)
diff --git a/gcc/m2/gm2-compiler/SymbolTable.mod b/gcc/m2/gm2-compiler/SymbolTable.mod
index a63fa605c73..d04b3283a29 100644
--- a/gcc/m2/gm2-compiler/SymbolTable.mod
+++ b/gcc/m2/gm2-compiler/SymbolTable.mod
@@ -30,9 +30,12 @@ FROM libc IMPORT printf ;
 IMPORT Indexing ;
 FROM Indexing IMPORT InitIndex, InBounds, LowIndice, HighIndice, PutIndice, GetIndice ;
 FROM Sets IMPORT Set, InitSet, IncludeElementIntoSet, IsElementInSet ;
+FROM m2linemap IMPORT location_t ;
 
 FROM M2Options IMPORT Pedantic, ExtendedOpaque, DebugFunctionLineNumbers, ScaffoldDynamic ;
-FROM M2LexBuf IMPORT UnknownTokenNo, TokenToLineNo, FindFileNameFromToken ;
+
+FROM M2LexBuf IMPORT UnknownTokenNo, TokenToLineNo,
+                     FindFileNameFromToken, TokenToLocation ;
 
 FROM M2ALU IMPORT InitValue, PtrToValue, PushCard, PopInto,
                   PushString, PushFrom, PushChar, PushInt,
@@ -4614,7 +4617,7 @@ VAR
 BEGIN
    IF constType=NulSym
    THEN
-      constType := GetConstLitType (constName)
+      constType := GetConstLitType (tok, constName)
    END ;
    NewSym (Sym) ;
    pSym := GetPsym (Sym) ;
@@ -4624,7 +4627,7 @@ BEGIN
 
       ConstLitSym : ConstLit.name := constName ;
                     ConstLit.Value := InitValue () ;
-                    PushString (constName) ;
+                    PushString (tok, constName) ;
                     PopInto (ConstLit.Value) ;
                     ConstLit.Type := constType ;
                     ConstLit.IsSet := FALSE ;
@@ -6216,8 +6219,9 @@ END IsHiddenType ;
                      depending upon their value.
 *)
 
-PROCEDURE GetConstLitType (name: Name) : CARDINAL ;
+PROCEDURE GetConstLitType (tok: CARDINAL; name: Name) : CARDINAL ;
 VAR
+   loc          : location_t ;
    s            : String ;
    needsLong,
    needsUnsigned: BOOLEAN ;
@@ -6233,17 +6237,18 @@ BEGIN
          s := KillString (s) ;
          RETURN RType
       END ;
+      loc := TokenToLocation (tok) ;
       CASE char (s, -1) OF
 
-      'H':  DetermineSizeOfConstant (string (s), 16,
+      'H':  DetermineSizeOfConstant (loc, string (s), 16,
                                      needsLong, needsUnsigned) |
-      'B':  DetermineSizeOfConstant (string (s), 8,
+      'B':  DetermineSizeOfConstant (loc, string (s), 8,
                                      needsLong, needsUnsigned) |
-      'A':  DetermineSizeOfConstant (string (s), 2,
+      'A':  DetermineSizeOfConstant (loc, string (s), 2,
                                      needsLong, needsUnsigned)
 
       ELSE
-         DetermineSizeOfConstant (string (s), 10,
+         DetermineSizeOfConstant (loc, string (s), 10,
                                   needsLong, needsUnsigned)
       END ;
       s := KillString (s) ;
diff --git a/gcc/m2/gm2-gcc/m2decl.cc b/gcc/m2/gm2-gcc/m2decl.cc
index dd23c6ce0a3..86bd3ee48ff 100644
--- a/gcc/m2/gm2-gcc/m2decl.cc
+++ b/gcc/m2/gm2-gcc/m2decl.cc
@@ -284,22 +284,16 @@ m2decl_DeclareModuleCtor (tree decl)
    and needsUnsigned appropriately.  */
 
 void
-m2decl_DetermineSizeOfConstant (const char *str, unsigned int base,
+m2decl_DetermineSizeOfConstant (location_t location,
+				const char *str, unsigned int base,
                                 int *needsLong, int *needsUnsigned)
 {
-  int low;
+  unsigned int ulow;
   int high;
-  int overflow;
-
-  overflow
-      = m2expr_interpret_m2_integer (str, base, (unsigned int *)&low, &high);
-  *needsLong = (high != 0);
-  if (*needsLong)
-    *needsUnsigned = (high < 0);
-  else
-    *needsUnsigned = (low < 0);
+  int overflow = m2expr_interpret_m2_integer (str, base, &ulow, &high,
+					      needsLong, needsUnsigned);
   if (overflow)
-    error ("constant too large");
+    error_at (location, "constant %qs is too large", str);
 }
 
 /* BuildConstLiteralNumber - returns a GCC TREE built from the
@@ -307,7 +301,7 @@ m2decl_DetermineSizeOfConstant (const char *str, unsigned int base,
    Modula-2.  It always returns a positive value.  */
 
 tree
-m2decl_BuildConstLiteralNumber (const char *str, unsigned int base)
+m2decl_BuildConstLiteralNumber (location_t location, const char *str, unsigned int base)
 {
   tree value, type;
   unsigned HOST_WIDE_INT low;
@@ -322,7 +316,7 @@ m2decl_BuildConstLiteralNumber (const char *str, unsigned int base)
 
   widest_int wval = widest_int::from_array (ival, 3);
 
-  m2decl_DetermineSizeOfConstant (str, base, &needLong, &needUnsigned);
+  m2decl_DetermineSizeOfConstant (location, str, base, &needLong, &needUnsigned);
 
   if (needUnsigned && needLong)
     type = m2type_GetM2LongCardType ();
@@ -332,7 +326,7 @@ m2decl_BuildConstLiteralNumber (const char *str, unsigned int base)
   value = wide_int_to_tree (type, wval);
 
   if (overflow || m2expr_TreeOverflow (value))
-    error ("constant too large");
+    error_at (location, "constant %qs is too large", str);
 
   return m2block_RememberConstant (value);
 }
diff --git a/gcc/m2/gm2-gcc/m2decl.def b/gcc/m2/gm2-gcc/m2decl.def
index 3f4a1613fe9..eea0b117b8c 100644
--- a/gcc/m2/gm2-gcc/m2decl.def
+++ b/gcc/m2/gm2-gcc/m2decl.def
@@ -162,7 +162,8 @@ PROCEDURE RememberVariables (l: Tree) ;
                               needsLong and needsUnsigned appropriately.
 *)
 
-PROCEDURE DetermineSizeOfConstant (str: ADDRESS; base: CARDINAL;
+PROCEDURE DetermineSizeOfConstant (location: location_t;
+                                   str: ADDRESS; base: CARDINAL;
                                    VAR needsLong, needsUnsigned: BOOLEAN) ;
 
 
@@ -173,7 +174,8 @@ PROCEDURE DetermineSizeOfConstant (str: ADDRESS; base: CARDINAL;
                               positive value.
 *)
 
-PROCEDURE BuildConstLiteralNumber (str: ADDRESS; base: CARDINAL) : Tree ;
+PROCEDURE BuildConstLiteralNumber (location: location_t;
+                                   str: ADDRESS; base: CARDINAL) : Tree ;
 
 
 (*
diff --git a/gcc/m2/gm2-gcc/m2decl.h b/gcc/m2/gm2-gcc/m2decl.h
index f651042fef2..9b9805aaec4 100644
--- a/gcc/m2/gm2-gcc/m2decl.h
+++ b/gcc/m2/gm2-gcc/m2decl.h
@@ -43,9 +43,11 @@ EXTERN tree m2decl_DeclareModuleCtor (tree decl);
 EXTERN tree m2decl_GetDeclContext (tree t);
 EXTERN tree m2decl_BuildStringConstant (location_t location, const char *string, int length);
 EXTERN tree m2decl_BuildCStringConstant (const char *string, int length);
-EXTERN tree m2decl_BuildConstLiteralNumber (const char *str,
+EXTERN tree m2decl_BuildConstLiteralNumber (location_t location,
+					    const char *str,
                                             unsigned int base);
-EXTERN void m2decl_DetermineSizeOfConstant (const char *str, unsigned int base,
+EXTERN void m2decl_DetermineSizeOfConstant (location_t location,
+					    const char *str, unsigned int base,
                                             int *needsLong,
                                             int *needsUnsigned);
 EXTERN void m2decl_RememberVariables (tree l);
diff --git a/gcc/m2/gm2-gcc/m2expr.cc b/gcc/m2/gm2-gcc/m2expr.cc
index 115ff96fc52..4616835ba0d 100644
--- a/gcc/m2/gm2-gcc/m2expr.cc
+++ b/gcc/m2/gm2-gcc/m2expr.cc
@@ -3966,7 +3966,7 @@ m2expr_interpret_integer (const char *str, unsigned int base,
           else
             {
               overflow = append_digit (low, high, c, base);
-              max = 0; /* From now on we always use append_digit.  */
+              max = 0;  /* From now on we always use append_digit.  */
             }
         }
     }
@@ -3978,12 +3978,13 @@ m2expr_interpret_integer (const char *str, unsigned int base,
 
 static int
 append_m2_digit (unsigned int *low, int *high, unsigned int digit,
-                 unsigned int base)
+                 unsigned int base, int *needsUnsigned)
 {
   unsigned int shift;
   int overflow;
   int add_high, res_high, test_high;
   unsigned int add_low, res_low, test_low;
+  unsigned int add_uhigh, res_uhigh, test_uhigh;
 
   switch (base)
     {
@@ -4035,7 +4036,15 @@ append_m2_digit (unsigned int *low, int *high, unsigned int digit,
     add_high++;
   test_high = res_high + add_high;
   if (test_high < res_high)
-    overflow = TRUE;
+    {
+      res_uhigh = res_high;
+      add_uhigh = add_high;
+      test_uhigh = res_uhigh + add_uhigh;
+      if (test_uhigh < res_uhigh)
+	overflow = TRUE;
+      else
+	*needsUnsigned = TRUE;
+    }
 
   *low = res_low + add_low;
   *high = res_high + add_high;
@@ -4047,15 +4056,18 @@ append_m2_digit (unsigned int *low, int *high, unsigned int digit,
    constants.  Heavily borrowed from gcc/cppexp.cc.  Note that this is a
    copy of the above code except that it uses `int' rather than
    HOST_WIDE_INT to allow gm2 to determine what Modula-2 base type to
-   use for this constant.  */
+   use for this constant and it also sets needsLong and needsUnsigned
+   if an overflow can be avoided by using these techniques.  */
 
 int
 m2expr_interpret_m2_integer (const char *str, unsigned int base,
-                             unsigned int *low, int *high)
+                             unsigned int *low, int *high,
+			     int *needsLong, int *needsUnsigned)
 {
   const unsigned char *p, *end;
-  int overflow = FALSE;
   int len;
+  *needsLong = FALSE;
+  *needsUnsigned = FALSE;
 
   *low = 0;
   *high = 0;
@@ -4083,19 +4095,22 @@ m2expr_interpret_m2_integer (const char *str, unsigned int base,
           if (ISDIGIT (c) || (base == 16 && ISXDIGIT (c)))
             c = hex_value (c);
           else
-            return overflow;
+            return FALSE;  /* End of string and no overflow found.  */
 
           /* Strict inequality for when max is set to zero.  */
           if (*low < max)
             *low = (*low) * base + c;
           else
             {
-              overflow = append_m2_digit (low, high, c, base);
-              max = 0; /* From now on we always use append_digit.  */
+	      *needsLong = TRUE;
+	      if (append_m2_digit (low, high, c, base,
+				   needsUnsigned))
+		return TRUE;  /* We have overflowed so bail out.  */
+              max = 0;  /* From now on we always use append_digit.  */
             }
         }
     }
-  return overflow;
+  return FALSE;
 }
 
 /* GetSizeOfInBits return the number of bits used to contain, type.  */
diff --git a/gcc/m2/gm2-gcc/m2expr.h b/gcc/m2/gm2-gcc/m2expr.h
index ab6457ecded..a2156e1bc32 100644
--- a/gcc/m2/gm2-gcc/m2expr.h
+++ b/gcc/m2/gm2-gcc/m2expr.h
@@ -128,7 +128,8 @@ EXTERN int m2expr_interpret_integer (const char *str, unsigned int base,
                                      unsigned HOST_WIDE_INT *low,
                                      HOST_WIDE_INT *high);
 EXTERN int m2expr_interpret_m2_integer (const char *str, unsigned int base,
-                                        unsigned int *low, int *high);
+                                        unsigned int *low, int *high,
+					int *needsLong, int *needsUnsigned);
 
 EXTERN tree m2expr_BuildAddCheck (location_t location, tree op1, tree op2,
                                   tree lowest, tree min, tree max);
diff --git a/gcc/m2/mc/decl.mod b/gcc/m2/mc/decl.mod
index b258cdd3a55..0be1d2d3476 100644
--- a/gcc/m2/mc/decl.mod
+++ b/gcc/m2/mc/decl.mod
@@ -12710,6 +12710,7 @@ BEGIN
              visitNode (v, right, p) ;
              visitNode (v, resultType, p)
            END |
+   length,
    adr,
    size,
    tsize,
@@ -12727,10 +12728,6 @@ BEGIN
              visitNode (v, arg, p) ;
              visitNode (v, resultType, p)
           END |
-   length: WITH n^.unaryF DO
-             visitNode (v, arg, p) ;
-             visitNode (v, resultType, p)
-           END |
    throw:  WITH n^.intrinsicF DO
               visitNode (v, args, p) ;
               visitNode (v, type, p)

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-09-05 14:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-05 14:42 [gcc/devel/modula-2] Bugfix constant overflow detection and improved error messages Gaius Mulley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).