Patchwork [pch] Fix pch failure on mips-mti-linux-gnu

mail settings
Submitter Steve Ellcey
Date Nov. 21, 2012, 6:43 p.m.
Message ID <>
Download mbox | patch
Permalink /patch/200827/
State New
Headers show


Steve Ellcey - Nov. 21, 2012, 6:43 p.m.
While working on PR 55399 (pch broken on mips-mti-linux-gnu) I traced
through the execution of test gcc.dg/pch/common-1.c and in comparing r192714
and r192715 I found that in the earlier version the compiler gets to
pch_open_file (with common-1.h) and does this check:

  if (pfile->all_files
      && pfile->all_files->next_file) {

it finds that pfile->all_files->next_file is NULL and continues on in the

In the new version there is:

  if (pfile->all_files
      && pfile->all_files->next_file
      && !pfile->all_files->next_file->implicit_preinclude) {

and here it finds that pfile->all_files->next_file is true but
pfile->all_files->next_file->implicit_preinclude is false so it exits
the routine and this is why the code compiler doesn't find the
preprocessed header file.

Looking at pfile I see that pfile->all_files is pointing at stdc-predef.h
where implicit_preinclude is true but pfile->all_files->next_file is pointing
at common-1.c where implicit_preinclude is false.

My best guess as to why this is happening for me and not other people is that
the order of common-1.c and stdc-predef.h in this linked list is dependent on
how things are put into pfile->file_hash and for some reason stdc-predef.h
shows up before common-1.c for me but not for other people, where they get
common-1.c and then stdc-predef.h.

This patch checks for implicit_preinclude on both pfile->all_files and
pfile->all_files->next_file and it fixes the problem for me.  I tested
it on mips-mti-linux-gnu and had no regressions.

OK to checkin?

Steve Ellcey

2012-11-21  Steve Ellcey  <>

	PR pch/55399
	* files.c (pch_open_file): Fix check for implicit_preinclude.
Joseph S. Myers - Nov. 21, 2012, 8:51 p.m.
On Wed, 21 Nov 2012, Steve Ellcey  wrote:

> 2012-11-21  Steve Ellcey  <>
> 	PR pch/55399
> 	* files.c (pch_open_file): Fix check for implicit_preinclude.

OK.  I had the extra check in a previous version of my implicit 
preincludes patch, but took it out as it didn't seem to be needed in my 
final testing.


diff --git a/libcpp/files.c b/libcpp/files.c
index a8288dc..9f84d8c 100644
--- a/libcpp/files.c
+++ b/libcpp/files.c
@@ -295,7 +295,8 @@  pch_open_file (cpp_reader *pfile, _cpp_file *file, bool *invalid_pch)
      file or the command-line it is not a valid use of PCH.  */
   if (pfile->all_files
       && pfile->all_files->next_file
-      && !pfile->all_files->next_file->implicit_preinclude)
+      && !(pfile->all_files->implicit_preinclude
+	   || pfile->all_files->next_file->implicit_preinclude))
     return false;
   flen = strlen (path);