mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
yacc.c: initialize yylval and yylloc.
When generating a pure push parser, the initialization of yylval and yylloc may not be visible to the compiler. With warnings enabled, GCC 4.3.6, 4.4.7, 4.5.4, and 4.6.3 report uninitialized uses of yylval/yylloc. Using local pragmas to disable these warnings is not supported before 4.6, and 4.6 does not support it properly. So initialize yylval and yylloc at their definition. Reported by Peter Simons. See http://lists.gnu.org/archive/html/bison-patches/2012-10/msg00133.html * data/c.m4 (b4_yyloc_default_define): New. * data/yacc.c: Use it when locations are requested. (YYLVAL_INITIALIZE): Replace by... (YY_INITIAL_VALUE): this. (yyparse): Initialize yylloc and yylval. Therefore, remove the initialization of yylloc's field. * data/glr.c: Likewise.
This commit is contained in:
21
data/glr.c
21
data/glr.c
@@ -223,11 +223,11 @@ b4_percent_code_get([[top]])[
|
||||
#endif
|
||||
|
||||
/* Default (constant) value used for initialization for null
|
||||
right-hand sides. Unlike the standard yacc.c template,
|
||||
here we set the default value of $$ to a zeroed-out value.
|
||||
Since the default value is undefined, this behavior is
|
||||
technically correct. */
|
||||
static YYSTYPE yyval_default;
|
||||
right-hand sides. Unlike the standard yacc.c template, here we set
|
||||
the default value of $$ to a zeroed-out value. Since the default
|
||||
value is undefined, this behavior is technically correct. */
|
||||
static YYSTYPE yyval_default;]b4_locations_if([
|
||||
b4_yyloc_default_define])[
|
||||
|
||||
/* Copy the second part of user declarations. */
|
||||
]b4_user_post_prologue
|
||||
@@ -2295,14 +2295,9 @@ yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
|
||||
YYDPRINTF ((stderr, "Starting parse\n"));
|
||||
|
||||
yychar = YYEMPTY;
|
||||
yylval = yyval_default;
|
||||
]b4_locations_if([
|
||||
#if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL
|
||||
yylloc.first_line = yylloc.last_line = ]b4_location_initial_line[;
|
||||
yylloc.first_column = yylloc.last_column = ]b4_location_initial_column[;
|
||||
#endif
|
||||
])
|
||||
m4_ifdef([b4_initial_action], [
|
||||
yylval = yyval_default;]b4_locations_if([
|
||||
yylloc = yyloc_default;])[
|
||||
]m4_ifdef([b4_initial_action], [
|
||||
b4_dollar_pushdef([yylval], [], [yylloc])dnl
|
||||
/* User initialization code. */
|
||||
b4_user_initial_action
|
||||
|
||||
Reference in New Issue
Block a user