Fix the destruction "properly" in the sense that we actually destroy the 
ASTs.  This is a hack, but I haven't considered how we really 
want to do this.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51364 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/TranslationUnit.cpp b/lib/AST/TranslationUnit.cpp
index bfe6ee2..f1505b0 100644
--- a/lib/AST/TranslationUnit.cpp
+++ b/lib/AST/TranslationUnit.cpp
@@ -31,7 +31,7 @@
        DeclsBlock = 3 };
 
 TranslationUnit::~TranslationUnit() {
-  if (OwnsMetaData && Context) {
+  if (OwnsDecls) {
     llvm::DenseSet<Decl*> Killed;
     for (iterator I=begin(), E=end(); I!=E; ++I) {
       if (Killed.count(*I)) continue;
@@ -39,10 +39,13 @@
       Killed.insert(*I);
       (*I)->Destroy(*Context);
     }
+  }
 
+  if (OwnsMetaData && Context) {
     // The ASTContext object has the sole references to the IdentifierTable
     // Selectors, and the Target information.  Go and delete them, since
     // the TranslationUnit effectively owns them.
+    
     delete &(Context->Idents);
     delete &(Context->Selectors);
     delete &(Context->Target);