From 215f1600905ee321e056dfbe2783a7e6c5bc6a68 Mon Sep 17 00:00:00 2001 From: Mark Mitchell Date: Wed, 23 Oct 2002 21:56:55 +0000 Subject: [PATCH] re PR c++/7679 (The compiler crashes wen a right parentesis is missing) 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. PR c++/7679 * g++.dg/parse/inline1.C: New test. From-SVN: r58473 --- gcc/cp/ChangeLog | 9 +++++++++ gcc/cp/spew.c | 35 ++++++++++++++++++++++++++++++++--- gcc/testsuite/ChangeLog | 5 +++++ 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index e5a628c46947..bd57ba555e3a 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,12 @@ +2002-10-23 Mark Mitchell + + 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-22 Mark Mitchell PR c++/6579 diff --git a/gcc/cp/spew.c b/gcc/cp/spew.c index 93b8348b0293..278a99ad1755 100644 --- a/gcc/cp/spew.c +++ b/gcc/cp/spew.c @@ -485,9 +485,8 @@ add_token (t) memcpy (t, feed->input->pos, sizeof (struct token)); return (feed->input->pos++)->yychar; } - - memcpy (t, &Teosi, sizeof (struct token)); - return END_OF_SAVED_INPUT; + + return 0; } /* Shift the next token onto the fifo. */ @@ -1167,12 +1166,27 @@ snarf_method (decl) int starting_lineno = lineno; const char *starting_filename = input_filename; size_t len; + int i; struct unparsed_text *meth; /* Leave room for the header, then absorb the block. */ obstack_blank (&inline_text_obstack, sizeof (struct unparsed_text)); snarf_block (starting_filename, starting_lineno); + /* 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. */ + for (i = 0; i < 3; ++i) + { + size_t point = obstack_object_size (&inline_text_obstack); + obstack_blank (&inline_text_obstack, sizeof (struct token)); + memcpy ((struct token *) + (obstack_base (&inline_text_obstack) + point), + &Teosi, + sizeof (struct token)); + } len = obstack_object_size (&inline_text_obstack); meth = (struct unparsed_text *) obstack_finish (&inline_text_obstack); @@ -1223,6 +1237,7 @@ snarf_defarg () size_t point; size_t len; struct unparsed_text *buf; + int i; tree arg; obstack_blank (&inline_text_obstack, sizeof (struct unparsed_text)); @@ -1252,6 +1267,20 @@ snarf_defarg () push_token ((struct token *) (obstack_base (&inline_text_obstack) + point)); /* This is the documented way to shrink a growing obstack block. */ obstack_blank (&inline_text_obstack, - (int) sizeof (struct token)); + /* 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. */ + for (i = 0; i < 3; ++i) + { + point = obstack_object_size (&inline_text_obstack); + obstack_blank (&inline_text_obstack, sizeof (struct token)); + memcpy ((struct token *) + (obstack_base (&inline_text_obstack) + point), + &Teosi, + sizeof (struct token)); + } done: len = obstack_object_size (&inline_text_obstack); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 011f9f4af0b3..27d4ed3b35b1 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2002-10-23 Mark Mitchell + + PR c++/7679 + * g++.dg/parse/inline1.C: New test. + 2002-10-22 Mark Mitchell PR c++/6579 -- 2.47.2