summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkim Demaille <akim@lrde.epita.fr>2013-07-25 16:04:26 +0200
committerAkim Demaille <akim@lrde.epita.fr>2013-07-25 17:53:59 +0200
commitd3ae5af6ec7dbcfa2c7dce1a175e35934b85b274 (patch)
tree616299a64960026022539cf8fc4cb103a52e38a0
parent41dfa1cbf08eb5b6078cdbfad6a940191a7a7618 (diff)
downloadbison-d3ae5af6ec7dbcfa2c7dce1a175e35934b85b274.tar.gz
yacc: beware of "uninitialized uses" warnings
Again some issues with the fact that yylval is reported by GCC as possibly not initialized in some cases. Here, the case at hand is the %destructor. I am still not convinced that it is worth going all the trouble of using pragmas to disable temporarily some warnings, instead of just initializing the looking symbol once for all, but that's what Paul voted for, see <http://lists.gnu.org/archive/html/bison-patches/2012-10/msg00050.html>. * data/c.m4 (b4_attribute_define): Define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN, YY_IGNORE_MAYBE_UNINITIALIZED_END, YY_INITIAL_VALUE here, as we will need them in the generation of the destructor function, which is defined in yacc.c before yyparse, which was in charge of defining these macros. * data/yacc.c (b4_declare_scanner_communication_variables): Simplify: trying to factor the definitions of the case pure and impure is too complex. Actually, it is not even clear that this macro should really exist, as even the calls are complex. Be careful not to issue a lone ";", as this is a statement, and C90 forbids declarations after statements ; so write "YY_INITIAL_VALUE(Decl;)", not "YY_INITIAL_VALUE(Decl);".
-rw-r--r--data/c.m427
-rw-r--r--data/yacc.c35
2 files changed, 33 insertions, 29 deletions
diff --git a/data/c.m4 b/data/c.m4
index abc769b9..b1b43948 100644
--- a/data/c.m4
+++ b/data/c.m4
@@ -221,6 +221,25 @@ m4_define([b4_attribute_define],
#else
# define YYUSE(E) /* empty */
#endif
+
+#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
+/* Suppress an incorrect diagnostic about yylval being uninitialized. */
+# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
+ _Pragma ("GCC diagnostic push") \
+ _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
+ _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
+# define YY_IGNORE_MAYBE_UNINITIALIZED_END \
+ _Pragma ("GCC diagnostic pop")
+#else
+# define YY_INITIAL_VALUE(Value) Value
+#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
])
@@ -446,7 +465,9 @@ m4_ifset([b4_parse_param], [, b4_parse_param]))[
yymsg = "Deleting";
YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
+ YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
]b4_symbol_actions([destructor])[
+ YY_IGNORE_MAYBE_UNINITIALIZED_END
}]dnl
])
@@ -456,9 +477,9 @@ m4_ifset([b4_parse_param], [, b4_parse_param]))[
# Define the "yy_symbol_print" function.
m4_define_default([b4_yy_symbol_print_define],
[[
-/*--------------------------------.
-| Print this symbol on YYOUTPUT. |
-`--------------------------------*/
+/*----------------------------------------.
+| Print this symbol's value on YYOUTPUT. |
+`----------------------------------------*/
]b4_function_define([yy_symbol_value_print],
[static void],
diff --git a/data/yacc.c b/data/yacc.c
index ab8a1f7f..822656b8 100644
--- a/data/yacc.c
+++ b/data/yacc.c
@@ -175,36 +175,19 @@ m4_define([b4_declare_scanner_communication_variables], [[
int yychar;
]b4_pure_if([[
-#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
-/* Suppress an incorrect diagnostic about yylval being uninitialized. */
-# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
- _Pragma ("GCC diagnostic push") \
- _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
- _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
-# define YY_IGNORE_MAYBE_UNINITIALIZED_END \
- _Pragma ("GCC diagnostic pop")
-#else
+/* The semantic value of the lookahead symbol. */
/* Default value used for initialization, for pacifying older GCCs
or non-GCC compilers. */
-static YYSTYPE yyval_default;
-# define YY_INITIAL_VALUE(Value) = Value
-#endif]b4_locations_if([[
-static YYLTYPE yyloc_default][]b4_yyloc_default[;]])])[
-#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 YY_INITIAL_VALUE (yyval_default);]b4_locations_if([[
+YY_INITIAL_VALUE (static YYSTYPE yyval_default;)
+YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default);]b4_locations_if([[
/* Location data for the lookahead symbol. */
-YYLTYPE yylloc]b4_pure_if([ = yyloc_default], [b4_yyloc_default])[;
-]])b4_pure_if([], [[
-
+static YYLTYPE yyloc_default]b4_yyloc_default[;
+YYLTYPE yylloc = yyloc_default;]])],
+[[/* The semantic value of the lookahead symbol. */
+YYSTYPE yylval;]b4_locations_if([[
+/* Location data for the lookahead symbol. */
+YYLTYPE yylloc]b4_yyloc_default[;]])[
/* Number of syntax errors so far. */
int yynerrs;]])])