public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [libcpp] Fix ICE with conditional macros (PR preprocessor/61977)
@ 2015-04-01  8:22 Jakub Jelinek
  2015-04-03 15:43 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2015-04-01  8:22 UTC (permalink / raw)
  To: Jason Merrill, Marek Polacek, Joseph S. Myers, Dodji Seketeli; +Cc: gcc-patches

Hi!

cpp_peek_token is broken whenever it sees CPP_EOF, as it doesn't back up
the previous tokens (if any) and the CPP_EOF token, so for callers
of cpp_peek_token whenever it returns CPP_EOF it is a fatal condition,
so one really can't peek safely.

cpp_peek_token has apparently been written for the conditional macros
where it really assumes one can safely peek tokens several times.

The following patch fixes that.  If no CPP_EOF is seen or it is seen on the
last token, index will be -1 and thus count - index is still count + 1
as before, but if we hit CPP_EOF earlier, we only back up tokens before
that.

Richard and Prathamesh raised this issue already some time ago:
https://gcc.gnu.org/ml/gcc-patches/2014-08/msg00895.html
but there was no follow-up on that.

Bootstrapped/regtested on powerpc64{,le}-linux and {x86_64,i686}-linux, ok
for trunk?

2015-03-31  Jakub Jelinek  <jakub@redhat.com>

	PR preprocessor/61977
	* lex.c (cpp_peek_token): If peektok is CPP_EOF, back it up
	with all tokens peeked by the current function.

--- libcpp/lex.c.jj	2015-03-17 18:10:12.000000000 +0100
+++ libcpp/lex.c	2015-03-31 19:39:28.207748285 +0200
@@ -2084,11 +2084,14 @@ cpp_peek_token (cpp_reader *pfile, int i
     {
       peektok = _cpp_lex_token (pfile);
       if (peektok->type == CPP_EOF)
-	return peektok;
+	{
+	  index--;
+	  break;
+	}
     }
   while (index--);
 
-  _cpp_backup_tokens_direct (pfile, count + 1);
+  _cpp_backup_tokens_direct (pfile, count - index);
   pfile->keep_tokens--;
 
   return peektok;
--- gcc/testsuite/gcc.dg/cpp/pr61977.c.jj	2015-03-31 19:46:12.226279905 +0200
+++ gcc/testsuite/gcc.dg/cpp/pr61977.c	2015-03-31 19:46:03.638417398 +0200
@@ -0,0 +1,4 @@
+/* PR preprocessor/61977 */
+/* { dg-do preprocess } */
+
+vector

	Jakub

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

* Re: [libcpp] Fix ICE with conditional macros (PR preprocessor/61977)
  2015-04-01  8:22 [libcpp] Fix ICE with conditional macros (PR preprocessor/61977) Jakub Jelinek
@ 2015-04-03 15:43 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2015-04-03 15:43 UTC (permalink / raw)
  To: Jakub Jelinek, Marek Polacek, Joseph S. Myers, Dodji Seketeli; +Cc: gcc-patches

OK.

Jason

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

end of thread, other threads:[~2015-04-03 15:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-01  8:22 [libcpp] Fix ICE with conditional macros (PR preprocessor/61977) Jakub Jelinek
2015-04-03 15:43 ` Jason Merrill

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).