From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6905 invoked by alias); 21 Oct 2011 18:59:12 -0000 Received: (qmail 6888 invoked by uid 22791); 21 Oct 2011 18:59:10 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 21 Oct 2011 18:58:52 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p9LIwqRg028964 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 21 Oct 2011 14:58:52 -0400 Received: from localhost (ovpn-113-95.phx2.redhat.com [10.3.113.95]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p9LIwoX1019068 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 21 Oct 2011 14:58:51 -0400 Received: by localhost (Postfix, from userid 500) id 47E2729C129; Fri, 21 Oct 2011 20:58:49 +0200 (CEST) From: Dodji Seketeli To: Tom Tromey , Jason Merrill Cc: GCC Patches Subject: [PATCH, libcpp] Fix cpp_peek_token behaviour (PR bootstrap/50778) X-URL: http://www.redhat.com Date: Fri, 21 Oct 2011 19:26:00 -0000 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2011-10/txt/msg02022.txt.bz2 Hello, cpp_peek_token can fail to peek tokens sometimes because _cpp_remaining_tokens_num_in_context counts tokens only from the current context; worse, _cpp_token_from_context_at also get tokens only from the context context. They should both operate on the context given by cpp_peek_token. I did the mistake in the first place. This was breaking bootstrap on ppc-darwin. Fixed thus, bootstrapped on x86_64-unknown-linux-gnu, tested on ppc-darwin and a full (very slow) bootstrap is on-going on ppc-darwin. OK for trunk when ppc-darwin finishes? (or even before?) libcpp/ * include/internal.h (_cpp_remaining_tokens_num_in_context): Take the context to act upon. * lex.c (_cpp_remaining_tokens_num_in_context): Likewise. Update comment. (cpp_token_from_context_at): Likewise. (cpp_peek_token): Use the context to peek tokens from. --- libcpp/internal.h | 2 +- libcpp/lex.c | 16 +++++++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/libcpp/internal.h b/libcpp/internal.h index 6fb2606..e60330df 100644 --- a/libcpp/internal.h +++ b/libcpp/internal.h @@ -652,7 +652,7 @@ extern cpp_token *_cpp_lex_direct (cpp_reader *); extern int _cpp_equiv_tokens (const cpp_token *, const cpp_token *); extern void _cpp_init_tokenrun (tokenrun *, unsigned int); extern cpp_hashnode *_cpp_lex_identifier (cpp_reader *, const char *); -extern int _cpp_remaining_tokens_num_in_context (cpp_reader *); +extern int _cpp_remaining_tokens_num_in_context (cpp_context *); /* In init.c. */ extern void _cpp_maybe_push_include_file (cpp_reader *); diff --git a/libcpp/lex.c b/libcpp/lex.c index 527368b..896a3be 100644 --- a/libcpp/lex.c +++ b/libcpp/lex.c @@ -1703,12 +1703,11 @@ next_tokenrun (tokenrun *run) return run->next; } -/* Return the number of not yet processed token in the the current +/* Return the number of not yet processed token in a given context. */ int -_cpp_remaining_tokens_num_in_context (cpp_reader *pfile) +_cpp_remaining_tokens_num_in_context (cpp_context *context) { - cpp_context *context = pfile->context; if (context->tokens_kind == TOKENS_KIND_DIRECT) return (LAST (context).token - FIRST (context).token); else if (context->tokens_kind == TOKENS_KIND_INDIRECT @@ -1718,12 +1717,11 @@ _cpp_remaining_tokens_num_in_context (cpp_reader *pfile) abort (); } -/* Returns the token present at index INDEX in the current context. - If INDEX is zero, the next token to be processed is returned. */ +/* Returns the token present at index INDEX in a given context. If + INDEX is zero, the next token to be processed is returned. */ static const cpp_token* -_cpp_token_from_context_at (cpp_reader *pfile, int index) +_cpp_token_from_context_at (cpp_context *context, int index) { - cpp_context *context = pfile->context; if (context->tokens_kind == TOKENS_KIND_DIRECT) return &(FIRST (context).token[index]); else if (context->tokens_kind == TOKENS_KIND_INDIRECT @@ -1744,10 +1742,10 @@ cpp_peek_token (cpp_reader *pfile, int index) /* First, scan through any pending cpp_context objects. */ while (context->prev) { - ptrdiff_t sz = _cpp_remaining_tokens_num_in_context (pfile); + ptrdiff_t sz = _cpp_remaining_tokens_num_in_context (context); if (index < (int) sz) - return _cpp_token_from_context_at (pfile, index); + return _cpp_token_from_context_at (context, index); index -= (int) sz; context = context->prev; } -- 1.7.6.4 -- Dodji