[PATCH] Fix -H vs. PCH (PR preprocessor/36649)

Jakub Jelinek jakub@redhat.com
Wed Jul 30 15:55:00 GMT 2008


Hi!

When line_table has been changed from a structure to a pointer
into GC memory, if a PCH header isn't among -include headers,
-H setting basically comes from the command line when the *.gch
header has been precompiled.  So, if a header is precompiled
with -H and later on something includes it, compiled without -H,
headers will be still printed as if -H was given, and similarly
if a header is precompiled without -H, even when compiling something
with -H nothing will be printed.

The following patch fixes it by saving/restoring the
line_table->trace_includes
setting around PCH reading, similarly how e.g. location is saved.

Ok for trunk/4.3?

2008-07-30  Jakub Jelinek  <jakub@redhat.com>

	PR preprocessor/36649
	* c-pch.c (c_common_read_pch): Save and restore
	line_table->trace_includes across PCH restore.

	* gcc.dg/pch/cpp-3.c: New test.
	* gcc.dg/pch/cpp-3.hs: New file.
	* gcc.dg/pch/cpp-3a.h: New file.
	* gcc.dg/pch/cpp-3b.h: New file.

--- gcc/c-pch.c.jj	2008-07-28 16:44:55.000000000 +0200
+++ gcc/c-pch.c	2008-07-30 00:33:11.000000000 +0200
@@ -367,6 +367,7 @@ c_common_read_pch (cpp_reader *pfile, co
   struct c_pch_header h;
   struct save_macro_data *smd;
   expanded_location saved_loc;
+  bool saved_trace_includes;
 
   f = fdopen (fd, "rb");
   if (f == NULL)
@@ -412,6 +413,7 @@ c_common_read_pch (cpp_reader *pfile, co
 
   /* Save the location and then restore it after reading the PCH.  */
   saved_loc = expand_location (line_table->highest_line);
+  saved_trace_includes = line_table->trace_includes;
 
   cpp_prepare_state (pfile, &smd);
 
@@ -425,6 +427,7 @@ c_common_read_pch (cpp_reader *pfile, co
 
   fclose (f);
 
+  line_table->trace_includes = saved_trace_includes;
   cpp_set_line_map (pfile, line_table);
   linemap_add (line_table, LC_RENAME, 0, saved_loc.file, saved_loc.line);
 
--- gcc/testsuite/gcc.dg/pch/cpp-3.c.jj	2008-07-30 10:18:49.000000000 +0200
+++ gcc/testsuite/gcc.dg/pch/cpp-3.c	2008-07-30 10:40:23.000000000 +0200
@@ -0,0 +1,13 @@
+/* PR preprocessor/36649 */
+/* { dg-do compile } */
+/* { dg-options "-H -I." } */
+/* { dg-message "cpp-3.h\[^\n\]*(\n\[^\n\]*cpp-3.c)?\n\[^\n\]*cpp-3a.h\n\[^\n\]*cpp-3b.h" "" { target *-*-* } 0 } */
+
+#include "cpp-3.h"
+#include "cpp-3a.h"
+
+int
+main (void)
+{
+  return 0;
+}
--- gcc/testsuite/gcc.dg/pch/cpp-3.hs.jj	2008-07-30 10:18:54.000000000 +0200
+++ gcc/testsuite/gcc.dg/pch/cpp-3.hs	2008-07-30 10:19:05.000000000 +0200
@@ -0,0 +1 @@
+/* empty */
--- gcc/testsuite/gcc.dg/pch/cpp-3a.h.jj	2008-07-30 10:19:56.000000000 +0200
+++ gcc/testsuite/gcc.dg/pch/cpp-3a.h	2008-07-30 10:20:28.000000000 +0200
@@ -0,0 +1 @@
+#include "cpp-3b.h"
--- gcc/testsuite/gcc.dg/pch/cpp-3b.h.jj	2008-07-30 10:20:05.000000000 +0200
+++ gcc/testsuite/gcc.dg/pch/cpp-3b.h	2008-07-30 10:19:05.000000000 +0200
@@ -0,0 +1 @@
+/* empty */

	Jakub



More information about the Gcc-patches mailing list