bison-patches
[Top][All Lists]
Advanced

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

{maint} yacc.c: initialize yylval in pure-parser mode


From: Akim Demaille
Subject: {maint} yacc.c: initialize yylval in pure-parser mode
Date: Fri, 31 Aug 2012 18:02:36 +0200

Hi Paul,

I would very much like to have your opinion on this regard.
yacc.c has never initialized yylval, and this can actually
trigger warnings from GCC in some situations.  It turns out
that the test suite was avoiding this issue by disabling
the compilation flags that unhide the problem.

If the parser is not pure, then yylval is a global, and gcc
issues no such warning (since yylval is a global, the user might
have initialized it with a specific value and we should not
override it.  This is actually the case in one of our test cases
("Many lookahead tokens") for the push-parser where yylval is
initialized to an int before yyparse is called).

So it is only when the parser is pure that I wish to initialize
yylval.  What do you think about the attached patch?

Thanks in advance!

From 844e9773a77b5cf2ffe03de9b464a09536a19aa9 Mon Sep 17 00:00:00 2001
From: Akim Demaille <address@hidden>
Date: Sat, 31 Mar 2012 10:32:10 +0200
Subject: [PATCH] tests: do not disable -O flags

Tests are running without -O since
f377f69fec28013c79db4efe12bbb9d48987fb2c because some warnings (about
yylval not being initialized) show only when GCC is given -O2.

* data/yacc.c (b4_declare_scanner_communication_variables): As is
done in glr.c, initialize yylval with zeros when pure parser.
When not-pure, yylval might already have been initialized by the user,
do not try to override this value.
* tests/atlocal.in (O0CFLAGS, O0CXXFLAGS): Remove, use the
regular CFLAGS and CXXFLAGS.
---
 data/yacc.c      | 10 ++++++++--
 tests/atlocal.in | 11 ++---------
 2 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/data/yacc.c b/data/yacc.c
index 2c57f01..0a33734 100644
--- a/data/yacc.c
+++ b/data/yacc.c
@@ -166,12 +166,18 @@ m4_define([b4_rhs_location],
 # ------------------------------------------
 # Declare the variables that are global, or local to YYPARSE if
 # pure-parser.
+#
+# Do not override yylval when it is global, as the user might have
+# already done so.
 m4_define([b4_declare_scanner_communication_variables], [[
 /* The lookahead symbol.  */
-int yychar;
+int yychar;]b4_pure_if([
+
+/* Default (constant) value used for initialization.  */
+static YYSTYPE yyval_default;])[
 
 /* The semantic value of the lookahead symbol.  */
-YYSTYPE yylval;]b4_locations_if([[
+YYSTYPE yylval]b4_pure_if([ = yyval_default])[;]b4_locations_if([[
 
 /* Location data for the lookahead symbol.  */
 YYLTYPE yylloc;]])b4_pure_if([], [[
diff --git a/tests/atlocal.in b/tests/atlocal.in
index d059d63..d64140f 100644
--- a/tests/atlocal.in
+++ b/tests/atlocal.in
@@ -29,16 +29,10 @@ CPPFLAGS="-I$abs_top_builddir/lib @CPPFLAGS@"
 # Is the compiler GCC?
 GCC='@GCC@'
 
-# We want no optimization, as they uncover warnings (therefore,
-# failures) about uninitialized variables in the test suite.  FIXME:
-# fix the warnings, not the flags.
-  O0CFLAGS=`echo '@CFLAGS@'   | sed 's/-O[0-9s] *//g'`
-O0CXXFLAGS=`echo '@CXXFLAGS@' | sed 's/-O[0-9s] *//g'`
-
 # Sometimes a test group needs to ignore gcc warnings, so it locally
 # sets CFLAGS to this.
-  NO_WERROR_CFLAGS="$O0CFLAGS   @WARN_CFLAGS@   @WARN_CFLAGS_TEST@"
-NO_WERROR_CXXFLAGS="$O0CXXFLAGS @WARN_CXXFLAGS@ @WARN_CXXFLAGS_TEST@"
+  NO_WERROR_CFLAGS='@CFLAGS@   @WARN_CFLAGS@   @WARN_CFLAGS_TEST@'
+NO_WERROR_CXXFLAGS='@CXXFLAGS@ @WARN_CXXFLAGS@ @WARN_CXXFLAGS_TEST@'
 
 # But most of the time, we want -Werror.
   CFLAGS="$NO_WERROR_CFLAGS   @WERROR_CFLAGS@"
@@ -51,7 +45,6 @@ BISON_CXX_WORKS='@BISON_CXX_WORKS@'
 if "$at_arg_compile_c_with_cxx"; then
   CC_IS_CXX=1
   CC=$CXX
-  O0CFLAGS=$O0CXXFLAGS
   NO_WERROR_CFLAGS=$NO_WERROR_CXXFLAGS
   CFLAGS=$CXXFLAGS
 else
-- 
1.7.11.5





reply via email to

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