* [PATCH] preprocessor: Don't register pragmas in directives-only mode [PR108244]
@ 2022-12-30 17:21 Lewis Hyatt
2023-01-11 19:26 ` Jakub Jelinek
0 siblings, 1 reply; 2+ messages in thread
From: Lewis Hyatt @ 2022-12-30 17:21 UTC (permalink / raw)
To: gcc-patches; +Cc: Lewis Hyatt
libcpp's directives-only mode does not expect deferred pragmas to be
registered, but to date the c-family registration process has not checked for
this case. That issue became more visible since r13-1544, which added the
commonly used GCC diagnostic pragmas to the set of those registered in
preprocessing modes. Fix it by checking for directives-only mode in
c-family/c-pragma.cc.
gcc/c-family/ChangeLog:
PR preprocessor/108244
* c-pragma.cc (c_register_pragma_1): Don't attempt to register any
deferred pragmas if -fdirectives-only.
(init_pragma): Likewise.
gcc/testsuite/ChangeLog:
* c-c++-common/cpp/pr108244-1.c: New test.
* c-c++-common/cpp/pr108244-2.c: New test.
* c-c++-common/cpp/pr108244-3.c: New test.
---
Notes:
Hello-
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108244
The PR notes a regression in GCC 13 which is fixed by the attached
patch. Bootstrap+regtest all languages on x86-64 Linux looks good. Please let
me know if it is OK? Thanks.
-Lewis
gcc/c-family/c-pragma.cc | 54 ++++++++++++---------
gcc/testsuite/c-c++-common/cpp/pr108244-1.c | 5 ++
gcc/testsuite/c-c++-common/cpp/pr108244-2.c | 5 ++
gcc/testsuite/c-c++-common/cpp/pr108244-3.c | 6 +++
4 files changed, 46 insertions(+), 24 deletions(-)
create mode 100644 gcc/testsuite/c-c++-common/cpp/pr108244-1.c
create mode 100644 gcc/testsuite/c-c++-common/cpp/pr108244-2.c
create mode 100644 gcc/testsuite/c-c++-common/cpp/pr108244-3.c
diff --git a/gcc/c-family/c-pragma.cc b/gcc/c-family/c-pragma.cc
index 142a46441ac..91fabf0a513 100644
--- a/gcc/c-family/c-pragma.cc
+++ b/gcc/c-family/c-pragma.cc
@@ -1647,7 +1647,8 @@ c_register_pragma_1 (const char *space, const char *name,
if (flag_preprocess_only)
{
- if (!(allow_expansion || ihandler.early_handler.handler_1arg))
+ if (cpp_get_options (parse_in)->directives_only
+ || !(allow_expansion || ihandler.early_handler.handler_1arg))
return;
pragma_pp_data pp_data;
@@ -1811,34 +1812,39 @@ c_pp_invoke_early_pragma_handler (unsigned int id)
void
init_pragma (void)
{
- if (flag_openacc)
+
+ if (!cpp_get_options (parse_in)->directives_only)
{
- const int n_oacc_pragmas = ARRAY_SIZE (oacc_pragmas);
- int i;
+ if (flag_openacc)
+ {
+ const int n_oacc_pragmas = ARRAY_SIZE (oacc_pragmas);
+ int i;
- for (i = 0; i < n_oacc_pragmas; ++i)
- cpp_register_deferred_pragma (parse_in, "acc", oacc_pragmas[i].name,
- oacc_pragmas[i].id, true, true);
- }
+ for (i = 0; i < n_oacc_pragmas; ++i)
+ cpp_register_deferred_pragma (parse_in, "acc", oacc_pragmas[i].name,
+ oacc_pragmas[i].id, true, true);
+ }
- if (flag_openmp)
- {
- const int n_omp_pragmas = ARRAY_SIZE (omp_pragmas);
- int i;
+ if (flag_openmp)
+ {
+ const int n_omp_pragmas = ARRAY_SIZE (omp_pragmas);
+ int i;
- for (i = 0; i < n_omp_pragmas; ++i)
- cpp_register_deferred_pragma (parse_in, "omp", omp_pragmas[i].name,
- omp_pragmas[i].id, true, true);
- }
- if (flag_openmp || flag_openmp_simd)
- {
- const int n_omp_pragmas_simd = sizeof (omp_pragmas_simd)
- / sizeof (*omp_pragmas);
- int i;
+ for (i = 0; i < n_omp_pragmas; ++i)
+ cpp_register_deferred_pragma (parse_in, "omp", omp_pragmas[i].name,
+ omp_pragmas[i].id, true, true);
+ }
+ if (flag_openmp || flag_openmp_simd)
+ {
+ const int n_omp_pragmas_simd
+ = sizeof (omp_pragmas_simd) / sizeof (*omp_pragmas);
+ int i;
- for (i = 0; i < n_omp_pragmas_simd; ++i)
- cpp_register_deferred_pragma (parse_in, "omp", omp_pragmas_simd[i].name,
- omp_pragmas_simd[i].id, true, true);
+ for (i = 0; i < n_omp_pragmas_simd; ++i)
+ cpp_register_deferred_pragma (parse_in, "omp",
+ omp_pragmas_simd[i].name,
+ omp_pragmas_simd[i].id, true, true);
+ }
}
if (!flag_preprocess_only)
diff --git a/gcc/testsuite/c-c++-common/cpp/pr108244-1.c b/gcc/testsuite/c-c++-common/cpp/pr108244-1.c
new file mode 100644
index 00000000000..1678004a4d9
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/cpp/pr108244-1.c
@@ -0,0 +1,5 @@
+/* { dg-do preprocess } */
+/* { dg-additional-options "-fdirectives-only" } */
+#pragma GCC diagnostic push
+#ifdef t
+#endif
diff --git a/gcc/testsuite/c-c++-common/cpp/pr108244-2.c b/gcc/testsuite/c-c++-common/cpp/pr108244-2.c
new file mode 100644
index 00000000000..017682ad186
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/cpp/pr108244-2.c
@@ -0,0 +1,5 @@
+/* { dg-do preprocess } */
+/* { dg-additional-options "-fdirectives-only" } */
+#pragma message "hello"
+#ifdef t
+#endif
diff --git a/gcc/testsuite/c-c++-common/cpp/pr108244-3.c b/gcc/testsuite/c-c++-common/cpp/pr108244-3.c
new file mode 100644
index 00000000000..e9e784b40d5
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/cpp/pr108244-3.c
@@ -0,0 +1,6 @@
+/* { dg-do preprocess } */
+/* { dg-additional-options "-fdirectives-only -fopenmp" } */
+/* { dg-require-effective-target "fopenmp" } */
+#pragma omp parallel
+#ifdef t
+#endif
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] preprocessor: Don't register pragmas in directives-only mode [PR108244]
2022-12-30 17:21 [PATCH] preprocessor: Don't register pragmas in directives-only mode [PR108244] Lewis Hyatt
@ 2023-01-11 19:26 ` Jakub Jelinek
0 siblings, 0 replies; 2+ messages in thread
From: Jakub Jelinek @ 2023-01-11 19:26 UTC (permalink / raw)
To: Lewis Hyatt; +Cc: gcc-patches
On Fri, Dec 30, 2022 at 12:21:37PM -0500, Lewis Hyatt via Gcc-patches wrote:
> libcpp's directives-only mode does not expect deferred pragmas to be
> registered, but to date the c-family registration process has not checked for
> this case. That issue became more visible since r13-1544, which added the
> commonly used GCC diagnostic pragmas to the set of those registered in
> preprocessing modes. Fix it by checking for directives-only mode in
> c-family/c-pragma.cc.
>
> gcc/c-family/ChangeLog:
>
> PR preprocessor/108244
> * c-pragma.cc (c_register_pragma_1): Don't attempt to register any
> deferred pragmas if -fdirectives-only.
> (init_pragma): Likewise.
>
> gcc/testsuite/ChangeLog:
>
> * c-c++-common/cpp/pr108244-1.c: New test.
> * c-c++-common/cpp/pr108244-2.c: New test.
> * c-c++-common/cpp/pr108244-3.c: New test.
Ok, with a nit:
> --- /dev/null
> +++ b/gcc/testsuite/c-c++-common/cpp/pr108244-3.c
> @@ -0,0 +1,6 @@
> +/* { dg-do preprocess } */
> +/* { dg-additional-options "-fdirectives-only -fopenmp" } */
> +/* { dg-require-effective-target "fopenmp" } */
> +#pragma omp parallel
> +#ifdef t
> +#endif
This test should be in gcc/testsuite/c-c++-common/gomp/
directory instead, without the dg-require-effective-target.
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-01-11 19:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-30 17:21 [PATCH] preprocessor: Don't register pragmas in directives-only mode [PR108244] Lewis Hyatt
2023-01-11 19:26 ` Jakub Jelinek
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).