diff mbox series

preprocessor: Reinitialize frontend parser after loading a PCH [PR112319]

Message ID 20231101215457.3935908-1-lhyatt@gmail.com
State New
Headers show
Series preprocessor: Reinitialize frontend parser after loading a PCH [PR112319] | expand

Commit Message

Lewis Hyatt Nov. 1, 2023, 9:54 p.m. UTC
Hello-

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112319

This is a one-line patch to fix the GCC 14 regression noted in the
PR. Bootstrap + regtest all languages on x86-64 looks good. Is it OK please?
Thanks!

-Lewis

-- >8 --

Since r14-2893, the frontend parser object needs to exist when running in
preprocess-only mode, because pragma_lex() is now called in that mode and
needs to make use of it. This is handled by calling c_init_preprocess() at
startup. If -fpch-preprocess is in effect (commonly, because of
-save-temps), a PCH file may be loaded during preprocessing, in which
case the parser will be destroyed, causing the issue noted in the
PR. Resolve it by reinitializing the frontend parser after loading the PCH.

gcc/c-family/ChangeLog:

	PR pch/112319
	* c-ppoutput.cc (cb_read_pch): Reinitialize the frontend parser
	after loading a PCH.

gcc/testsuite/ChangeLog:

	PR pch/112319
	* g++.dg/pch/pr112319.C: New test.
	* g++.dg/pch/pr112319.Hs: New test.
	* gcc.dg/pch/pr112319.c: New test.
	* gcc.dg/pch/pr112319.hs: New test.
---
 gcc/c-family/c-ppoutput.cc           | 5 +++++
 gcc/testsuite/g++.dg/pch/pr112319.C  | 5 +++++
 gcc/testsuite/g++.dg/pch/pr112319.Hs | 1 +
 gcc/testsuite/gcc.dg/pch/pr112319.c  | 5 +++++
 gcc/testsuite/gcc.dg/pch/pr112319.hs | 1 +
 5 files changed, 17 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/pch/pr112319.C
 create mode 100644 gcc/testsuite/g++.dg/pch/pr112319.Hs
 create mode 100644 gcc/testsuite/gcc.dg/pch/pr112319.c
 create mode 100644 gcc/testsuite/gcc.dg/pch/pr112319.hs

Comments

Lewis Hyatt Nov. 17, 2023, 2:16 p.m. UTC | #1
May I please ping this one? Thanks...
https://gcc.gnu.org/pipermail/gcc-patches/2023-November/634931.html

On Wed, Nov 1, 2023 at 5:55 PM Lewis Hyatt <lhyatt@gmail.com> wrote:
>
> Hello-
>
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112319
>
> This is a one-line patch to fix the GCC 14 regression noted in the
> PR. Bootstrap + regtest all languages on x86-64 looks good. Is it OK please?
> Thanks!
>
> -Lewis
>
> -- >8 --
>
> Since r14-2893, the frontend parser object needs to exist when running in
> preprocess-only mode, because pragma_lex() is now called in that mode and
> needs to make use of it. This is handled by calling c_init_preprocess() at
> startup. If -fpch-preprocess is in effect (commonly, because of
> -save-temps), a PCH file may be loaded during preprocessing, in which
> case the parser will be destroyed, causing the issue noted in the
> PR. Resolve it by reinitializing the frontend parser after loading the PCH.
>
> gcc/c-family/ChangeLog:
>
>         PR pch/112319
>         * c-ppoutput.cc (cb_read_pch): Reinitialize the frontend parser
>         after loading a PCH.
>
> gcc/testsuite/ChangeLog:
>
>         PR pch/112319
>         * g++.dg/pch/pr112319.C: New test.
>         * g++.dg/pch/pr112319.Hs: New test.
>         * gcc.dg/pch/pr112319.c: New test.
>         * gcc.dg/pch/pr112319.hs: New test.
> ---
>  gcc/c-family/c-ppoutput.cc           | 5 +++++
>  gcc/testsuite/g++.dg/pch/pr112319.C  | 5 +++++
>  gcc/testsuite/g++.dg/pch/pr112319.Hs | 1 +
>  gcc/testsuite/gcc.dg/pch/pr112319.c  | 5 +++++
>  gcc/testsuite/gcc.dg/pch/pr112319.hs | 1 +
>  5 files changed, 17 insertions(+)
>  create mode 100644 gcc/testsuite/g++.dg/pch/pr112319.C
>  create mode 100644 gcc/testsuite/g++.dg/pch/pr112319.Hs
>  create mode 100644 gcc/testsuite/gcc.dg/pch/pr112319.c
>  create mode 100644 gcc/testsuite/gcc.dg/pch/pr112319.hs
>
> diff --git a/gcc/c-family/c-ppoutput.cc b/gcc/c-family/c-ppoutput.cc
> index 4aa2bef2c0f..4f973767976 100644
> --- a/gcc/c-family/c-ppoutput.cc
> +++ b/gcc/c-family/c-ppoutput.cc
> @@ -862,4 +862,9 @@ cb_read_pch (cpp_reader *pfile, const char *name,
>
>    fprintf (print.outf, "#pragma GCC pch_preprocess \"%s\"\n", name);
>    print.src_line++;
> +
> +  /* The process of reading the PCH has destroyed the frontend parser,
> +     so ask the frontend to reinitialize it, in case we need it to
> +     process any #pragma directives encountered while preprocessing.  */
> +  c_init_preprocess ();
>  }
> diff --git a/gcc/testsuite/g++.dg/pch/pr112319.C b/gcc/testsuite/g++.dg/pch/pr112319.C
> new file mode 100644
> index 00000000000..9e0457e8aec
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/pch/pr112319.C
> @@ -0,0 +1,5 @@
> +/* { dg-additional-options "-Wpragmas -save-temps" } */
> +#include "pr112319.H"
> +#pragma GCC diagnostic error "-Wpragmas"
> +#pragma GCC diagnostic ignored "oops" /* { dg-error "oops" } */
> +/* { dg-regexp {[^[:space:]]*: some warnings being treated as errors} } */
> diff --git a/gcc/testsuite/g++.dg/pch/pr112319.Hs b/gcc/testsuite/g++.dg/pch/pr112319.Hs
> new file mode 100644
> index 00000000000..3b6178bfae0
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/pch/pr112319.Hs
> @@ -0,0 +1 @@
> +/* This space intentionally left blank.  */
> diff --git a/gcc/testsuite/gcc.dg/pch/pr112319.c b/gcc/testsuite/gcc.dg/pch/pr112319.c
> new file mode 100644
> index 00000000000..043881463c5
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/pch/pr112319.c
> @@ -0,0 +1,5 @@
> +/* { dg-additional-options "-Wpragmas -save-temps" } */
> +#include "pr112319.h"
> +#pragma GCC diagnostic error "-Wpragmas"
> +#pragma GCC diagnostic ignored "oops" /* { dg-error "oops" } */
> +/* { dg-regexp {[^[:space:]]*: some warnings being treated as errors} } */
> diff --git a/gcc/testsuite/gcc.dg/pch/pr112319.hs b/gcc/testsuite/gcc.dg/pch/pr112319.hs
> new file mode 100644
> index 00000000000..3b6178bfae0
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/pch/pr112319.hs
> @@ -0,0 +1 @@
> +/* This space intentionally left blank.  */
Jakub Jelinek Nov. 24, 2023, 4:04 p.m. UTC | #2
On Wed, Nov 01, 2023 at 05:54:57PM -0400, Lewis Hyatt wrote:
> Since r14-2893, the frontend parser object needs to exist when running in
> preprocess-only mode, because pragma_lex() is now called in that mode and
> needs to make use of it. This is handled by calling c_init_preprocess() at
> startup. If -fpch-preprocess is in effect (commonly, because of
> -save-temps), a PCH file may be loaded during preprocessing, in which
> case the parser will be destroyed, causing the issue noted in the
> PR. Resolve it by reinitializing the frontend parser after loading the PCH.
> 
> gcc/c-family/ChangeLog:
> 
> 	PR pch/112319
> 	* c-ppoutput.cc (cb_read_pch): Reinitialize the frontend parser
> 	after loading a PCH.
> 
> gcc/testsuite/ChangeLog:
> 
> 	PR pch/112319
> 	* g++.dg/pch/pr112319.C: New test.
> 	* g++.dg/pch/pr112319.Hs: New test.
> 	* gcc.dg/pch/pr112319.c: New test.
> 	* gcc.dg/pch/pr112319.hs: New test.

LGTM.

	Jakub
Marek Polacek Nov. 30, 2023, 9:19 p.m. UTC | #3
On Wed, Nov 01, 2023 at 05:54:57PM -0400, Lewis Hyatt wrote:
> Hello-
> 
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112319
> 
> This is a one-line patch to fix the GCC 14 regression noted in the
> PR. Bootstrap + regtest all languages on x86-64 looks good. Is it OK please?
> Thanks!
> 
> -Lewis
> 
> -- >8 --
> 
> Since r14-2893, the frontend parser object needs to exist when running in
> preprocess-only mode, because pragma_lex() is now called in that mode and
> needs to make use of it. This is handled by calling c_init_preprocess() at
> startup. If -fpch-preprocess is in effect (commonly, because of
> -save-temps), a PCH file may be loaded during preprocessing, in which
> case the parser will be destroyed, causing the issue noted in the
> PR. Resolve it by reinitializing the frontend parser after loading the PCH.
> 
> gcc/c-family/ChangeLog:
> 
> 	PR pch/112319
> 	* c-ppoutput.cc (cb_read_pch): Reinitialize the frontend parser

"front-end"

> 	after loading a PCH.
> 
> gcc/testsuite/ChangeLog:
> 
> 	PR pch/112319
> 	* g++.dg/pch/pr112319.C: New test.
> 	* g++.dg/pch/pr112319.Hs: New test.
> 	* gcc.dg/pch/pr112319.c: New test.
> 	* gcc.dg/pch/pr112319.hs: New test.
> ---
>  gcc/c-family/c-ppoutput.cc           | 5 +++++
>  gcc/testsuite/g++.dg/pch/pr112319.C  | 5 +++++
>  gcc/testsuite/g++.dg/pch/pr112319.Hs | 1 +
>  gcc/testsuite/gcc.dg/pch/pr112319.c  | 5 +++++
>  gcc/testsuite/gcc.dg/pch/pr112319.hs | 1 +
>  5 files changed, 17 insertions(+)
>  create mode 100644 gcc/testsuite/g++.dg/pch/pr112319.C
>  create mode 100644 gcc/testsuite/g++.dg/pch/pr112319.Hs
>  create mode 100644 gcc/testsuite/gcc.dg/pch/pr112319.c
>  create mode 100644 gcc/testsuite/gcc.dg/pch/pr112319.hs
> 
> diff --git a/gcc/c-family/c-ppoutput.cc b/gcc/c-family/c-ppoutput.cc
> index 4aa2bef2c0f..4f973767976 100644
> --- a/gcc/c-family/c-ppoutput.cc
> +++ b/gcc/c-family/c-ppoutput.cc
> @@ -862,4 +862,9 @@ cb_read_pch (cpp_reader *pfile, const char *name,
>  
>    fprintf (print.outf, "#pragma GCC pch_preprocess \"%s\"\n", name);
>    print.src_line++;
> +
> +  /* The process of reading the PCH has destroyed the frontend parser,

"front-end"

> +     so ask the frontend to reinitialize it, in case we need it to

"front end"

(sorry to be overly pedantic...)

Patch looks fine to me; please go ahead if you haven't pushed it already.

> +     process any #pragma directives encountered while preprocessing.  */
> +  c_init_preprocess ();
>  }
> diff --git a/gcc/testsuite/g++.dg/pch/pr112319.C b/gcc/testsuite/g++.dg/pch/pr112319.C
> new file mode 100644
> index 00000000000..9e0457e8aec
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/pch/pr112319.C
> @@ -0,0 +1,5 @@
> +/* { dg-additional-options "-Wpragmas -save-temps" } */
> +#include "pr112319.H"
> +#pragma GCC diagnostic error "-Wpragmas"
> +#pragma GCC diagnostic ignored "oops" /* { dg-error "oops" } */
> +/* { dg-regexp {[^[:space:]]*: some warnings being treated as errors} } */
> diff --git a/gcc/testsuite/g++.dg/pch/pr112319.Hs b/gcc/testsuite/g++.dg/pch/pr112319.Hs
> new file mode 100644
> index 00000000000..3b6178bfae0
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/pch/pr112319.Hs
> @@ -0,0 +1 @@
> +/* This space intentionally left blank.  */
> diff --git a/gcc/testsuite/gcc.dg/pch/pr112319.c b/gcc/testsuite/gcc.dg/pch/pr112319.c
> new file mode 100644
> index 00000000000..043881463c5
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/pch/pr112319.c
> @@ -0,0 +1,5 @@
> +/* { dg-additional-options "-Wpragmas -save-temps" } */
> +#include "pr112319.h"
> +#pragma GCC diagnostic error "-Wpragmas"
> +#pragma GCC diagnostic ignored "oops" /* { dg-error "oops" } */
> +/* { dg-regexp {[^[:space:]]*: some warnings being treated as errors} } */
> diff --git a/gcc/testsuite/gcc.dg/pch/pr112319.hs b/gcc/testsuite/gcc.dg/pch/pr112319.hs
> new file mode 100644
> index 00000000000..3b6178bfae0
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/pch/pr112319.hs
> @@ -0,0 +1 @@
> +/* This space intentionally left blank.  */
> 

Marek
Lewis Hyatt Nov. 30, 2023, 10:20 p.m. UTC | #4
On Thu, Nov 30, 2023 at 4:19 PM Marek Polacek <polacek@redhat.com> wrote:
>
> On Wed, Nov 01, 2023 at 05:54:57PM -0400, Lewis Hyatt wrote:
> > Hello-
> >
> > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112319
> >
> > This is a one-line patch to fix the GCC 14 regression noted in the
> > PR. Bootstrap + regtest all languages on x86-64 looks good. Is it OK please?
> > Thanks!
> >
> > -Lewis
> >
> > -- >8 --
> >
> > Since r14-2893, the frontend parser object needs to exist when running in
> > preprocess-only mode, because pragma_lex() is now called in that mode and
> > needs to make use of it. This is handled by calling c_init_preprocess() at
> > startup. If -fpch-preprocess is in effect (commonly, because of
> > -save-temps), a PCH file may be loaded during preprocessing, in which
> > case the parser will be destroyed, causing the issue noted in the
> > PR. Resolve it by reinitializing the frontend parser after loading the PCH.
> >
> > gcc/c-family/ChangeLog:
> >
> >       PR pch/112319
> >       * c-ppoutput.cc (cb_read_pch): Reinitialize the frontend parser
>
> "front-end"
>
> >       after loading a PCH.
> >
> > gcc/testsuite/ChangeLog:
> >
> >       PR pch/112319
> >       * g++.dg/pch/pr112319.C: New test.
> >       * g++.dg/pch/pr112319.Hs: New test.
> >       * gcc.dg/pch/pr112319.c: New test.
> >       * gcc.dg/pch/pr112319.hs: New test.
> > ---
> >  gcc/c-family/c-ppoutput.cc           | 5 +++++
> >  gcc/testsuite/g++.dg/pch/pr112319.C  | 5 +++++
> >  gcc/testsuite/g++.dg/pch/pr112319.Hs | 1 +
> >  gcc/testsuite/gcc.dg/pch/pr112319.c  | 5 +++++
> >  gcc/testsuite/gcc.dg/pch/pr112319.hs | 1 +
> >  5 files changed, 17 insertions(+)
> >  create mode 100644 gcc/testsuite/g++.dg/pch/pr112319.C
> >  create mode 100644 gcc/testsuite/g++.dg/pch/pr112319.Hs
> >  create mode 100644 gcc/testsuite/gcc.dg/pch/pr112319.c
> >  create mode 100644 gcc/testsuite/gcc.dg/pch/pr112319.hs
> >
> > diff --git a/gcc/c-family/c-ppoutput.cc b/gcc/c-family/c-ppoutput.cc
> > index 4aa2bef2c0f..4f973767976 100644
> > --- a/gcc/c-family/c-ppoutput.cc
> > +++ b/gcc/c-family/c-ppoutput.cc
> > @@ -862,4 +862,9 @@ cb_read_pch (cpp_reader *pfile, const char *name,
> >
> >    fprintf (print.outf, "#pragma GCC pch_preprocess \"%s\"\n", name);
> >    print.src_line++;
> > +
> > +  /* The process of reading the PCH has destroyed the frontend parser,
>
> "front-end"
>
> > +     so ask the frontend to reinitialize it, in case we need it to
>
> "front end"
>
> (sorry to be overly pedantic...)
>
> Patch looks fine to me; please go ahead if you haven't pushed it already.
>

Thanks for the review! I did push it a few days ago as Jakub approved
it... I will spell front end correctly next time :).

-Lewis
diff mbox series

Patch

diff --git a/gcc/c-family/c-ppoutput.cc b/gcc/c-family/c-ppoutput.cc
index 4aa2bef2c0f..4f973767976 100644
--- a/gcc/c-family/c-ppoutput.cc
+++ b/gcc/c-family/c-ppoutput.cc
@@ -862,4 +862,9 @@  cb_read_pch (cpp_reader *pfile, const char *name,
 
   fprintf (print.outf, "#pragma GCC pch_preprocess \"%s\"\n", name);
   print.src_line++;
+
+  /* The process of reading the PCH has destroyed the frontend parser,
+     so ask the frontend to reinitialize it, in case we need it to
+     process any #pragma directives encountered while preprocessing.  */
+  c_init_preprocess ();
 }
diff --git a/gcc/testsuite/g++.dg/pch/pr112319.C b/gcc/testsuite/g++.dg/pch/pr112319.C
new file mode 100644
index 00000000000..9e0457e8aec
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pch/pr112319.C
@@ -0,0 +1,5 @@ 
+/* { dg-additional-options "-Wpragmas -save-temps" } */
+#include "pr112319.H"
+#pragma GCC diagnostic error "-Wpragmas"
+#pragma GCC diagnostic ignored "oops" /* { dg-error "oops" } */
+/* { dg-regexp {[^[:space:]]*: some warnings being treated as errors} } */
diff --git a/gcc/testsuite/g++.dg/pch/pr112319.Hs b/gcc/testsuite/g++.dg/pch/pr112319.Hs
new file mode 100644
index 00000000000..3b6178bfae0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pch/pr112319.Hs
@@ -0,0 +1 @@ 
+/* This space intentionally left blank.  */
diff --git a/gcc/testsuite/gcc.dg/pch/pr112319.c b/gcc/testsuite/gcc.dg/pch/pr112319.c
new file mode 100644
index 00000000000..043881463c5
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pch/pr112319.c
@@ -0,0 +1,5 @@ 
+/* { dg-additional-options "-Wpragmas -save-temps" } */
+#include "pr112319.h"
+#pragma GCC diagnostic error "-Wpragmas"
+#pragma GCC diagnostic ignored "oops" /* { dg-error "oops" } */
+/* { dg-regexp {[^[:space:]]*: some warnings being treated as errors} } */
diff --git a/gcc/testsuite/gcc.dg/pch/pr112319.hs b/gcc/testsuite/gcc.dg/pch/pr112319.hs
new file mode 100644
index 00000000000..3b6178bfae0
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pch/pr112319.hs
@@ -0,0 +1 @@ 
+/* This space intentionally left blank.  */