[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [3.0.4] %printer/%destructor: simple backslashes in paths of #line s
From: |
Akim Demaille |
Subject: |
Re: [3.0.4] %printer/%destructor: simple backslashes in paths of #line statements not escaped |
Date: |
Sat, 18 Aug 2018 10:06:59 +0200 |
Hi!
> Le 4 mai 2017 à 22:55, Jannick <address@hidden> a écrit :
>
> Thanks, J.
This is the shortest (yet precise!) bug report I have ever seen!
Thanks for the report. I am installing this in Bison master. It should be
part of Bison 3.1.0.
Cheers!
commit adf0425d11fcb60a8171b1c004f1c013789d3a96
Author: Akim Demaille <address@hidden>
Date: Sat Aug 18 09:59:48 2018 +0200
escape properly the file names in #line for printer/destructor
Reported by Jannick.
http://lists.gnu.org/archive/html/bug-bison/2017-05/msg00001.html
"Amusingly" enough, we have the same problem with %defines when the
parser file name has backslashes or quotes: we generate #includes with
an incorrect C string.
* src/output.c (prepare_symbol_definitions): Escape properly the file
names before passing them to M4.
* data/bison.m4, data/lalr1.cc: Don't simply put the file name between
two quotes (that should have been strong enough a smell...), expect
the string to be properly quoted.
* tests/synclines.at: New tests to check this.
diff --git a/NEWS b/NEWS
index 9135184a..760f9399 100644
--- a/NEWS
+++ b/NEWS
@@ -86,6 +86,12 @@ GNU Bison NEWS
were issued with #lines in the middle of C code.
+*** Printer and destructor with broken #line directives
+
+ The #line directives were not properly escaped when emitting the code for
+ %printer/%destructor, which resulted in compiler errors if there are
+ backslashes or double-quotes in the grammar file name.
+
* Noteworthy changes in release 3.0.5 (2018-05-27) [stable]
** Bug fixes
diff --git a/THANKS b/THANKS
index 9d37dc84..9cf3ef22 100644
--- a/THANKS
+++ b/THANKS
@@ -64,6 +64,7 @@ Guido Trentalancia address@hidden
H. Merijn Brand address@hidden
Hans Åberg address@hidden
Jan Nieuwenhuizen address@hidden
+Jannick address@hidden
Jerry Quinn address@hidden
Jesse Thilo address@hidden
Jim Kent address@hidden
diff --git a/data/bison.m4 b/data/bison.m4
index 42bb67b8..80e025c9 100644
--- a/data/bison.m4
+++ b/data/bison.m4
@@ -444,7 +444,7 @@ m4_define([b4_symbol_action],
[m4_dquote(b4_symbol([$1], [type]))]),
[(*yylocationp)])dnl
b4_symbol_case_([$1])[]dnl
-b4_syncline([b4_symbol([$1], [$2_line])], ["b4_symbol([$1], [$2_file])"])
+b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])])
b4_symbol([$1], [$2])
b4_syncline(address@hidden@], address@hidden@])
break;
diff --git a/data/lalr1.cc b/data/lalr1.cc
index 053875de..a59ab213 100644
--- a/data/lalr1.cc
+++ b/data/lalr1.cc
@@ -107,7 +107,7 @@ b4_dollar_pushdef([yysym.value],
[m4_dquote(b4_symbol([$1], [type]))]),
[yysym.location])dnl
b4_symbol_case_([$1])
-b4_syncline([b4_symbol([$1], [$2_line])], ["b4_symbol([$1], [$2_file])"])
+b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])])
b4_symbol([$1], [$2])
b4_syncline(address@hidden@], address@hidden@])
break;
diff --git a/src/output.c b/src/output.c
index a28488ed..22c73f1c 100644
--- a/src/output.c
+++ b/src/output.c
@@ -442,7 +442,7 @@ prepare_symbol_definitions (void)
if (p->code)
{
SET_KEY2 (pname, "file");
- MUSCLE_INSERT_STRING (key, p->location.start.file);
+ MUSCLE_INSERT_C_STRING (key, p->location.start.file);
SET_KEY2 (pname, "line");
MUSCLE_INSERT_INT (key, p->location.start.line);
diff --git a/tests/synclines.at b/tests/synclines.at
index b76e47ab..45bac3c0 100644
--- a/tests/synclines.at
+++ b/tests/synclines.at
@@ -329,6 +329,97 @@ exp: '0';
[input.y:2: #error "2"
])
+## ---------------------- ##
+## %destructor syncline. ##
+## ---------------------- ##
+
+AT_TEST([%destructor syncline],
+[[%destructor {
+#error "2"
+} <ival>
+%{
+]AT_YYERROR_DECLARE_EXTERN[
+]AT_YYLEX_DECLARE_EXTERN[
+%}
+%union {
+ int ival;
+}
+%nterm <ival> exp
+%%
+exp: '0' { $$ = 0; };
+%%
+]],
+[input.y:2: #error "2"
+])
+
+
+## ------------------- ##
+## %printer syncline. ##
+## ------------------- ##
+
+AT_TEST([%printer syncline],
+[[%printer {
+#error "2"
+} <ival>
+%debug
+%code {
+ ]AT_YYERROR_DECLARE_EXTERN[
+ ]AT_YYLEX_DECLARE_EXTERN[
+}
+%union {
+ int ival;
+}
+%nterm <ival> exp
+%%
+exp: '0' { $$ = 0; };
+%%
+]],
+[input.y:2: #error "2"
+])
+
+m4_popdef([AT_TEST])
+
+
+
+## ------------------ ##
+## syncline escapes. ##
+## ------------------ ##
+
+# AT_TEST([SKELETON])
+# -------------------
+m4_pushdef([AT_TEST],
+[AT_SETUP([syncline escapes: $1])
+
+AT_BISON_OPTION_PUSHDEFS([%skeleton "$1"])
+AT_DATA_GRAMMAR([\"\\\"\".y],
+[[%skeleton "$1"
+%code {
+ ]AT_YYERROR_DECLARE[
+ ]AT_YYLEX_DECLARE[
+}
+%destructor {} <>
+%printer {} <>
+%%
+exp: '0'
+%%
+]AT_YYERROR_DEFINE[
+]AT_YYLEX_DEFINE[
+]AT_MAIN_DEFINE[
+]])
+
+AT_FULL_COMPILE([\"\\\"\"])
+AT_BISON_OPTION_POPDEFS
+
+AT_CLEANUP
+])
+
+AT_TEST([yacc.c])
+AT_TEST([glr.c])
+AT_TEST([lalr1.cc])
+AT_TEST([glr.cc])
+
+m4_popdef([AT_TEST])
+
## ----------- ##
- Re: [3.0.4] %printer/%destructor: simple backslashes in paths of #line statements not escaped,
Akim Demaille <=