public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc(refs/vendors/redhat/heads/gcc-8-branch)] libcpp: Fix up pragma preprocessing [PR100450]
Date: Fri, 14 May 2021 14:57:48 +0000 (GMT)	[thread overview]
Message-ID: <20210514145748.C08CD3953C08@sourceware.org> (raw)

https://gcc.gnu.org/g:455e8d7dfa059c0fb1b881e16b8f913dc066adad

commit 455e8d7dfa059c0fb1b881e16b8f913dc066adad
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri May 7 17:48:37 2021 +0200

    libcpp: Fix up pragma preprocessing [PR100450]
    
    Since the r0-85991-ga25a8f3be322fe0f838947b679f73d6efc2a412c
    https://gcc.gnu.org/legacy-ml/gcc-patches/2008-02/msg01329.html
    changes, so that we handle macros inside of pragmas that should expand
    macros, during preprocessing we print those pragmas token by token,
    with CPP_PRAGMA printed as
          fputs ("#pragma ", print.outf);
          if (space)
            fprintf (print.outf, "%s %s", space, name);
          else
            fprintf (print.outf, "%s", name);
    where name is some identifier (so e.g. print
     #pragma omp parallel
    or
     #pragma omp for
    etc.).  Because it ends in an identifier, we need to handle it like
    an identifier (i.e. CPP_NAME) for the decision whether a space needs
    to be emitted in between that #pragma whatever or #pragma whatever whatever
    and following token, otherwise the attached testcase is preprocessed as
     #pragma omp forreduction(+:red)
    rather than
     #pragma omp for reduction(+:red)
    The cpp_avoid_paste function is only called for this purpose.
    
    2021-05-07  Jakub Jelinek  <jakub@redhat.com>
    
            PR c/100450
            * lex.c (cpp_avoid_paste): Handle token1 CPP_PRAGMA like CPP_NAME.
    
            * c-c++-common/gomp/pr100450.c: New test.
    
    (cherry picked from commit 170c850e4bd46745e2a5130b5eb09f9fceb98416)

Diff:
---
 gcc/testsuite/c-c++-common/gomp/pr100450.c | 20 ++++++++++++++++++++
 libcpp/lex.c                               |  1 +
 2 files changed, 21 insertions(+)

diff --git a/gcc/testsuite/c-c++-common/gomp/pr100450.c b/gcc/testsuite/c-c++-common/gomp/pr100450.c
new file mode 100644
index 00000000000..a6d2a2829ff
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/gomp/pr100450.c
@@ -0,0 +1,20 @@
+/* PR c/100450 */
+/* { dg-do compile } */
+/* { dg-options "-fopenmp -save-temps -Wunknown-pragmas" } */
+
+#define TEST(T) { \
+     {T} \
+}
+#define CLAUSES reduction(+:red)
+#define PARALLEL_FOR(X) TEST({ \
+_Pragma("omp for CLAUSES") \
+X \
+})
+
+void foo()
+{
+  int red = 0;
+  int A[3] = {};
+  #pragma omp parallel shared(red)
+  PARALLEL_FOR( for(int i=0; i < 3; i++) red += A[i]; )
+}
diff --git a/libcpp/lex.c b/libcpp/lex.c
index f0c53b71c25..a408f912c5c 100644
--- a/libcpp/lex.c
+++ b/libcpp/lex.c
@@ -3453,6 +3453,7 @@ cpp_avoid_paste (cpp_reader *pfile, const cpp_token *token1,
     case CPP_DEREF:	return c == '*';
     case CPP_DOT:	return c == '.' || c == '%' || b == CPP_NUMBER;
     case CPP_HASH:	return c == '#' || c == '%'; /* Digraph form.  */
+    case CPP_PRAGMA:
     case CPP_NAME:	return ((b == CPP_NUMBER
 				 && name_p (pfile, &token2->val.str))
 				|| b == CPP_NAME


                 reply	other threads:[~2021-05-14 14:57 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=20210514145748.C08CD3953C08@sourceware.org \
    --to=jakub@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).