[cfe-commits] r51364 - in /cfe/trunk: Driver/SerializationTest.cpp include/clang/AST/TranslationUnit.h lib/AST/TranslationUnit.cpp
Eli Friedman
eli.friedman at gmail.com
Tue May 20 22:33:11 PDT 2008
Author: efriedma
Date: Wed May 21 00:33:10 2008
New Revision: 51364
URL: http://llvm.org/viewvc/llvm-project?rev=51364&view=rev
Log:
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.
Modified:
cfe/trunk/Driver/SerializationTest.cpp
cfe/trunk/include/clang/AST/TranslationUnit.h
cfe/trunk/lib/AST/TranslationUnit.cpp
Modified: cfe/trunk/Driver/SerializationTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/SerializationTest.cpp?rev=51364&r1=51363&r2=51364&view=diff
==============================================================================
--- cfe/trunk/Driver/SerializationTest.cpp (original)
+++ cfe/trunk/Driver/SerializationTest.cpp Wed May 21 00:33:10 2008
@@ -44,7 +44,10 @@
~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) {
Modified: cfe/trunk/include/clang/AST/TranslationUnit.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TranslationUnit.h?rev=51364&r1=51363&r2=51364&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/TranslationUnit.h (original)
+++ cfe/trunk/include/clang/AST/TranslationUnit.h Wed May 21 00:33:10 2008
@@ -35,13 +35,18 @@
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();
Modified: cfe/trunk/lib/AST/TranslationUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TranslationUnit.cpp?rev=51364&r1=51363&r2=51364&view=diff
==============================================================================
--- cfe/trunk/lib/AST/TranslationUnit.cpp (original)
+++ cfe/trunk/lib/AST/TranslationUnit.cpp Wed May 21 00:33:10 2008
@@ -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);
More information about the cfe-commits
mailing list