This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PATCH to _cpp_backup_tokens
- From: Neil Booth <neil at daikokuya dot demon dot co dot uk>
- To: Jason Merrill <jason at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Mon, 19 Nov 2001 19:02:05 +0000
- Subject: Re: PATCH to _cpp_backup_tokens
- References: <wvlr8qvvwbx.fsf@prospero.cambridge.redhat.com>
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 <jason@redhat.com>
>
> * 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