Relocate PCH-write call to catch deferred functions.  Radar 7657755.

llvm-svn: 96793
diff --git a/llvm-gcc-4.2/gcc/c-lang.c b/llvm-gcc-4.2/gcc/c-lang.c
index 81fb05b..c837f7f 100644
--- a/llvm-gcc-4.2/gcc/c-lang.c
+++ b/llvm-gcc-4.2/gcc/c-lang.c
@@ -88,6 +88,11 @@
 void
 finish_file (void)
 {
+  /* APPLE LOCAL begin radar 4874613 */
+  /* Bad parse errors.  Just forget about it.  */
+  if (!errorcount && !sorrycount && pch_file)
+    c_common_write_pch ();
+  /* APPLE LOCAL end radar 4874613 */
 }
 
 #include "gtype-c.h"
diff --git a/llvm-gcc-4.2/gcc/cp/cp-lang.c b/llvm-gcc-4.2/gcc/cp/cp-lang.c
index 9605272..95c5047 100644
--- a/llvm-gcc-4.2/gcc/cp/cp-lang.c
+++ b/llvm-gcc-4.2/gcc/cp/cp-lang.c
@@ -149,6 +149,12 @@
 finish_file (void)
 {
   cp_finish_file ();
+  /* APPLE LOCAL begin radar 4874613 */
+  /* Bad parse errors.  Just forget about it.  */
+  if (pch_file && lang_hooks.decls.global_bindings_p () &&
+      !current_class_type && !decl_namespace_list)
+    c_common_write_pch ();
+  /* APPLE LOCAL end radar 4874613 */
 }
 
 #include "gtype-cp.h"
diff --git a/llvm-gcc-4.2/gcc/cp/parser.c b/llvm-gcc-4.2/gcc/cp/parser.c
index 45358f0..62c0cd1 100644
--- a/llvm-gcc-4.2/gcc/cp/parser.c
+++ b/llvm-gcc-4.2/gcc/cp/parser.c
@@ -23492,13 +23492,6 @@
 				? dk_no_deferred : dk_no_check);
   error_occurred = cp_parser_translation_unit (the_parser);
   the_parser = NULL;
-  /* APPLE LOCAL begin radar 4874613 */
-  /* Bad parse errors.  Just forget about it.  */
-  if (! global_bindings_p () || current_class_type || decl_namespace_list)
-    return;
-  if (pch_file)
-    c_common_write_pch ();
-  /* APPLE LOCAL end radar 4874613 */
 }
 
 /* This variable must be provided by every front end.  */