]> git.saurik.com Git - bison.git/commitdiff
yacc.c: initialize yylval and yylloc.
authorAkim Demaille <akim@lrde.epita.fr>
Fri, 26 Oct 2012 09:25:41 +0000 (11:25 +0200)
committerAkim Demaille <akim@lrde.epita.fr>
Sun, 28 Oct 2012 15:53:18 +0000 (16:53 +0100)
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.

NEWS
data/c.m4
data/glr.c
data/yacc.c

diff --git a/NEWS b/NEWS
index 895f55db559e245492b3deb5a74c7669d8eabd06..8c5bf593807fe7dc312af5c55c53b666b69ee1a5 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,17 @@ GNU Bison NEWS
 
 * Noteworthy changes in release ?.? (????-??-??) [?]
 
+  We consider compiler warnings about Bison generated parsers to be bugs.
+  Rather than working around them in your own project, please consider
+  reporting them to us.
+
+** Bug fixes
+
+  Warnings about uninitialized yylval and/or yylloc for push parsers with a
+  pure interface have been fixed for GCC 4.0 up to 4.8, and Clang 2.9 to
+  3.2.
+
+  Other issues in the test suite have been addressed.
 
 * Noteworthy changes in release 2.6.4 (2012-10-23) [stable]
 
index 561900afe8c6fd23f676506ada13b35bff8b45f3..136b46e105ecb305bdbedb3955cf3711f12e3217 100644 (file)
--- a/data/c.m4
+++ b/data/c.m4
@@ -643,3 +643,19 @@ m4_define([b4_yylloc_default_define],
     while (YYID (0))
 #endif
 ]])
+
+# b4_yyloc_default_define
+# ------------------------
+# Define yyloc_default, which can be used to initialize location
+# variables.
+m4_define([b4_yyloc_default_define],
+[[static YYLTYPE yyloc_default
+# if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL
+  = { ]m4_join([, ],
+               m4_defn([b4_location_initial_line]),
+               m4_defn([b4_location_initial_column]),
+               m4_defn([b4_location_initial_line]),
+               m4_defn([b4_location_initial_column]))[ }
+# endif
+  ;]dnl
+])
index 79d6ffd0cda269a4a0460cffb3cb7513ec902660..89a76e3e9ada3dc6c936b9d7880a76d2f6d54bcb 100644 (file)
@@ -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
index 3b111d123fda767347b1b4bc685274c8ceee23c8..5d68bd4e0ee058a8fc400f3750eb9630f746e287 100644 (file)
@@ -181,22 +181,23 @@ int yychar;
 #else
 /* Default value used for initialization, for pacifying older GCCs
    or non-GCC compilers.  */
-static YYSTYPE yyval_default;
-# define YYLVAL_INITIALIZE() (yylval = yyval_default)
+static YYSTYPE yyval_default;]b4_locations_if([
+b4_yyloc_default_define])[
+# define YY_INITIAL_VALUE(Value) = Value
 #endif]])[
-#ifndef YYLVAL_INITIALIZE
-# define YYLVAL_INITIALIZE()
-#endif
 #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
 # define YY_IGNORE_MAYBE_UNINITIALIZED_END
 #endif
+#ifndef YY_INITIAL_VALUE
+# define YY_INITIAL_VALUE(Value) /* Nothing. */
+#endif
 
 /* The semantic value of the lookahead symbol.  */
-YYSTYPE yylval;]b4_locations_if([[
+YYSTYPE yylval YY_INITIAL_VALUE(yyval_default);]b4_locations_if([[
 
 /* Location data for the lookahead symbol.  */
-YYLTYPE yylloc;]])b4_pure_if([], [[
+YYLTYPE yylloc YY_INITIAL_VALUE(yyloc_default);]])b4_pure_if([], [[
 
 /* Number of syntax errors so far.  */
 int yynerrs;]])])
@@ -1581,14 +1582,7 @@ b4_c_function_def([[yyparse]], [[int]], b4_parse_param)[
   yyssp = yyss;
   yyvsp = yyvs;]b4_locations_if([[
   yylsp = yyls;]])[
-
-  YYLVAL_INITIALIZE ();]b4_locations_if([[
-#if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL
-  /* Initialize the default location before parsing starts.  */
-  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],[
+]m4_ifdef([b4_initial_action],[
 b4_dollar_pushdef([m4_define([b4_dollar_dollar_used])yylval], [],
                   [m4_define([b4_at_dollar_used])yylloc])dnl
 /* User initialization code.  */