mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 20:33:03 +00:00
lalr1, yacc: use the default location as initial error location
Currently lalr1.cc makes an out-of-bound access when trying to read @1 in rules with an empty rhs (i.e., when there is no @1) that raises an error (YYERROR). glr.c already gracefully handles this by using @$ as initial location for the errors. Let's do that in yacc.c and lalr1.cc. * data/lalr1.cc, data/yacc.c: Use @$ to initialize the error location. * tests/actions.at: Check that case.
This commit is contained in:
@@ -848,6 +848,7 @@ b4_dollar_popdef])[]dnl
|
||||
{
|
||||
slice<stack_symbol_type, stack_type> slice (yystack_, yylen);
|
||||
YYLLOC_DEFAULT (yylhs.location, slice, yylen);
|
||||
yyerror_range[1].location = yylhs.location;
|
||||
}]])[
|
||||
|
||||
// Perform the reduction.
|
||||
@@ -918,8 +919,7 @@ b4_dollar_popdef])[]dnl
|
||||
YYERROR and the label yyerrorlab therefore never appears in user
|
||||
code. */
|
||||
if (false)
|
||||
goto yyerrorlab;]b4_locations_if([[
|
||||
yyerror_range[1].location = yystack_[yylen - 1].location;]])[
|
||||
goto yyerrorlab;
|
||||
/* Do not reclaim the symbols of the rule whose action triggered
|
||||
this YYERROR. */
|
||||
yypop_ (yylen);
|
||||
|
||||
@@ -1641,8 +1641,9 @@ yyreduce:
|
||||
yyval = yyvsp[1-yylen];
|
||||
|
||||
]b4_locations_if(
|
||||
[[ /* Default location. */
|
||||
YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);]])[
|
||||
[[ /* Default location. */
|
||||
YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
|
||||
yyerror_range[1] = yyloc;]])[
|
||||
YY_REDUCE_PRINT (yyn);]b4_lac_if([[
|
||||
{
|
||||
int yychar_backup = yychar;
|
||||
@@ -1782,8 +1783,7 @@ yyerrorlab:
|
||||
if (/*CONSTCOND*/ 0)
|
||||
goto yyerrorlab;
|
||||
|
||||
]b4_locations_if([[ yyerror_range[1] = yylsp[1-yylen];
|
||||
]])[ /* Do not reclaim the symbols of the rule whose action triggered
|
||||
/* Do not reclaim the symbols of the rule whose action triggered
|
||||
this YYERROR. */
|
||||
YYPOPSTACK (yylen);
|
||||
yylen = 0;
|
||||
|
||||
Reference in New Issue
Block a user