public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-4686] cpplib:  EOF in pragmas
@ 2020-11-03 18:07 Nathan Sidwell
  0 siblings, 0 replies; only message in thread
From: Nathan Sidwell @ 2020-11-03 18:07 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:8bd9a00f4349ebcd65223e3dcdfe83867e417287

commit r11-4686-g8bd9a00f4349ebcd65223e3dcdfe83867e417287
Author: Nathan Sidwell <nathan@acm.org>
Date:   Tue Nov 3 09:06:09 2020 -0800

    cpplib:  EOF in pragmas
    
    This patch moves the generation of PRAGMA_EOF earlier, to when we set
    need_line, rather than when we try and get the next line.  It also
    prevents peeking past a PRAGMA token.
    
            libcpp/
            * lex.c (cpp_peek_token): Do not peek past CPP_PRAGMA.
            (_cpp_lex_direct): Handle EOF in pragma when setting need_line,
            not when needing a line.

Diff:
---
 libcpp/lex.c | 31 +++++++++++++++++++++++--------
 1 file changed, 23 insertions(+), 8 deletions(-)

diff --git a/libcpp/lex.c b/libcpp/lex.c
index 1d522030a3c..f58a8828124 100644
--- a/libcpp/lex.c
+++ b/libcpp/lex.c
@@ -2554,6 +2554,15 @@ cpp_peek_token (cpp_reader *pfile, int index)
 	  index--;
 	  break;
 	}
+      else if (peektok->type == CPP_PRAGMA)
+	{
+	  /* Don't peek past a pragma.  */
+	  if (peektok == &pfile->directive_result)
+	    /* Save the pragma in the buffer.  */
+	    *pfile->cur_token++ = *peektok;
+	  index--;
+	  break;
+	}
     }
   while (index--);
 
@@ -2757,14 +2766,7 @@ _cpp_lex_direct (cpp_reader *pfile)
   buffer = pfile->buffer;
   if (buffer->need_line)
     {
-      if (pfile->state.in_deferred_pragma)
-	{
-	  result->type = CPP_PRAGMA_EOL;
-	  pfile->state.in_deferred_pragma = false;
-	  if (!pfile->state.pragma_allow_expansion)
-	    pfile->state.prevent_expansion--;
-	  return result;
-	}
+      gcc_assert (!pfile->state.in_deferred_pragma);
       if (!_cpp_get_fresh_line (pfile))
 	{
 	  result->type = CPP_EOF;
@@ -2829,6 +2831,19 @@ _cpp_lex_direct (cpp_reader *pfile)
 	      && !CPP_OPTION (pfile, traditional)))
 	CPP_INCREMENT_LINE (pfile, 0);
       buffer->need_line = true;
+      if (pfile->state.in_deferred_pragma)
+	{
+	  /* Produce the PRAGMA_EOL on this line.  File reading
+	     ensures there is always a \n at end of the buffer, thus
+	     in a deferred pragma we always see CPP_PRAGMA_EOL before
+	     any CPP_EOF.  */
+	  result->type = CPP_PRAGMA_EOL;
+	  result->flags &= ~PREV_WHITE;
+	  pfile->state.in_deferred_pragma = false;
+	  if (!pfile->state.pragma_allow_expansion)
+	    pfile->state.prevent_expansion--;
+	  return result;
+	}
       goto fresh_line;
 
     case '0': case '1': case '2': case '3': case '4':


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-11-03 18:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-03 18:07 [gcc r11-4686] cpplib: EOF in pragmas Nathan Sidwell

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