@@ -953,10 +953,6 @@ pph_stream_register (pph_stream *stream)
/* Add a mapping between STREAM's PPH file name and STREAM. */
pph_stream_registry_add_name (stream, stream->name);
-
- /* Mark this file as being in memory. This prevents opening the
- same file more than twice. */
- stream->in_memory_p = true;
}
@@ -2839,11 +2839,17 @@ pph_read_file_1 (pph_stream *stream)
VEC(tree,gc) *file_unemitted_tinfo_decls;
source_location cpp_token_replay_loc;
- /* If we have opened STREAM before, we do not need to re-read the rest
- of its body. */
+ /* If we already have STREAM in memory (or are reading it), ignore
+ this request. */
if (stream->in_memory_p)
return;
+ /* Mark this file as being in memory. This prevents multiple reads
+ from the same file. This scenario can happen in #include chains
+ where the top header file is also included by one of its children
+ (common in system headers). */
+ stream->in_memory_p = true;
+
if (flag_pph_tracer >= 1)
fprintf (pph_logfile, "PPH: Reading %s\n", stream->name);