This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[pph] Tolerate missing and invalid PPH files (issue5475055)


We currently emit hard errors when a PPH image is missing or invalid.
This is not ideal, because in these cases, what the compiler could do
is to simply use the original text header file.  After all, they are
interchangeable.

Additionally, this helps the current implementation into finding other
bugs, if a header failed to pre-parse, it can block many other
headers from pre-parsing.

I have created two warning flags: -Winvalid-pph and -Wmissing-pph.
This way, an implementation can choose to build with these warnings
and -Werror to stop the build, if needed.

Tested on x86_64.  Committed to branch.


Diego.


c-family/ChangeLog.pph

	* c.opt (Winvalid-pph, Wmissing-pph): New flags.

cp/ChangeLog.pph

	* pph-core.c (pph_is_valid_here): Call warning_at instead of
	error_at.
	(pph_include_handler): If pph_read_file returns NULL, emit
	warning and proceed with textual header parsing.
	* pph-in.c (pph_read_file): Do not call fatal_error if
	FILENAME is not found.


diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index e390479..c0095fc 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -448,6 +448,11 @@ Winvalid-pch
 C ObjC C++ ObjC++ Warning
 Warn about PCH files that are found but not used
 
+Winvalid-pph
+C++ Warning
+Warn about PPH files that are found but cannot used
+
+
 Wjump-misses-init
 C ObjC Var(warn_jump_misses_init) Init(-1) Warning
 Warn when a jump misses a variable initialization
@@ -492,6 +497,10 @@ Wmissing-prototypes
 C ObjC Var(warn_missing_prototypes) Warning
 Warn about global functions without prototypes
 
+Wmissing-pph
+C++ Warning
+Warn about missing PPH files
+
 Wmultichar
 C ObjC C++ ObjC++ Warning
 Warn about use of multi-character character constants
diff --git a/gcc/cp/pph-core.c b/gcc/cp/pph-core.c
index 76765d9..33ed64b 100644
--- a/gcc/cp/pph-core.c
+++ b/gcc/cp/pph-core.c
@@ -586,7 +586,8 @@ pph_is_valid_here (const char *name, location_t loc)
      the original text file.  */
   if (scope_chain->x_brace_nesting > 0)
     {
-      error_at (loc, "PPH file %s not included at global scope", name);
+      warning_at (loc, OPT_Winvalid_pph,
+		  "PPH file %s not included at global scope", name);
       return false;
     }
 
@@ -626,22 +627,22 @@ pph_include_handler (cpp_reader *reader,
       && pph_is_valid_here (name, loc)
       && !cpp_included_before (reader, name, input_location))
     {
-      pph_stream *include;
-
-      /* Hack. We do this to mimic what the non-pph compiler does in
-	_cpp_stack_include as our goal is to have identical line_tables.  */
-      line_table->highest_location--;
-
-      include = pph_read_file (pph_file);
-
-      /* If we are generating a new PPH image, add the stream we just
-	 read to the list of includes.   This way, the parser will be
-	 able to resolve references to symbols in INCLUDE and its
-	 children.  */
-      if (pph_writer_enabled_p ())
-	pph_writer_add_include (include);
-
-      read_text_file_p = false;
+      pph_stream *include = pph_read_file (pph_file);
+      if (include)
+	{
+	  /* If we are generating a new PPH image, add the stream we
+	     just read to the list of includes.   This way, the parser
+	     will be able to resolve references to symbols in INCLUDE
+	     and its children.  */
+	  if (pph_writer_enabled_p ())
+	    pph_writer_add_include (include);
+
+	  read_text_file_p = false;
+	}
+      else
+	warning_at (input_location, OPT_Wmissing_pph,
+		    "cannot open PPH file %s for reading: %m\n"
+		    "using original header %s", pph_file, name);
     }
 
   return read_text_file_p;
diff --git a/gcc/cp/pph-in.c b/gcc/cp/pph-in.c
index 323516d..780d208 100644
--- a/gcc/cp/pph-in.c
+++ b/gcc/cp/pph-in.c
@@ -2900,10 +2900,15 @@ pph_stream *
 pph_read_file (const char *filename)
 {
   pph_stream *stream = pph_stream_open (filename, "rb");
-  if (stream == NULL)
-    fatal_error ("cannot open PPH file %s for reading: %m", filename);
+  if (stream)
+    {
+      /* FIXME pph.  We do this to mimic what the non-pph compiler
+	 does in _cpp_stack_include as our goal is to have identical
+	 line_tables.  */
+      line_table->highest_location--;
 
-  pph_read_file_1 (stream);
+      pph_read_file_1 (stream);
+    }
 
   return stream;
 }

--
This patch is available for review at http://codereview.appspot.com/5475055


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]