From patchwork Thu Jun 9 00:52:35 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Diego Novillo X-Patchwork-Id: 99590 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id DDB8BB6FCF for ; Thu, 9 Jun 2011 10:52:59 +1000 (EST) Received: (qmail 2245 invoked by alias); 9 Jun 2011 00:52:56 -0000 Received: (qmail 2233 invoked by uid 22791); 9 Jun 2011 00:52:55 -0000 X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (74.125.121.67) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 09 Jun 2011 00:52:39 +0000 Received: from wpaz33.hot.corp.google.com (wpaz33.hot.corp.google.com [172.24.198.97]) by smtp-out.google.com with ESMTP id p590qbuO005938; Wed, 8 Jun 2011 17:52:37 -0700 Received: from topo.tor.corp.google.com (topo.tor.corp.google.com [172.29.41.2]) by wpaz33.hot.corp.google.com with ESMTP id p590qZD6014223; Wed, 8 Jun 2011 17:52:35 -0700 Received: by topo.tor.corp.google.com (Postfix, from userid 54752) id 2D3BF1DA1CF; Wed, 8 Jun 2011 20:52:35 -0400 (EDT) To: reply@codereview.appspotmail.com, crowl@google.com, gchare@google.com, gcc-patches@gcc.gnu.org Subject: [pph] Fix cp_debug_parser (issue4571058) Message-Id: <20110609005235.2D3BF1DA1CF@topo.tor.corp.google.com> Date: Wed, 8 Jun 2011 20:52:35 -0400 (EDT) From: dnovillo@google.com (Diego Novillo) X-System-Of-Record: true X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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 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;