From: Gaius Mulley Date: Wed, 7 Jun 2023 00:21:19 +0000 (+0100) Subject: PR modula2/110019 Reported line numbers off by 1 when cpp invoked. X-Git-Tag: basepoints/gcc-15~8551 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=29c82c6ca929e0f5eccfe038dea71177d814c6b7;p=thirdparty%2Fgcc.git PR modula2/110019 Reported line numbers off by 1 when cpp invoked. 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 --- diff --git a/gcc/m2/gm2-compiler/SymbolKey.mod b/gcc/m2/gm2-compiler/SymbolKey.mod index b9fa87fa8518..fa112665be45 100644 --- a/gcc/m2/gm2-compiler/SymbolKey.mod +++ b/gcc/m2/gm2-compiler/SymbolKey.mod @@ -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 ; diff --git a/gcc/m2/gm2-compiler/SymbolTable.mod b/gcc/m2/gm2-compiler/SymbolTable.mod index f43a734acbe0..1ea5fee9d3e1 100644 --- a/gcc/m2/gm2-compiler/SymbolTable.mod +++ b/gcc/m2/gm2-compiler/SymbolTable.mod @@ -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))))) diff --git a/gcc/m2/m2.flex b/gcc/m2/m2.flex index 0f23a3585fd6..0e6b52c83915 100644 --- a/gcc/m2/m2.flex +++ b/gcc/m2/m2.flex @@ -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; } \#[ \t]* { updatepos(); } -[0-9]+[ \t]*\" { updatepos(); lineno=atoi(yytext)-1; BEGIN LINE1; } +[0-9]+[ \t]*\" { updatepos(); lineno=atoi(yytext); BEGIN LINE1; } \n { m2flex_M2Error("missing initial quote after #line directive"); resetpos(); BEGIN INITIAL; } [^\n] [^\"\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 index 000000000000..343a3960c773 --- /dev/null +++ b/gcc/testsuite/gm2/cpp/fail/cpp-fail.exp @@ -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 +# . + +# 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 index 000000000000..8d95fc05751c --- /dev/null +++ b/gcc/testsuite/gm2/cpp/fail/foocpp.mod @@ -0,0 +1,5 @@ +MODULE foo; + +BEGIN + i := 0; +END foo.