diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index 6b257d211cba5d6be5258580bc732bf72131d16d..eff8cd4ae27e8b67cf8385213124ce678939a5a7 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,8 @@
+2009-09-22  Richard Guenther  <rguenther@suse.de>
+
+	PR pch/38987
+	* files.c (pch_open_file): Disallow non-toplevel PCH inclusion.
+
 2009-09-18  Chris Demetriou  <cgd@google.com>
 
 	PR preprocessor/28435:
diff --git a/libcpp/files.c b/libcpp/files.c
index 96ba7e80afc25c8de2e712b815955e10481747f0..ecf9d6c4651a598aa8b385800e12ace34301a114 100644
--- a/libcpp/files.c
+++ b/libcpp/files.c
@@ -288,6 +288,12 @@ pch_open_file (cpp_reader *pfile, _cpp_file *file, bool *invalid_pch)
   if (file->name[0] == '\0' || !pfile->cb.valid_pch)
     return false;
 
+  /* If the file is not included as first include from either the toplevel
+     file or the command-line it is not a valid use of PCH.  */
+  if (pfile->all_files
+      && pfile->all_files->next_file)
+    return false;
+
   flen = strlen (path);
   len = flen + sizeof (extension);
   pchname = XNEWVEC (char, len);