]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR modula2/110019 Reported line numbers off by 1 when cpp invoked.
authorGaius Mulley <gaiusmod2@gmail.com>
Wed, 7 Jun 2023 00:21:19 +0000 (01:21 +0100)
committerGaius Mulley <gaiusmod2@gmail.com>
Wed, 7 Jun 2023 00:21:19 +0000 (01:21 +0100)
Fix off by one in m2.flex when the line number is set via cpp.

gcc/m2/ChangeLog:

PR modula2/110019
* gm2-compiler/SymbolKey.mod (SearchAndDo): Reformatted.
(ForeachNodeDo): Reformatted.
* gm2-compiler/SymbolTable.mod (AddListify): Join list
with "," or "and" if more than one word is in the list.
* m2.flex: Remove -1 from atoi(yytext) line number.

gcc/testsuite/ChangeLog:

PR modula2/110019
* gm2/cpp/fail/cpp-fail.exp: New test.
* gm2/cpp/fail/foocpp.mod: New test.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
gcc/m2/gm2-compiler/SymbolKey.mod
gcc/m2/gm2-compiler/SymbolTable.mod
gcc/m2/m2.flex
gcc/testsuite/gm2/cpp/fail/cpp-fail.exp [new file with mode: 0644]
gcc/testsuite/gm2/cpp/fail/foocpp.mod [new file with mode: 0644]

index b9fa87fa851896e97da191956a4c3a65d495fed2..fa112665be45290dbdddfe904734085b68e2c69a 100644 (file)
@@ -312,7 +312,7 @@ END SearchForAny ;
 
 PROCEDURE ForeachNodeDo (t: SymbolTree; P: PerformOperation) ;
 BEGIN
-   SearchAndDo(t^.Left, P)
+   SearchAndDo (t^.Left, P)
 END ForeachNodeDo ;
 
 
@@ -327,9 +327,9 @@ BEGIN
    IF t#NIL
    THEN
       WITH t^ DO
-         SearchAndDo(Right, P) ;
-         P(KeySym) ;
-         SearchAndDo(Left, P)
+         SearchAndDo (Right, P) ;
+         P (KeySym) ;
+         SearchAndDo (Left, P)
       END
    END
 END SearchAndDo ;
index f43a734acbe0d84b11cecf6f9c66e7f004e6c04a..1ea5fee9d3e1e15adb7ec98444630fb0b4a72a4b 100644 (file)
@@ -9028,12 +9028,16 @@ VAR
 PROCEDURE AddListify (sym: CARDINAL) ;
 BEGIN
    INC (ListifyWordCount) ;
-   IF ListifyWordCount = ListifyTotal
+   (* printf ("AddListify: ListifyWordCount = %d, ListifyTotal = %d\n",
+              ListifyWordCount, ListifyTotal) ;  *)
+   IF ListifyWordCount > 1
    THEN
-      ListifySentance := ConCat (ListifySentance, Mark (InitString (" and ")))
-   ELSIF ListifyWordCount > 1
-   THEN
-      ListifySentance := ConCat (ListifySentance, Mark (InitString (", ")))
+      IF ListifyWordCount = ListifyTotal
+      THEN
+         ListifySentance := ConCat (ListifySentance, Mark (InitString (" and ")))
+      ELSE
+         ListifySentance := ConCat (ListifySentance, Mark (InitString (", ")))
+      END
    END ;
    ListifySentance := ConCat (ListifySentance,
                               Mark (InitStringCharStar (KeyToCharStar (GetSymName (sym)))))
index 0f23a3585fd61d54e53fdf212f72989d78ad3c48..0e6b52c83915f725b7bf12178dceab39f1128f93 100644 (file)
@@ -163,7 +163,7 @@ extern  void  yylex                   (void);
 ^\#.*                      { consumeLine(); /* printf("found: %s\n", currentLine->linebuf); */ BEGIN LINE0; }
 \n\#.*                     { consumeLine(); /* printf("found: %s\n", currentLine->linebuf); */ BEGIN LINE0; }
 <LINE0>\#[ \t]*            { updatepos(); }
-<LINE0>[0-9]+[ \t]*\"      { updatepos(); lineno=atoi(yytext)-1; BEGIN LINE1; }
+<LINE0>[0-9]+[ \t]*\"      { updatepos(); lineno=atoi(yytext); BEGIN LINE1; }
 <LINE0>\n                  { m2flex_M2Error("missing initial quote after #line directive"); resetpos(); BEGIN INITIAL; }
 <LINE0>[^\n]
 <LINE1>[^\"\n]+            { m2flex_M2Error("missing final quote after #line directive"); resetpos(); BEGIN INITIAL; }
diff --git a/gcc/testsuite/gm2/cpp/fail/cpp-fail.exp b/gcc/testsuite/gm2/cpp/fail/cpp-fail.exp
new file mode 100644 (file)
index 0000000..343a396
--- /dev/null
@@ -0,0 +1,37 @@
+# Expect driver script for GCC Regression Tests
+# Copyright (C) 2003-2023 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
+# <http://www.gnu.org/licenses/>.
+
+# This file was written by Gaius Mulley (gaius.mulley@southwales.ac.uk)
+# for GNU Modula-2.
+
+if $tracelevel then {
+    strace $tracelevel
+}
+
+# load support procs
+load_lib gm2-torture.exp
+
+gm2_init_pim "${srcdir}/gm2/pim/fail" -fcpp
+
+foreach testcase [lsort [glob -nocomplain $srcdir/$subdir/foocpp.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-fail $testcase
+}
diff --git a/gcc/testsuite/gm2/cpp/fail/foocpp.mod b/gcc/testsuite/gm2/cpp/fail/foocpp.mod
new file mode 100644 (file)
index 0000000..8d95fc0
--- /dev/null
@@ -0,0 +1,5 @@
+MODULE foo;
+
+BEGIN
+  i := 0;
+END foo.