diff mbox series

c++: Make -Wunknown-pragmas controllable by #pragma GCC diagnostic [PR89038]

Message ID 20231018211542.1516517-1-lhyatt@gmail.com
State New
Headers show
Series c++: Make -Wunknown-pragmas controllable by #pragma GCC diagnostic [PR89038] | expand

Commit Message

Lewis Hyatt Oct. 18, 2023, 9:15 p.m. UTC
Hello-

The PR points out that my fix for PR53431 was incomplete and did not handle
-Wunknown-pragmas. This is a one-line fix to correct that, is it OK for
trunk and for GCC 13 backport please? bootstrap + regtest all languages on
x86-64 Linux. Thanks!

-Lewis

-- >8 --

As noted on the PR, commit r13-1544, the fix for PR53431, did not handle
the specific case of -Wunknown-pragmas, because that warning is issued
during preprocessing, but not by libcpp directly (it comes from the
cb_def_pragma callback).  Address that by handling this pragma in
addition to libcpp pragmas during the early pragma handler.

gcc/c-family/ChangeLog:

	PR c++/89038
	* c-pragma.cc (handle_pragma_diagnostic_impl):  Handle
	-Wunknown-pragmas during early processing.

gcc/testsuite/ChangeLog:

	PR c++/89038
	* c-c++-common/cpp/Wunknown-pragmas-1.c: New test.
---
 gcc/c-family/c-pragma.cc                            |  3 ++-
 gcc/testsuite/c-c++-common/cpp/Wunknown-pragmas-1.c | 13 +++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/c-c++-common/cpp/Wunknown-pragmas-1.c

Comments

Marek Polacek Oct. 19, 2023, 12:43 p.m. UTC | #1
On Wed, Oct 18, 2023 at 05:15:42PM -0400, Lewis Hyatt wrote:
> Hello-
> 
> The PR points out that my fix for PR53431 was incomplete and did not handle
> -Wunknown-pragmas. This is a one-line fix to correct that, is it OK for
> trunk and for GCC 13 backport please? bootstrap + regtest all languages on
> x86-64 Linux. Thanks!

I think I can approve this, so, OK.  Thanks.
 
> -Lewis
> 
> -- >8 --
> 
> As noted on the PR, commit r13-1544, the fix for PR53431, did not handle
> the specific case of -Wunknown-pragmas, because that warning is issued
> during preprocessing, but not by libcpp directly (it comes from the
> cb_def_pragma callback).  Address that by handling this pragma in
> addition to libcpp pragmas during the early pragma handler.
> 
> gcc/c-family/ChangeLog:
> 
> 	PR c++/89038
> 	* c-pragma.cc (handle_pragma_diagnostic_impl):  Handle
> 	-Wunknown-pragmas during early processing.
> 
> gcc/testsuite/ChangeLog:
> 
> 	PR c++/89038
> 	* c-c++-common/cpp/Wunknown-pragmas-1.c: New test.
> ---
>  gcc/c-family/c-pragma.cc                            |  3 ++-
>  gcc/testsuite/c-c++-common/cpp/Wunknown-pragmas-1.c | 13 +++++++++++++
>  2 files changed, 15 insertions(+), 1 deletion(-)
>  create mode 100644 gcc/testsuite/c-c++-common/cpp/Wunknown-pragmas-1.c
> 
> diff --git a/gcc/c-family/c-pragma.cc b/gcc/c-family/c-pragma.cc
> index 293311dd4ce..98dfb0f108b 100644
> --- a/gcc/c-family/c-pragma.cc
> +++ b/gcc/c-family/c-pragma.cc
> @@ -963,7 +963,8 @@ handle_pragma_diagnostic_impl ()
>    /* option_string + 1 to skip the initial '-' */
>    unsigned int option_index = find_opt (data.option_str + 1, lang_mask);
>  
> -  if (early && !c_option_is_from_cpp_diagnostics (option_index))
> +  if (early && !(c_option_is_from_cpp_diagnostics (option_index)
> +		 || option_index == OPT_Wunknown_pragmas))
>      return;
>  
>    if (option_index == OPT_SPECIAL_unknown)
> diff --git a/gcc/testsuite/c-c++-common/cpp/Wunknown-pragmas-1.c b/gcc/testsuite/c-c++-common/cpp/Wunknown-pragmas-1.c
> new file mode 100644
> index 00000000000..fb58739e2bc
> --- /dev/null
> +++ b/gcc/testsuite/c-c++-common/cpp/Wunknown-pragmas-1.c
> @@ -0,0 +1,13 @@
> +/* PR c++/89038 */
> +/* { dg-additional-options "-Wunknown-pragmas" } */
> +
> +#pragma oops /* { dg-warning "-:-Wunknown-pragmas" } */
> +#pragma GGC diagnostic push /* { dg-warning "-:-Wunknown-pragmas" } */
> +#pragma GCC diagnostics push /* { dg-warning "-:-Wunknown-pragmas" } */
> +
> +/* Test we can disable the warnings.  */
> +#pragma GCC diagnostic ignored "-Wunknown-pragmas"
> +
> +#pragma oops /* { dg-bogus "-:-Wunknown-pragmas" } */
> +#pragma GGC diagnostic push /* { dg-bogus "-:-Wunknown-pragmas" } */
> +#pragma GCC diagnostics push /* { dg-bogus "-:-Wunknown-pragmas" } */
> 

Marek
Lewis Hyatt Oct. 19, 2023, 1:07 p.m. UTC | #2
On Thu, Oct 19, 2023 at 8:43 AM Marek Polacek <polacek@redhat.com> wrote:
>
> On Wed, Oct 18, 2023 at 05:15:42PM -0400, Lewis Hyatt wrote:
> > Hello-
> >
> > The PR points out that my fix for PR53431 was incomplete and did not handle
> > -Wunknown-pragmas. This is a one-line fix to correct that, is it OK for
> > trunk and for GCC 13 backport please? bootstrap + regtest all languages on
> > x86-64 Linux. Thanks!
>
> I think I can approve this, so, OK.  Thanks.
>

Great, thank you very much. Just to be safe, was that OK for the
backport as well?

-Lewis
Marek Polacek Oct. 19, 2023, 1:14 p.m. UTC | #3
On Thu, Oct 19, 2023 at 09:07:36AM -0400, Lewis Hyatt wrote:
> On Thu, Oct 19, 2023 at 8:43 AM Marek Polacek <polacek@redhat.com> wrote:
> >
> > On Wed, Oct 18, 2023 at 05:15:42PM -0400, Lewis Hyatt wrote:
> > > Hello-
> > >
> > > The PR points out that my fix for PR53431 was incomplete and did not handle
> > > -Wunknown-pragmas. This is a one-line fix to correct that, is it OK for
> > > trunk and for GCC 13 backport please? bootstrap + regtest all languages on
> > > x86-64 Linux. Thanks!
> >
> > I think I can approve this, so, OK.  Thanks.
> >
> 
> Great, thank you very much. Just to be safe, was that OK for the
> backport as well?

It's a safe bugfix, it doesn't enable an extra warning, so yes, I don't
see why not.  Thanks,

Marek
diff mbox series

Patch

diff --git a/gcc/c-family/c-pragma.cc b/gcc/c-family/c-pragma.cc
index 293311dd4ce..98dfb0f108b 100644
--- a/gcc/c-family/c-pragma.cc
+++ b/gcc/c-family/c-pragma.cc
@@ -963,7 +963,8 @@  handle_pragma_diagnostic_impl ()
   /* option_string + 1 to skip the initial '-' */
   unsigned int option_index = find_opt (data.option_str + 1, lang_mask);
 
-  if (early && !c_option_is_from_cpp_diagnostics (option_index))
+  if (early && !(c_option_is_from_cpp_diagnostics (option_index)
+		 || option_index == OPT_Wunknown_pragmas))
     return;
 
   if (option_index == OPT_SPECIAL_unknown)
diff --git a/gcc/testsuite/c-c++-common/cpp/Wunknown-pragmas-1.c b/gcc/testsuite/c-c++-common/cpp/Wunknown-pragmas-1.c
new file mode 100644
index 00000000000..fb58739e2bc
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/cpp/Wunknown-pragmas-1.c
@@ -0,0 +1,13 @@ 
+/* PR c++/89038 */
+/* { dg-additional-options "-Wunknown-pragmas" } */
+
+#pragma oops /* { dg-warning "-:-Wunknown-pragmas" } */
+#pragma GGC diagnostic push /* { dg-warning "-:-Wunknown-pragmas" } */
+#pragma GCC diagnostics push /* { dg-warning "-:-Wunknown-pragmas" } */
+
+/* Test we can disable the warnings.  */
+#pragma GCC diagnostic ignored "-Wunknown-pragmas"
+
+#pragma oops /* { dg-bogus "-:-Wunknown-pragmas" } */
+#pragma GGC diagnostic push /* { dg-bogus "-:-Wunknown-pragmas" } */
+#pragma GCC diagnostics push /* { dg-bogus "-:-Wunknown-pragmas" } */