From: Eli Friedman Date: Wed, 21 May 2008 05:33:10 +0000 (+0000) Subject: Fix the destruction "properly" in the sense that we actually destroy the X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5f1adf8fb4b41988a8715492cc97c62873d25969;p=clang 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/Driver/SerializationTest.cpp b/Driver/SerializationTest.cpp index 6e9309dc28..5f7b94fca4 100644 --- a/Driver/SerializationTest.cpp +++ b/Driver/SerializationTest.cpp @@ -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) { diff --git a/include/clang/AST/TranslationUnit.h b/include/clang/AST/TranslationUnit.h index 6aa3a40b87..13b29c14a8 100644 --- a/include/clang/AST/TranslationUnit.h +++ b/include/clang/AST/TranslationUnit.h @@ -35,13 +35,18 @@ class TranslationUnit { ASTContext* Context; std::vector 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(); diff --git a/lib/AST/TranslationUnit.cpp b/lib/AST/TranslationUnit.cpp index bfe6ee27fb..f1505b0621 100644 --- a/lib/AST/TranslationUnit.cpp +++ b/lib/AST/TranslationUnit.cpp @@ -31,7 +31,7 @@ enum { BasicMetadataBlock = 1, DeclsBlock = 3 }; TranslationUnit::~TranslationUnit() { - if (OwnsMetaData && Context) { + if (OwnsDecls) { llvm::DenseSet 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);