Patchwork [pph] Fix cp_debug_parser (issue4571058)

login
register
mail settings
Submitter Diego Novillo
Date June 9, 2011, 12:52 a.m.
Message ID <20110609005235.2D3BF1DA1CF@topo.tor.corp.google.com>
Download mbox | patch
Permalink /patch/99590/
State New
Headers show

Comments

Diego Novillo - June 9, 2011, 12:52 a.m.
This fixes the ICE that Gab ran into while calling cp_debug_parser on a
test case.

We were not handling the case of empty token buffers and when the
caller set the starting token to NULL.

Additionally, the window of tokens to print was too small to be of any
real use.


	* parser.c (cp_lexer_dump_tokens): If START_TOKEN is NULL,
	set it to the start of the token buffer.
	If BUFFER is NULL, do nothing.
	(cp_debug_parser): Increase token window size.


--
This patch is available for review at http://codereview.appspot.com/4571058

Patch

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 300fcba..e241cc7 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -265,10 +265,16 @@  cp_lexer_dump_tokens (FILE *file, VEC(cp_token,gc) *buffer,
 
   fprintf (file, "%u tokens\n", VEC_length (cp_token, buffer));
 
+  if (buffer == NULL)
+    return;
+
   if (num == 0)
     num = VEC_length (cp_token, buffer);
 
-  if (start_token && start_token > VEC_address (cp_token, buffer))
+  if (start_token == NULL)
+    start_token = VEC_address (cp_token, buffer);
+
+  if (start_token > VEC_address (cp_token, buffer))
     {
       cp_lexer_print_token (file, VEC_index (cp_token, buffer, 0));
       fprintf (file, " ... ");
@@ -436,7 +442,7 @@  void
 cp_debug_parser (FILE *file, cp_parser *parser)
 {
   cp_token *start_token, *first_token, *next_token;
-  const size_t window_size = 20;
+  const size_t window_size = 200;
 
   if (file == NULL)
     file = stderr;