This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH: Fix PR 7679
- From: Mark Mitchell <mark at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 23 Oct 2002 11:28:34 -0700
- Subject: C++ PATCH: Fix PR 7679
- Reply-to: mark at codesourcery dot com
This patch fixes PR 7679; an infinite loop in the C++ parser.
Needless to say, the new parser does not have these problems.
Tested on i686-pc-linux-gnu, applied on the mainline. A variant of
this patch will go on the branch shortly.
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com
2002-10-23 Mark Mitchell <mark@codesourcery.com>
PR c++/7679
* spew.c (next_token): Do not return an endless stream of
END_OF_SAVED_INPUT tokens.
(snarf_method): Add three END_OF_SAVED_INPUT tokens to the end of
the cached token stream.
(snarf_defarg): Likewise.
2002-10-23 Mark Mitchell <mark@codesourcery.com>
PR c++/7679
* g++.dg/parse/inline1.C: New test.
Index: cp/spew.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/spew.c,v
retrieving revision 1.74
diff -c -p -r1.74 spew.c
*** cp/spew.c 22 Oct 2002 23:44:25 -0000 1.74
--- cp/spew.c 23 Oct 2002 18:34:07 -0000
*************** next_token (t)
*** 477,484 ****
return t->yychar;
}
! memcpy (t, &Teosi, sizeof (struct token));
! return END_OF_SAVED_INPUT;
}
/* Shift the next token onto the fifo. */
--- 477,483 ----
return t->yychar;
}
! return 0;
}
/* Shift the next token onto the fifo. */
*************** snarf_method (decl)
*** 1195,1200 ****
--- 1194,1207 ----
: (interface_only ? 0 : 2)));
snarf_block (meth);
+ /* Add three END_OF_SAVED_INPUT tokens. We used to provide an
+ infinite stream of END_OF_SAVED_INPUT tokens -- but that can
+ cause the compiler to get stuck in an infinite loop when
+ encountering invalid code. We need more than one because the
+ parser sometimes peeks ahead several tokens. */
+ memcpy (space_for_token (meth), &Teosi, sizeof (struct token));
+ memcpy (space_for_token (meth), &Teosi, sizeof (struct token));
+ memcpy (space_for_token (meth), &Teosi, sizeof (struct token));
/* Happens when we get two declarations of the same function in the
same scope. */
*************** snarf_defarg ()
*** 1253,1258 ****
--- 1260,1273 ----
/* Unget the last token. */
push_token (remove_last_token (buf));
+ /* Add three END_OF_SAVED_INPUT tokens. We used to provide an
+ infinite stream of END_OF_SAVED_INPUT tokens -- but that can
+ cause the compiler to get stuck in an infinite loop when
+ encountering invalid code. We need more than one because the
+ parser sometimes peeks ahead several tokens. */
+ memcpy (space_for_token (buf), &Teosi, sizeof (struct token));
+ memcpy (space_for_token (buf), &Teosi, sizeof (struct token));
+ memcpy (space_for_token (buf), &Teosi, sizeof (struct token));
done:
#ifdef SPEW_DEBUG
Index: testsuite/g++.dg/parse/inline1.C
===================================================================
RCS file: testsuite/g++.dg/parse/inline1.C
diff -N testsuite/g++.dg/parse/inline1.C
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/parse/inline1.C 23 Oct 2002 18:34:07 -0000
***************
*** 0 ****
--- 1,7 ----
+ struct f
+ {
+ int oo()
+ {
+ return (2; // { dg-error "" }
+ }
+ };