bug-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bison-2.6.4-generated parser triggers pragma warnings in GCC 4.6.3


From: Akim Demaille
Subject: Re: bison-2.6.4-generated parser triggers pragma warnings in GCC 4.6.3
Date: Sun, 28 Oct 2012 18:23:16 +0100

Le 26 oct. 2012 à 19:21, Paul Eggert a écrit :

> That looks good to me.  Thanks for all the work you've been doing!

Well, I should have spotted it earlier :(

I installed a slightly modified version which uses a
common macro for both yylval and yylloc:

commit a68b1f237e63c96ee905916424013f79d01908ba
Author: Akim Demaille <address@hidden>
Date:   Fri Oct 26 11:25:41 2012 +0200

    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.

diff --git a/NEWS b/NEWS
index 895f55d..8c5bf59 100644
--- 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]
 
diff --git a/data/c.m4 b/data/c.m4
index 561900a..136b46e 100644
--- 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
+])
diff --git a/data/glr.c b/data/glr.c
index 79d6ffd..89a76e3 100644
--- a/data/glr.c
+++ b/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
diff --git a/data/yacc.c b/data/yacc.c
index 3b111d1..5d68bd4 100644
--- a/data/yacc.c
+++ b/data/yacc.c
@@ -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.  */




reply via email to

[Prev in Thread] Current Thread [Next in Thread]