public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: Neil Booth <neil@daikokuya.co.uk>
To: neil@gcc.gnu.org
Cc: gcc-prs@gcc.gnu.org,
Subject: Re: preprocessor/8524: _Pragma within macros is improperly expanded
Date: Sat, 23 Nov 2002 21:36:00 -0000	[thread overview]
Message-ID: <20021118204603.20203.qmail@sources.redhat.com> (raw)

The following reply was made to PR preprocessor/8524; it has been noted by GNATS.

From: Neil Booth <neil@daikokuya.co.uk>
To: 157416@bugs.debian.org, Andrew Suffield <asuffield@debian.org>
Cc: gcc-gnats@gcc.gnu.org, debian-gcc@lists.debian.org,
	Zack Weinberg <zack@codesourcery.com>, gcc-patches@gcc.gnu.org
Subject: Re: preprocessor/8524: _Pragma within macros is improperly expanded
Date: Mon, 18 Nov 2002 20:39:57 +0000

 I think this fixes it for good.  I'm applying this to 3.3, and 3.2.2
 when it arrives.
 
 Neil.
 
 	PR preprocessor/8524
 	* cpplib.c (run_directive): Remove previous kludge to _Pragma.
 	Add a new one in its place, which hopefully works.
 	(skip_rest_of_line): Change test for bottom-of-context-stack.
 testsuite:
 	* gcc.dg/cpp/_Pragma5.c: New test.
 
 Index: cpplib.c
 ===================================================================
 RCS file: /cvs/gcc/gcc/gcc/cpplib.c,v
 retrieving revision 1.324
 diff -u -p -r1.324 cpplib.c
 --- cpplib.c	22 Sep 2002 02:03:17 -0000	1.324
 +++ cpplib.c	17 Nov 2002 22:11:21 -0000
 @@ -207,7 +207,7 @@ skip_rest_of_line (pfile)
       cpp_reader *pfile;
  {
    /* Discard all stacked contexts.  */
 -  while (pfile->context != &pfile->base_context)
 +  while (pfile->context->prev)
      _cpp_pop_context (pfile);
  
    /* Sweep up all tokens remaining on the line.  */
 @@ -1277,9 +1277,6 @@ destringize_and_run (pfile, in)
  {
    const unsigned char *src, *limit;
    char *dest, *result;
 -  cpp_context saved_context;
 -  cpp_context *saved_cur_context;
 -  unsigned int saved_line;
  
    dest = result = alloca (in->len + 1);
    for (src = in->text, limit = src + in->len; src < limit;)
 @@ -1291,24 +1288,29 @@ destringize_and_run (pfile, in)
      }
    *dest = '\0';
  
 -  /* FIXME.  All this saving is a horrible kludge to handle the case
 -     when we're in a macro expansion.
 -
 -     A better strategy it to not convert _Pragma to #pragma if doing
 -     preprocessed output, but to just pass it through as-is, unless it
 -     is a CPP pragma in which case is should be processed normally.
 -     When compiling the preprocessed output the _Pragma should be
 -     handled.  This will be become necessary when we move to
 -     line-at-a-time lexing since we will be macro-expanding the line
 -     before outputting / compiling it.  */
 -  saved_line = pfile->line;
 -  saved_context = pfile->base_context;
 -  saved_cur_context = pfile->context;
 -  pfile->context = &pfile->base_context;
 -  run_directive (pfile, T_PRAGMA, result, dest - result);
 -  pfile->context = saved_cur_context;
 -  pfile->base_context = saved_context;
 -  pfile->line = saved_line;
 +  /* Ugh; an awful kludge.  We are really not set up to be lexing
 +     tokens when in the middle of a macro expansion.  Use a new
 +     context to force cpp_get_token to lex, and so skip_rest_of_line
 +     doesn't go beyond the end of the text.  Also, remember the
 +     current lexing position so we can return to it later.
 +
 +     Something like line-at-a-time lexing should remove the need for
 +     this.  */
 +  {
 +    cpp_context *saved_context = pfile->context;
 +    cpp_token *saved_cur_token = pfile->cur_token;
 +    tokenrun *saved_cur_run = pfile->cur_run;
 +
 +    pfile->context = xnew (cpp_context);
 +    pfile->context->macro = 0;
 +    pfile->context->prev = 0;
 +    run_directive (pfile, T_PRAGMA, result, dest - result);
 +    free (pfile->context);
 +    pfile->context = saved_context;
 +    pfile->cur_token = saved_cur_token;
 +    pfile->cur_run = saved_cur_run;
 +    pfile->line--;
 +  }
  
    /* See above comment.  For the moment, we'd like
  


             reply	other threads:[~2002-11-18 20:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-11-23 21:36 Neil Booth [this message]
  -- strict thread matches above, loose matches on Subject: below --
2002-11-24  3:35 neil
2002-11-24  3:25 Neil Booth
2002-11-22 13:26 neil
2002-11-10 22:44 neil
2002-11-10 22:36 Matthias Klose

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=20021118204603.20203.qmail@sources.redhat.com \
    --to=neil@daikokuya.co.uk \
    --cc=gcc-prs@gcc.gnu.org \
    --cc=neil@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).