* [PATCH] libcpp: Fix up pragma preprocessing [PR100450]
@ 2021-05-07 7:53 Jakub Jelinek
2021-05-07 14:58 ` Marek Polacek
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2021-05-07 7:53 UTC (permalink / raw)
To: Nathan Sidwell, Jason Merrill, Joseph S. Myers, Marek Polacek,
David Malcolm
Cc: gcc-patches
Hi!
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.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk
and release branches (in particular 8 which freezes later today)?
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.
--- libcpp/lex.c.jj 2021-05-04 21:02:13.633917100 +0200
+++ libcpp/lex.c 2021-05-06 20:32:07.695035739 +0200
@@ -3709,6 +3709,7 @@ cpp_avoid_paste (cpp_reader *pfile, cons
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
--- gcc/testsuite/c-c++-common/gomp/pr100450.c.jj 2021-05-06 20:33:45.302961055 +0200
+++ gcc/testsuite/c-c++-common/gomp/pr100450.c 2021-05-06 20:33:39.882020738 +0200
@@ -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]; )
+}
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] libcpp: Fix up pragma preprocessing [PR100450]
2021-05-07 7:53 [PATCH] libcpp: Fix up pragma preprocessing [PR100450] Jakub Jelinek
@ 2021-05-07 14:58 ` Marek Polacek
0 siblings, 0 replies; 2+ messages in thread
From: Marek Polacek @ 2021-05-07 14:58 UTC (permalink / raw)
To: Jakub Jelinek
Cc: Nathan Sidwell, Jason Merrill, Joseph S. Myers, David Malcolm,
gcc-patches
On Fri, May 07, 2021 at 09:53:29AM +0200, Jakub Jelinek wrote:
> Hi!
>
> 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.
Nice explanation, it helped me to understand this.
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk
> and release branches (in particular 8 which freezes later today)?
OK. I don't think we'd ever want to actually concatenate in this context.
> 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.
>
> --- libcpp/lex.c.jj 2021-05-04 21:02:13.633917100 +0200
> +++ libcpp/lex.c 2021-05-06 20:32:07.695035739 +0200
> @@ -3709,6 +3709,7 @@ cpp_avoid_paste (cpp_reader *pfile, cons
> 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
> --- gcc/testsuite/c-c++-common/gomp/pr100450.c.jj 2021-05-06 20:33:45.302961055 +0200
> +++ gcc/testsuite/c-c++-common/gomp/pr100450.c 2021-05-06 20:33:39.882020738 +0200
> @@ -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]; )
> +}
>
> Jakub
>
Marek
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-05-07 14:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-07 7:53 [PATCH] libcpp: Fix up pragma preprocessing [PR100450] Jakub Jelinek
2021-05-07 14:58 ` Marek Polacek
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).