Improve crash recovery cleanup to recovery CompilerInstances during crash recovery.  This was a huge resource "root" during crashes.

This change requires making a bunch of fundamental Clang structures (optionally) reference counted to allow correct
ownership semantics of these objects (e.g., ASTContext) to play out between an active ASTUnit and CompilerInstance
object.

llvm-svn: 128011
diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp
index 5c34e94..42da44c 100644
--- a/clang/lib/Frontend/FrontendAction.cpp
+++ b/clang/lib/Frontend/FrontendAction.cpp
@@ -258,10 +258,10 @@
   // matching EndSourceFile().
   failure:
   if (isCurrentFileAST()) {
-    CI.takeASTContext();
-    CI.takePreprocessor();
-    CI.takeSourceManager();
-    CI.takeFileManager();
+    CI.setASTContext(0);
+    CI.setPreprocessor(0);
+    CI.setSourceManager(0);
+    CI.setFileManager(0);
   }
 
   CI.getDiagnosticClient().EndSourceFile();
@@ -313,7 +313,7 @@
     CI.takeASTConsumer();
     if (!isCurrentFileAST()) {
       CI.takeSema();
-      CI.takeASTContext();
+      CI.resetAndLeakASTContext();
     }
   } else {
     if (!isCurrentFileAST()) {
@@ -342,10 +342,10 @@
 
   if (isCurrentFileAST()) {
     CI.takeSema();
-    CI.takeASTContext();
-    CI.takePreprocessor();
-    CI.takeSourceManager();
-    CI.takeFileManager();
+    CI.resetAndLeakASTContext();
+    CI.resetAndLeakPreprocessor();
+    CI.resetAndLeakSourceManager();
+    CI.resetAndLeakFileManager();
   }
 
   setCompilerInstance(0);