public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: PATCH to _cpp_backup_tokens
  2001-11-13 15:03 PATCH to _cpp_backup_tokens Jason Merrill
@ 2001-11-13 15:03 ` Neil Booth
  0 siblings, 0 replies; 2+ messages in thread
From: Neil Booth @ 2001-11-13 15:03 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* PATCH to _cpp_backup_tokens
@ 2001-11-13 15:03 Jason Merrill
  2001-11-13 15:03 ` Neil Booth
  0 siblings, 1 reply; 2+ messages in thread
From: Jason Merrill @ 2001-11-13 15:03 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 305 bytes --]

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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 732 bytes --]

*** cppmacro.c.~1~	Mon Nov 19 11:19:05 2001
--- cppmacro.c	Sat Nov 17 10:43:30 2001
*************** _cpp_backup_tokens (pfile, count)
*** 1087,1098 ****
        pfile->lookaheads += count;
        while (count--)
  	{
- 	  pfile->cur_token--;
  	  if (pfile->cur_token == pfile->cur_run->base)
  	    {
  	      pfile->cur_run = pfile->cur_run->prev;
  	      pfile->cur_token = pfile->cur_run->limit;
  	    }
  	}
      }
    else
--- 1087,1098 ----
        pfile->lookaheads += count;
        while (count--)
  	{
  	  if (pfile->cur_token == pfile->cur_run->base)
  	    {
  	      pfile->cur_run = pfile->cur_run->prev;
  	      pfile->cur_token = pfile->cur_run->limit;
  	    }
+ 	  pfile->cur_token--;
  	}
      }
    else

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2001-11-19 19:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-11-13 15:03 PATCH to _cpp_backup_tokens Jason Merrill
2001-11-13 15:03 ` Neil Booth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).