simplify ParseAST by sucking -disable-free handling logic up into
clang.cpp


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67890 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/clang-cc/clang.cpp b/tools/clang-cc/clang.cpp
index 5d3f68d..3b2afa9 100644
--- a/tools/clang-cc/clang.cpp
+++ b/tools/clang-cc/clang.cpp
@@ -1476,17 +1476,26 @@
   }
 
   if (Consumer) {
-    TranslationUnit *TU = 0;
+    llvm::OwningPtr<ASTContext> ContextOwner;
+    llvm::OwningPtr<TranslationUnit> TranslationUnitOwner;
+
+    ContextOwner.reset(new ASTContext(PP.getLangOptions(),
+                                      PP.getSourceManager(),
+                                      PP.getTargetInfo(),
+                                      PP.getIdentifierTable(),
+                                      PP.getSelectorTable(),
+                                      /* FreeMemory = */ !DisableFree));
+    TranslationUnitOwner.reset(new TranslationUnit(*ContextOwner.get()));
+    
+    
+    ParseAST(PP, Consumer.get(), *TranslationUnitOwner.get(), Stats);
+    
+    // If in -disable-free mode, don't deallocate these when they go out of
+    // scope.
     if (DisableFree) {
-      ASTContext *Context = new ASTContext(PP.getLangOptions(),
-                                           PP.getSourceManager(),
-                                           PP.getTargetInfo(),
-                                           PP.getIdentifierTable(),
-                                           PP.getSelectorTable(),
-                                           /* FreeMemory = */ false);
-      TU = new TranslationUnit(*Context);
+      ContextOwner.take();
+      TranslationUnitOwner.take();
     }
-    ParseAST(PP, Consumer.get(), TU, Stats);
   }
 
   if (VerifyDiagnostics)