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: Fri, 26 Oct 2012 11:36:19 +0200

This is my proposal to fix (all) the remaining errors.  First,
its result on the Bison's own parser.

diff --git a/src/parse-gram.c b/src/parse-gram.c
index 4032c71..4e1f42a 100644
--- a/src/parse-gram.c
+++ b/src/parse-gram.c
@@ -1890,10 +1888,19 @@ int yychar;
 /* Default value used for initialization, for pacifying older GCCs
    or non-GCC compilers.  */
 static YYSTYPE yyval_default;
-# define YYLVAL_INITIALIZE() (yylval = yyval_default)
+# define YYLVAL_INITIALIZE = yyval_default
+static YYLTYPE yyloc_default
+# if defined GRAM_LTYPE_IS_TRIVIAL && GRAM_LTYPE_IS_TRIVIAL
+  = { 1, 1, 1, 1 }
+# endif
+  ;
+# define YYLLOC_INITIALIZE = yyloc_default
 #endif
 #ifndef YYLVAL_INITIALIZE
-# define YYLVAL_INITIALIZE()
+# define YYLVAL_INITIALIZE
+#endif
+#ifndef YYLLOC_INITIALIZE
+# define YYLLOC_INITIALIZE
 #endif
 #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
@@ -1901,10 +1908,10 @@ static YYSTYPE yyval_default;
 #endif
 
 /* The semantic value of the lookahead symbol.  */
-YYSTYPE yylval;
+YYSTYPE yylval YYLVAL_INITIALIZE;
 
 /* Location data for the lookahead symbol.  */
-YYLTYPE yylloc;
+YYLTYPE yylloc YYLLOC_INITIALIZE;
 
     /* Number of syntax errors so far.  */
     int yynerrs;
@@ -1993,11 +2000,5 @@ YYLTYPE yylloc;
   yyvsp = yyvs;
   yylsp = yyls;
 
-  YYLVAL_INITIALIZE ();
-#if defined GRAM_LTYPE_IS_TRIVIAL && GRAM_LTYPE_IS_TRIVIAL
-  /* Initialize the default location before parsing starts.  */
-  yylloc.first_line   = yylloc.last_line   = 1;
-  yylloc.first_column = yylloc.last_column = 1;
-#endif
 
 /* User initialization code.  */




commit d01fc6ad22e4f747d7e5652367178a4ea374244d
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.
    (YYLLOC_INITIALIZE): New.
    (YYLVAL_INITIALIZE): Redefine to be usable in a variable definition.
    (yyparse): Initialize yylloc and yylval.
    Therefore, remove the initialization of yylloc's field.
    * data/glr: Likewise.

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..871261d 100644
--- a/data/yacc.c
+++ b/data/yacc.c
@@ -182,21 +182,26 @@ int yychar;
 /* Default value used for initialization, for pacifying older GCCs
    or non-GCC compilers.  */
 static YYSTYPE yyval_default;
-# define YYLVAL_INITIALIZE() (yylval = yyval_default)
+# define YYLVAL_INITIALIZE = yyval_default]b4_locations_if([[
+]b4_yyloc_default_define[
+# define YYLLOC_INITIALIZE = yyloc_default]])[
 #endif]])[
 #ifndef YYLVAL_INITIALIZE
-# define YYLVAL_INITIALIZE()
-#endif
+# define YYLVAL_INITIALIZE
+#endif]b4_locations_if([[
+#ifndef YYLLOC_INITIALIZE
+# define YYLLOC_INITIALIZE
+#endif]])[
 #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
 # define YY_IGNORE_MAYBE_UNINITIALIZED_END
 #endif
 
 /* The semantic value of the lookahead symbol.  */
-YYSTYPE yylval;]b4_locations_if([[
+YYSTYPE yylval YYLVAL_INITIALIZE;]b4_locations_if([[
 
 /* Location data for the lookahead symbol.  */
-YYLTYPE yylloc;]])b4_pure_if([], [[
+YYLTYPE yylloc YYLLOC_INITIALIZE;]])b4_pure_if([], [[
 
 /* Number of syntax errors so far.  */
 int yynerrs;]])])
@@ -1582,13 +1587,7 @@ b4_c_function_def([[yyparse]], [[int]], b4_parse_param)[
   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]