[Top][All Lists]

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

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

From: Paul Eggert
Subject: Re: {maint} yacc.c: initialize yylval in pure-parser mode
Date: Wed, 03 Oct 2012 17:55:28 -0700
User-agent: Mozilla/5.0 (X11; Linux i686; rv:15.0) Gecko/20120912 Thunderbird/15.0.1

On 09/28/2012 12:22 AM, Akim Demaille wrote:
> That's not true: the test case I sent _does_ use that
> initial yylval, yet GCC does not complain. 

Ouch.  I looked into that, and it's a GCC bug.
I filed a bug report here:

In the meantime, here is a similar grammar that
does not run afoul of the GCC bug, i.e., GCC correctly
reports that yylval is uninitialized:

  #define YYSTYPE double
  extern void report_error (const char *);
  extern void handle_value (int);
  static void yyerror (const char *msg)
    report_error (msg);

  static int yylex (YYSTYPE *lvalp)
    static const char *input = "a";
    return *input++;

  int main (void)
    return yyparse ();

%token 'a';
exp: 'a' { handle_value ($1); };

Compile it this way, with Bison master:

bison bar.y
gcc -S -Wall -O2

I get the correct warning: In function 'yyparse': warning: 'yylval' may be used uninitialized in this function 

If we alter Bison to always initialize yylval,
we'll suppress this correct warning.  On the other hand, if
we use the patch I'm proposing, the warning should
still be generated.

reply via email to

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