From adc90f13abe835bb5b6cf23ec00e516877c3f5d7 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 25 Aug 2005 06:11:35 +0000 Subject: [PATCH] * data/glr.c (yyrecoverSyntaxError, yyreturn): Don't invoke destructor on unresolved entries. * tests/glr-regression.at (User destructor for unresolved GLR semantic value): New test case. Problem reported by Joel E. Denny in: http://lists.gnu.org/archive/html/bison-patches/2005-08/msg00016.html --- ChangeLog | 9 ++++++ data/glr.c | 14 +++++---- tests/glr-regression.at | 70 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4ce49dff..0b99e468 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2005-08-24 Paul Eggert + + * data/glr.c (yyrecoverSyntaxError, yyreturn): + Don't invoke destructor on unresolved entries. + * tests/glr-regression.at + (User destructor for unresolved GLR semantic value): New test case. + Problem reported by Joel E. Denny in: + http://lists.gnu.org/archive/html/bison-patches/2005-08/msg00016.html + 2005-08-21 Paul Eggert * lib/.cvsignore: Remove realloc.c, strncasecmp.c, xstrdup.c. diff --git a/data/glr.c b/data/glr.c index 2d1cbc42..16608b61 100644 --- a/data/glr.c +++ b/data/glr.c @@ -1981,9 +1981,10 @@ yyrecoverSyntaxError (yyGLRStack* yystack, } } ]b4_location_if([[ yystack->yyerror_range[1].yystate.yyloc = yys->yyloc;]])[ - yydestruct ("Error: popping", - yystos[yys->yylrState], - &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[); + if (yys->yyresolved) + yydestruct ("Error: popping", + yystos[yys->yylrState], + &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[); yystack->yytops.yystates[0] = yys->yypred; yystack->yynextFree -= 1; yystack->yyspaceLeft += 1; @@ -2183,9 +2184,10 @@ b4_syncline([@oline@], [@ofile@])])dnl { yyGLRState *yys = yystates[0]; ]b4_location_if([[ yystack.yyerror_range[1].yystate.yyloc = yys->yyloc;]] -)[ yydestruct ("Cleanup: popping", - yystos[yys->yylrState], - &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[); +)[ if (yys->yyresolved) + yydestruct ("Cleanup: popping", + yystos[yys->yylrState], + &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[); yystates[0] = yys->yypred; yystack.yynextFree -= 1; yystack.yyspaceLeft += 1; diff --git a/tests/glr-regression.at b/tests/glr-regression.at index 91768a19..a2d3ce76 100644 --- a/tests/glr-regression.at +++ b/tests/glr-regression.at @@ -420,3 +420,73 @@ AT_CHECK([[./glr-regr4]], 0, ]], []) AT_CLEANUP + + +## ---------------------------------------------------------------------- ## +## User destructor for unresolved GLR semantic value ## +## Thanks to Joel E. Denny for this test; see ## +## . ## +## ---------------------------------------------------------------------- ## + +AT_SETUP([User destructor for unresolved GLR semantic value]) + +AT_DATA_GRAMMAR([glr-regr5.y], +[[%{ + #include + #include + static void yyerror (char const *); + static int yylex (void); + enum { MAGIC_VALUE = -1057808125 }; /* originally chosen at random */ +%} + +%glr-parser +%union { int value; } +%type start + +%destructor { + if ($$ != MAGIC_VALUE) + { + fprintf (stderr, "Bad destructor call.\n"); + exit (EXIT_FAILURE); + } +} start + +%% + +start: + 'a' { $$ = MAGIC_VALUE; } + | 'a' { $$ = MAGIC_VALUE; } + ; + +%% + +static int +yylex (void) +{ + static char const *input = "a"; + return *input++; +} + +static void +yyerror (char const *msg) +{ + printf ("%s\n", msg); +} + +int +main (void) +{ + return yyparse () != 1; +} +]]) + +AT_CHECK([[bison -o glr-regr5.c glr-regr5.y]], 0, [], +[glr-regr5.y: conflicts: 1 reduce/reduce +]) +AT_COMPILE([glr-regr5]) + +AT_CHECK([[./glr-regr5]], 0, +[syntax is ambiguous +]) + +AT_CLEANUP -- 2.45.2