This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: cp/parse.y:2120: invalid value: $3


> Date: Mon, 29 Apr 2002 13:31:29 -0700 (PDT)
> From: "David S. Miller" <davem@redhat.com>
> 
> 	http://gcc.gnu.org/ml/gcc-bugs/2002-04/msg01309.html

That thread explains why the C++ parser code is the way it is.
Unfortunately, the code is still wrong.  Here's why.

If you look at the C code that is generated by Bison 1.35 from
cp/parse.y, you'll find that the corresponding C-language action looks
like this:

   case 456:
   #line 2151 "parse.y"
   { /* Set things up as initdcl0_innards expects.  */
 (*)		 yyvsp[1].ttype = yyvsp[0].ttype;
		 yyvsp[0].ttype = yyvsp[-1].ttype; 
		 yyvsp[-1].ftype.t = NULL_TREE;
		 yyvsp[-1].ftype.lookups = NULL_TREE; }
       break;

The line marked (*) is the expansion of the controversial statement
`$<ttype>3 = $2;' that is attempting to make the stack "look right".

OK, what happens next?  The "break" statement takes us to here:

     yyvsp -= yylen;
     yyssp -= yylen;
   #if YYLSP_NEEDED
     yylsp -= yylen;
   #endif

yylen is zero, so these statements have no effect.  The next statement
executed is:

 (**)    *++yyvsp = yyval;

and this obliterates the effect of (*): it's as if (*) had never
happened, which means that `$<ttype>3 = $2;' is a no-op.

To fix the bug, you need to change (*) to look like this instead:

		 yyval = yyvsp[0].ttype;

so that (*) stores the desired value on the stack.  This will put the
desired value into yyval so that (**) makes the stack "look right".
Here's how to do this:

2002-04-29  Paul Eggert  <eggert@twinsun.com>

	* parse.y (nomods_initdcl0): Replace $<ttype>3 with $<ttype>$,
	to fix a typo uncovered by CVS Bison.  Let's buy Akim Demaille
	a beer!

--- parse.y	2002-04-29 14:43:20.511360000 -0700
+++ parse.y-fix	2002-04-29 14:55:06.991361000 -0700
@@ -2149,7 +2149,7 @@ notype_initdcl0:
 nomods_initdcl0:
           notype_declarator maybeasm
             { /* Set things up as initdcl0_innards expects.  */
-	      $<ttype>3 = $2;
+	      $<ttype>$ = $2;
 	      $2 = $1; 
               $<ftype>1.t = NULL_TREE;
 	      $<ftype>1.lookups = NULL_TREE; }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]