[Bug pch/115312] [14/15 Regression] ICE when including a PCH via compiler option -include since r14-5836

2024-07-03 Thread lhyatt at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115312

Lewis Hyatt  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |FIXED

--- Comment #11 from Lewis Hyatt  ---
Fixed for 14.2.

[Bug pch/115312] [14/15 Regression] ICE when including a PCH via compiler option -include since r14-5836

2024-07-03 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115312

--- Comment #10 from GCC Commits  ---
The releases/gcc-14 branch has been updated by Lewis Hyatt
:

https://gcc.gnu.org/g:3389a23fd492b7920a62de6af298251b3cdab617

commit r14-10374-g3389a23fd492b7920a62de6af298251b3cdab617
Author: Lewis Hyatt 
Date:   Sat Jun 15 21:09:01 2024 -0400

preprocessor: Create the parser before handling command-line includes
[PR115312]

Since r14-2893, we create a parser object in preprocess-only mode for the
purpose of parsing #pragma while preprocessing. The parser object was
formerly created after calling c_finish_options(), which leads to problems
on platforms that don't use stdc-predef.h (such as MinGW, as reported in
the PR). On such platforms, the call to c_finish_options() will process
the first command-line-specified include file. If that includes a PCH, then
c-ppoutput.cc will encounter a state it did not anticipate. Fix it by
creating the parser prior to calling c_finish_options().

gcc/c-family/ChangeLog:

PR pch/115312
* c-opts.cc (c_common_init): Call c_init_preprocess() before
c_finish_options() so that a parser is available to process any
includes specified on the command line.

gcc/testsuite/ChangeLog:

PR pch/115312
* g++.dg/pch/pr115312.C: New test.
* g++.dg/pch/pr115312.Hs: New test.

[Bug pch/115312] [14/15 Regression] ICE when including a PCH via compiler option -include since r14-5836

2024-07-02 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115312

--- Comment #9 from GCC Commits  ---
The master branch has been updated by Lewis Hyatt :

https://gcc.gnu.org/g:038d64f62271ddc62aa35d0a5dfd3843fdb9e6d7

commit r15-1803-g038d64f62271ddc62aa35d0a5dfd3843fdb9e6d7
Author: Lewis Hyatt 
Date:   Sat Jun 15 21:09:01 2024 -0400

preprocessor: Create the parser before handling command-line includes
[PR115312]

Since r14-2893, we create a parser object in preprocess-only mode for the
purpose of parsing #pragma while preprocessing. The parser object was
formerly created after calling c_finish_options(), which leads to problems
on platforms that don't use stdc-predef.h (such as MinGW, as reported in
the PR). On such platforms, the call to c_finish_options() will process
the first command-line-specified include file. If that includes a PCH, then
c-ppoutput.cc will encounter a state it did not anticipate. Fix it by
creating the parser prior to calling c_finish_options().

gcc/c-family/ChangeLog:

PR pch/115312
* c-opts.cc (c_common_init): Call c_init_preprocess() before
c_finish_options() so that a parser is available to process any
includes specified on the command line.

gcc/testsuite/ChangeLog:

PR pch/115312
* g++.dg/pch/pr115312.C: New test.
* g++.dg/pch/pr115312.Hs: New test.

[Bug pch/115312] [14/15 Regression] ICE when including a PCH via compiler option -include since r14-5836

2024-06-27 Thread lhyatt at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115312

Lewis Hyatt  changed:

   What|Removed |Added

URL||https://gcc.gnu.org/piperma
   ||il/gcc-patches/2024-June/65
   ||5900.html

--- Comment #8 from Lewis Hyatt  ---
Patch submitted for review.
https://gcc.gnu.org/pipermail/gcc-patches/2024-June/655900.html

[Bug pch/115312] [14/15 Regression] ICE when including a PCH via compiler option -include since r14-5836

2024-06-17 Thread lhyatt at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115312

Lewis Hyatt  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
 Ever confirmed|0   |1
   Last reconfirmed||2024-06-17
Summary|[14/15 Regression] ICE when |[14/15 Regression] ICE when
   |including a PCH via |including a PCH via
   |compiler option -include|compiler option -include
   ||since r14-5836

--- Comment #7 from Lewis Hyatt  ---
OK I see now. For the case of a PCH combined with -include it is a regression
in GCC 14 caused by r14-5836. I think any platform that does not make use of
the stdc-predef.h preinclude will be affected (including MinGW). 

The assert added in r14-5836 should not be failing, but it is failing due to an
oversight in r14-2893. This was a new feature for GCC 14 that made #pragma work
during preprocessing, which required the creation of a parser object in
preprocess-only mode.

I will test this patch that should fix it:

=

diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc
index faaf9ee6350..a09a0518c52 100644
--- a/gcc/c-family/c-opts.cc
+++ b/gcc/c-family/c-opts.cc
@@ -1296,8 +1296,8 @@ c_common_init (void)

   if (flag_preprocess_only)
 {
-  c_finish_options ();
   c_init_preprocess ();
+  c_finish_options ();
   preprocess_file (parse_in);
   return false;
 }

=

The problem is that c_finish_options() will also include the first
command-line- specified include file. On glibc platforms, this is always the
stdc-predef.h preinclude and then things work. In the absence of a preinclude,
it will include the first file requested with -include. If that file triggers a
PCH load, then we hit the code path introduced in r14-5836; after the PCH is
loaded, we reinitialize the parser. But in this case we have not called
c_init_preprocess() yet, so when we do call it afterward, the parser already
exists and so the assert fails. 

The above patch should make things right, I am testing it now and it should get
into GCC 14.2. You could add it to the list of MinGW-specific patches for
WinLibs and MSYS2 in the meantime too. It's preferable to commenting out the
assert, although that workaround probably does work fine at the moment as well.

[Bug pch/115312] [14/15 Regression] ICE when including a PCH via compiler option -include

2024-06-15 Thread brechtsanders at users dot sourceforge.net via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115312

--- Comment #6 from Brecht Sanders  
---
You're right. Sorry I missed that.

[Bug pch/115312] [14/15 Regression] ICE when including a PCH via compiler option -include

2024-06-15 Thread lhyatt at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115312

--- Comment #5 from Lewis Hyatt  ---
(In reply to Brecht Sanders from comment #4)
> No, that patch wasn't added for my build, see my build recipe here:
> https://github.com/brechtsanders/winlibs_recipes/blob/main/recipes/gcc.winlib

Thanks, this script is useful. FWIW I think the patch is there, line 778?
Unless I am missing something.

I see you also commented out the assert in your recipe. I am still not sure if
that is just masking some deeper issue, but I am getting close to being able to
reproduce it myself and will let you know.

[Bug pch/115312] [14/15 Regression] ICE when including a PCH via compiler option -include

2024-06-15 Thread brechtsanders at users dot sourceforge.net via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115312

--- Comment #4 from Brecht Sanders  
---
No, that patch wasn't added for my build, see my build recipe here:
https://github.com/brechtsanders/winlibs_recipes/blob/main/recipes/gcc.winlib

[Bug pch/115312] [14/15 Regression] ICE when including a PCH via compiler option -include

2024-06-11 Thread lhyatt at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115312

--- Comment #3 from Lewis Hyatt  ---
(In reply to Brecht Sanders from comment #2)
> I have made a native Windows MinGW-w64 build where the lines "gcc_assert
> (!the_parser);" were commented out in file gcc/cp/parser.cc and got
> confirmation this successfully works around the issue.

Thanks! Do you mind please confirming, are you building it with the following
downstream patch in place (which is not part of GCC itself as of now):
https://github.com/msys2/MINGW-packages/blob/master/mingw-w64-gcc/0021-PR14940-Allow-a-PCH-to-be-mapped-to-a-different-addr.patch
? If so, it would be interesting if possible to confirm whether the assert
still triggers without that patch.

[Bug pch/115312] [14/15 Regression] ICE when including a PCH via compiler option -include

2024-06-10 Thread brechtsanders at users dot sourceforge.net via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115312

Brecht Sanders  changed:

   What|Removed |Added

 CC||brechtsanders at users dot 
sourcef
   ||orge.net

--- Comment #2 from Brecht Sanders  
---
I have made a native Windows MinGW-w64 build where the lines "gcc_assert
(!the_parser);" were commented out in file gcc/cp/parser.cc and got
confirmation this successfully works around the issue.

See: https://github.com/brechtsanders/winlibs_mingw/issues/199

[Bug pch/115312] [14/15 Regression] ICE when including a PCH via compiler option -include

2024-06-03 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115312

Richard Biener  changed:

   What|Removed |Added

   Target Milestone|--- |14.2

[Bug pch/115312] [14/15 Regression] ICE when including a PCH via compiler option -include

2024-06-01 Thread lhyatt at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115312

Lewis Hyatt  changed:

   What|Removed |Added

 CC||lhyatt at gcc dot gnu.org

--- Comment #1 from Lewis Hyatt  ---
Hmm that is odd. It works fine on x86-64/Linux so I think this is something
target-specific with PCH? If this assert is firing:

void
c_init_preprocess ()
{
  gcc_assert (!the_parser);
...

It means that the_parser was not NULL after reading in the PCH. But it should
be, because the_parser is explicitly set to NULL prior to writing the PCH (at
the end of c_parse_file() in cp/parse.cc) and so that's what it should get set
to after reading the PCH back in. Are you able to confirm whether the_parser
stored in the PCH is indeed NULL, maybe? I don't have anywhere to test this
platform myself at the moment. Thanks...

That assert could be simply removed too, but it does seem worth understanding
how it can trigger here...