[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:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54804
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:
%pure-parser
%code
{
#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 bar.tab.c
I get the correct warning:
bar.tab.c: In function 'yyparse':
bar.tab.c:1133:12: warning: 'yylval' may be used uninitialized in this function
[-Wuninitialized]
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.
- Re: {maint} yacc.c: initialize yylval in pure-parser mode, Akim Demaille, 2012/10/03
- Re: {maint} yacc.c: initialize yylval in pure-parser mode,
Paul Eggert <=
- Re: {maint} yacc.c: initialize yylval in pure-parser mode, Akim Demaille, 2012/10/05
- Re: {maint} yacc.c: initialize yylval in pure-parser mode, Paul Eggert, 2012/10/05
- Re: {maint} yacc.c: initialize yylval in pure-parser mode, Akim Demaille, 2012/10/06
- Re: {maint} yacc.c: initialize yylval in pure-parser mode, Paul Eggert, 2012/10/06
- [PATCH 0/4] Re: {maint} yacc.c: initialize yylval in pure-parser mode, Akim Demaille, 2012/10/08
- Re: [PATCH 0/4] Re: {maint} yacc.c: initialize yylval in pure-parser mode, Paul Eggert, 2012/10/11
- Re: [PATCH 0/4] Re: {maint} yacc.c: initialize yylval in pure-parser mode, Akim Demaille, 2012/10/11
- Re: [PATCH 0/4] Re: {maint} yacc.c: initialize yylval in pure-parser mode, Paul Eggert, 2012/10/11