public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Nathan Sidwell <nathan@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r11-4686] cpplib:  EOF in pragmas
Date: Tue,  3 Nov 2020 18:07:27 +0000 (GMT)	[thread overview]
Message-ID: <20201103180727.3C4B63858001@sourceware.org> (raw)

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':


                 reply	other threads:[~2020-11-03 18:07 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201103180727.3C4B63858001@sourceware.org \
    --to=nathan@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).