[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bison core dump
From: |
Paul Eggert |
Subject: |
Re: bison core dump |
Date: |
Thu, 22 Jul 2004 07:46:29 -0700 |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) |
Peter Fales <address@hidden> writes:
> A user reported that the following bison program causes a segmentation
> violation (this is a stripped down example from the real program):
>
> %token TOK_HELLO
> %destructor { foo; } TOK_HELLO
> %%
> cmd: TOK_HELLO ;
Thanks for that bug report. It uncovered a combination of Bison
features that hasn't been tested, and had some other problems too.
I installed the following patch, which also adds some test cases.
2004-07-22 Paul Eggert <address@hidden>
Fix bug with non-%union parsers that have printers or destructors,
which led to a Bison core dump. Reported by Peter Fales in
<http://lists.gnu.org/archive/html/bug-bison/2004-07/msg00014.html>.
* data/c.m4 (b4_symbol_actions): Don't assume %union was used.
* data/lalr1.cc (yystype) [defined YYSTYPE]: Define to YYSTYPE,
not to our own type.
* src/output.c (symbol_destructors_output, symbol_printers_output):
Don't assume %union.
* tests/actions.at (_AT_CHECK_PRINTER_AND_DESTRUCTOR,
AT_CHECK_PRINTER_AND_DESTRUCTOR): New argument
UNION-FLAG. All callers changed.
(_AT_CHECK_PRINTER_AND_DESTRUCTOR): Don't assume %union.
Use type char, not unsigned int, when declaring an array of char;
this lets us remove a cast.
(Printers and Destructors): Add non-%union test cases.
Index: data/c.m4
===================================================================
RCS file: /cvsroot/bison/bison/data/c.m4,v
retrieving revision 1.22
diff -p -u -r1.22 c.m4
--- data/c.m4 31 Mar 2004 00:37:20 -0000 1.22
+++ data/c.m4 22 Jul 2004 14:37:26 -0000
@@ -327,7 +327,8 @@ m4_define([b4_syncline],
# SYMBOL-ACTION, SYMBOL-TYPENAME)
# -------------------------------------------------
m4_define([b4_symbol_actions],
-[m4_pushdef([b4_dollar_dollar], [yyvaluep->$6])dnl
+[m4_pushdef([b4_dollar_dollar],
+ [m4_ifval([$6], [(yyvaluep->$6)], [(*yyvaluep)])])dnl
m4_pushdef([b4_at_dollar], [(*yylocationp)])dnl
case $4: /* $3 */
b4_syncline([$2], [$1])
Index: data/lalr1.cc
===================================================================
RCS file: /cvsroot/bison/bison/data/lalr1.cc,v
retrieving revision 1.46
diff -p -u -r1.46 lalr1.cc
--- data/lalr1.cc 21 Jun 2004 20:20:30 -0000 1.46
+++ data/lalr1.cc 22 Jul 2004 14:37:26 -0000
@@ -161,7 +161,9 @@ b4_syncline(address@hidden@], address@hidden@])[
# define YYERROR_VERBOSE ]b4_error_verbose[
#endif
-#ifndef YYSTYPE
+#ifdef YYSTYPE
+typedef YYSTYPE yystype;
+#else
]m4_ifdef([b4_stype],
[b4_syncline([b4_stype_line], [b4_filename])
typedef union b4_stype yystype;
Index: src/output.c
===================================================================
RCS file: /cvsroot/bison/bison/src/output.c,v
retrieving revision 1.226
diff -p -u -r1.226 output.c
--- src/output.c 21 Jun 2004 20:20:31 -0000 1.226
+++ src/output.c 22 Jul 2004 14:37:26 -0000
@@ -402,16 +402,18 @@ symbol_destructors_output (FILE *out)
/* Filename, lineno,
Symbol-name, Symbol-number,
- destructor, typename. */
+ destructor, optional typename. */
fprintf (out, "%s[", sep);
sep = ",\n";
escaped_file_name_output (out, sym->destructor_location.start.file);
- fprintf (out, ", [[%d]], [[%s]], [[%d]], [[%s]], [[%s]]]",
+ fprintf (out, ", [[%d]], [[%s]], [[%d]], [[%s]]",
sym->destructor_location.start.line,
sym->tag,
sym->number,
- sym->destructor,
- sym->type_name);
+ sym->destructor);
+ if (sym->type_name)
+ fprintf (out, ", [[%s]]", sym->type_name);
+ fputc (']', out);
}
fputs ("])\n\n", out);
}
@@ -435,16 +437,18 @@ symbol_printers_output (FILE *out)
/* Filename, lineno,
Symbol-name, Symbol-number,
- printer, typename. */
+ printer, optional typename. */
fprintf (out, "%s[", sep);
sep = ",\n";
escaped_file_name_output (out, sym->printer_location.start.file);
- fprintf (out, ", [[%d]], [[%s]], [[%d]], [[%s]], [[%s]]]",
+ fprintf (out, ", [[%d]], [[%s]], [[%d]], [[%s]]",
sym->printer_location.start.line,
sym->tag,
sym->number,
- sym->printer,
- sym->type_name);
+ sym->printer);
+ if (sym->type_name)
+ fprintf (out, ", [[%s]]", sym->type_name);
+ fputc (']', out);
}
fputs ("])\n\n", out);
}
Index: tests/actions.at
===================================================================
RCS file: /cvsroot/bison/bison/tests/actions.at,v
retrieving revision 1.32
diff -p -u -r1.32 actions.at
--- tests/actions.at 30 May 2004 00:56:55 -0000 1.32
+++ tests/actions.at 22 Jul 2004 14:37:26 -0000
@@ -304,13 +304,13 @@ AT_CLEANUP
## Printers and Destructors. ##
## -------------------------- ##
-# _AT_CHECK_PRINTER_AND_DESTRUCTOR($1, $2, $3, $4, BISON-DIRECTIVE)
-# -----------------------------------------------------------------
+# _AT_CHECK_PRINTER_AND_DESTRUCTOR($1, $2, $3, $4, BISON-DIRECTIVE, UNION-FLAG)
+# -----------------------------------------------------------------------------
m4_define([_AT_CHECK_PRINTER_AND_DESTRUCTOR],
[m4_if([$1$2$3], $[1]$[2]$[3], [],
[m4_fatal([$0: Invalid arguments: address@hidden)])dnl
-AT_SETUP([Printers and Destructors: $5])
+AT_SETUP([Printers and Destructors $6: $5])
# Make sure complex $n work.
@@ -328,18 +328,19 @@ AT_DATA_GRAMMAR([[input.y]],
%debug
%verbose
%locations
-%union
+]m4_ifval([$6], [%union
{
int ival;
-}
-
+}])
+[
%{
-]AT_LALR1_CC_IF([typedef yy::Location YYLTYPE;])
+]AT_LALR1_CC_IF([typedef yy::Location YYLTYPE;
+m4_ifval([$6], , [#define YYSTYPE int])])
[static int yylex (]AT_LEX_FORMALS[);
]AT_LALR1_CC_IF([], [static void yyerror (const char *msg);])
[%}
-%type <ival> 'x' ';' thing line input
+]m4_ifval([$6], [%type <ival> 'x' ';' thing line input])[
%printer { fprintf (yyoutput, "address@hidden", $$, RANGE (@$)); }
input line thing 'x'
@@ -416,7 +417,7 @@ thing:
static int
yylex (]AT_LEX_FORMALS[)
{
- static const unsigned int input[] =
+ static const char input[] =
{
/* Exercise the discarding of stack top and input until `error'
can be reduced. */
@@ -433,21 +434,21 @@ yylex (]AT_LEX_FORMALS[)
if (counter < (sizeof(input) / sizeof (input[0])))
{
]AT_LALR1_CC_IF(
-[ yylval->ival = counter;
+[ int c = m4_ifval([$6], [yylval->ival], [*yylval]) = counter++;
/* As in BASIC, line numbers go from 10 to 10. */
- yylloc->begin.line = yylloc->begin.column = 10 * counter;
+ yylloc->begin.line = yylloc->begin.column = 10 * c;
yylloc->end.line = yylloc->end.column = yylloc->begin.line + 9;
printf ("sending: '%c' (address@hidden)\n",
- input[[counter]], yylval->ival, RANGE (*yylloc));
- return (int) input[[counter++]];
+ input[[c]], c, RANGE (*yylloc));
+ return input[[c]];
],
-[ yylval.ival = counter;
+[ int c = m4_ifval([$6], [yylval.ival], [yylval]) = counter++;
/* As in BASIC, line numbers go from 10 to 10. */
- yylloc.first_line = yylloc.first_column = 10 * counter;
+ yylloc.first_line = yylloc.first_column = 10 * c;
yylloc.last_line = yylloc.last_column = yylloc.first_line + 9;
printf ("sending: '%c' (address@hidden)\n",
- input[[counter]], yylval.ival, RANGE (yylloc));
- return (int) input[[counter++]];
+ input[[c]], c, RANGE (yylloc));
+ return input[[c]];
])[
}
else
@@ -547,16 +548,20 @@ AT_CLEANUP
])
-# AT_CHECK_PRINTER_AND_DESTRUCTOR([BISON-OPTIONS])
-# ------------------------------------------------
+# AT_CHECK_PRINTER_AND_DESTRUCTOR([BISON-OPTIONS], [UNION-FLAG])
+# --------------------------------------------------------------
# Produce `calc.y'.
m4_define([AT_CHECK_PRINTER_AND_DESTRUCTOR],
-[_AT_CHECK_PRINTER_AND_DESTRUCTOR($[1], $[2], $[3], $[4], [$1])
+[_AT_CHECK_PRINTER_AND_DESTRUCTOR($[1], $[2], $[3], $[4], [$1], [$2])
])
-AT_CHECK_PRINTER_AND_DESTRUCTOR()
+AT_CHECK_PRINTER_AND_DESTRUCTOR([])
+AT_CHECK_PRINTER_AND_DESTRUCTOR([], [with union])
AT_CHECK_PRINTER_AND_DESTRUCTOR([%locations %defines %skeleton "lalr1.cc"])
+AT_CHECK_PRINTER_AND_DESTRUCTOR([%locations %defines %skeleton "lalr1.cc"],
+ [with union])
-# FIXME. This test case fails.
+# FIXME. These test cases fail.
#AT_CHECK_PRINTER_AND_DESTRUCTOR([%glr-parser])
+#AT_CHECK_PRINTER_AND_DESTRUCTOR([%glr-parser], [with union])
- bison core dump, Peter Fales, 2004/07/15
- Re: bison core dump,
Paul Eggert <=