From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32487 invoked by alias); 19 Nov 2001 19:01:38 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 32463 invoked from network); 19 Nov 2001 19:01:35 -0000 Received: from unknown (HELO monkey.daikokuya.demon.co.uk) (158.152.184.26) by sourceware.cygnus.com with SMTP; 19 Nov 2001 19:01:35 -0000 Received: from neil by monkey.daikokuya.demon.co.uk with local (Exim 3.32 #1 (Debian)) id 165tgJ-00009Z-00; Mon, 19 Nov 2001 19:02:11 +0000 Date: Tue, 13 Nov 2001 15:03:00 -0000 To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: Re: PATCH to _cpp_backup_tokens Message-ID: <20011119190205.B31603@daikokuya.demon.co.uk> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.3.23i From: Neil Booth X-SW-Source: 2001-11/txt/msg00569.txt.bz2 Jason Merrill wrote:- > We don't want to back up to the previous hunk until we actually need > something from it; it might not exist. Fixes compilation of preprocessed > code with no # lines. > > 2001-11-19 Jason Merrill > > * cppmacro.c (_cpp_backup_tokens): Pop cur_run before decrementing > cur_token, not after. This is not correct. cpplib maintains cur_token as being a pointer just past the current token; as it is post-incremented. This is the simplest implementation for many reasons, but the variable is poorly named I guess. So your patch would give incorrect diagnostic locations and / or segfaults in some cases; see e.g. the diagnostic reporting code in cpperror.c. Also, your patch should have contained a testcase. Correct patch + testcase below; I'll commit them when a bootstrap has completed. Neil. * cppmacro.c (_cpp_backup_tokens): Revert previous check-in. Don't fall off the base token run. * gcc.dg/cpp/fpreprocessed.c: New test case. Index: cppmacro.c =================================================================== RCS file: /cvs/gcc/gcc/gcc/cppmacro.c,v retrieving revision 1.84 diff -u -p -r1.84 cppmacro.c --- cppmacro.c 2001/11/19 11:28:47 1.84 +++ cppmacro.c 2001/11/19 18:50:53 @@ -1087,12 +1087,14 @@ _cpp_backup_tokens (pfile, count) pfile->lookaheads += count; while (count--) { - if (pfile->cur_token == pfile->cur_run->base) + pfile->cur_token--; + if (pfile->cur_token == pfile->cur_run->base + /* Possible with -fpreprocessed and no leading #line. */ + && pfile->cur_run->prev != NULL) { pfile->cur_run = pfile->cur_run->prev; pfile->cur_token = pfile->cur_run->limit; } - pfile->cur_token--; } } else Index: testsuite/gcc.dg/cpp/fpreprocessed.c =================================================================== RCS file: fpreprocessed.c diff -N fpreprocessed.c --- /dev/null Tue May 5 13:32:27 1998 +++ fpreprocessed.c Mon Nov 19 10:50:53 2001 @@ -0,0 +1,10 @@ +/* Copyright (C) 2001 Free Software Foundation, Inc. */ + +/* { dg-do preprocess } */ +/* { dg-options -fpreprocessed } */ + +/* Source: Jason Merrill, 19 Nov 2001. We'd try and back up a token + and move to a non-existent token run with -fpreprocessed on a file + without a leading # line. */ + +foo