]> granicus.if.org Git - clang/commitdiff
Fix the destruction "properly" in the sense that we actually destroy the
authorEli Friedman <eli.friedman@gmail.com>
Wed, 21 May 2008 05:33:10 +0000 (05:33 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Wed, 21 May 2008 05:33:10 +0000 (05:33 +0000)
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

Driver/SerializationTest.cpp
include/clang/AST/TranslationUnit.h
lib/AST/TranslationUnit.cpp

index 6e9309dc28ba9c662aec71b9067f3a950f4efc63..5f7b94fca409b7d30b65dc21ebb27f6b052dc845 100644 (file)
@@ -44,7 +44,10 @@ public:
   ~SerializationTest();
 
   virtual void Initialize(ASTContext& context) {
-    if (!TU) TU.reset(new TranslationUnit(context, lopts));
+    if (!TU) {
+      TU.reset(new TranslationUnit(context, lopts));
+      TU->SetOwnsDecls(false);
+    }
   }  
 
   virtual void HandleTopLevelDecl(Decl *D) {
index 6aa3a40b87cbab6b39124da8023952ce022afab3..13b29c14a8fb64b20379fd20393d00837865fa19 100644 (file)
@@ -35,13 +35,18 @@ class TranslationUnit {
   ASTContext* Context;
   std::vector<Decl*> TopLevelDecls;
   bool OwnsMetaData;
+  bool OwnsDecls;
 
   // The default ctor is only invoked during deserialization.
-  explicit TranslationUnit() : Context(NULL), OwnsMetaData(true) {}
+  explicit TranslationUnit() : Context(NULL), OwnsMetaData(true),
+                               OwnsDecls(true) {}
   
 public:
   explicit TranslationUnit(ASTContext& Ctx, const LangOptions& lopt)
-    : LangOpts(lopt), Context(&Ctx), OwnsMetaData(false) {}
+    : LangOpts(lopt), Context(&Ctx), OwnsMetaData(false),
+      OwnsDecls(true) {}
+
+  void SetOwnsDecls(bool val) { OwnsDecls = val; }
 
   ~TranslationUnit();
 
index bfe6ee27fbe5bdb543080faecd5d1ae9713a7b2b..f1505b062186712228db096f7246e964f93771ff 100644 (file)
@@ -31,7 +31,7 @@ enum { BasicMetadataBlock = 1,
        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 @@ TranslationUnit::~TranslationUnit() {
       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);