Comment 10 for bug 1610220

Revision history for this message
In , Jakub-gcc (jakub-gcc) wrote :

Created attachment 40485
gcc7-pr72813.patch

I guess the resolution of this PR depends on what exactly should happen when creating PCH files.
On -x c-header or -x c++-header, with -E we just preprocess, nothing unexpected.
For -S without -o it has been broken for many years, only partially "fixed" in r237955, but that change only affected the non-save-temps path, with -save-temps -S still fails:
error: output filename specified twice
For -S with -o, or -save-temps and say -c or none of -E/-S/-c, we produced some assembly.

Now, the sources say:
/* This is the point to write out a PCH if we're doing that.
   In that case we do not want to do anything else. */
and bails out early from those functions, but actually in the caller the compilation happily continues.

So, either the comment is wrong and we just want to produce full assembly (sometimes thrown away, because it is written into a temporary file, sometimes user visible), then we need something like the attached untested patch (plus perhaps the fixes for the -S -save-temps case). This choice means creating of *.gch files might be slightly slower than now, but not significantly, because most of the work is done anyway, and also means that if there are some post-parsing reported errors, they will be diagnosed.

Or, we do what the comment says and e.g. set flag_syntax_only at that point before the early return, which means that even callers would do nothing else. Compilation of PCH files would be faster, the assembly written would need to be declared to be unusable for anything, and perhaps some diagnostics would not be emitted if it would normally happen after the spot where we write the PCH file.