Remove the TopLevelDecls from TranslationUnit, since all of those decls are owned by the ASTContext's TranslationUnitDecl. There are definitely some leaking Decls now that I'll tackle tomorrow
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62568 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp
index 70792c4..5526be0 100644
--- a/lib/AST/DeclBase.cpp
+++ b/lib/AST/DeclBase.cpp
@@ -358,25 +358,26 @@
void Decl::Destroy(ASTContext& C) {
#if 0
- // FIXME: This causes double-destroys in some cases, so it is
- // disabled at the moment.
+ // FIXME: Once ownership is fully understood, we can enable this code
+ if (DeclContext *DC = dyn_cast<DeclContext>(this))
+ DC->decls_begin()->Destroy(C);
- // Observe the unrolled recursion. By setting N->NextDeclarator = 0x0
+ // Observe the unrolled recursion. By setting N->NextDeclInScope = 0x0
// within the loop, only the Destroy method for the first Decl
// will deallocate all of the Decls in a chain.
- Decl* N = SD->getNextDeclarator();
+ Decl* N = NextDeclInScope;
while (N) {
- Decl* Tmp = N->getNextDeclarator();
- N->NextDeclarator = 0x0;
+ Decl* Tmp = N->NextDeclInScope;
+ N->NextDeclInScope = 0;
N->Destroy(C);
N = Tmp;
}
-#endif
this->~Decl();
C.getAllocator().Deallocate((void *)this);
+#endif
}
Decl *Decl::castFromDeclContext (const DeclContext *D) {
@@ -427,14 +428,8 @@
}
void DeclContext::DestroyDecls(ASTContext &C) {
- for (decl_iterator D = decls_begin(); D != decls_end(); ) {
- // FIXME: assert that this condition holds.
- if ((*D)->getLexicalDeclContext() == this)
- // Advance the cursor (via NextDeclInScope) *before* doing the Destroy.
- (*D++)->Destroy(C);
- else
- ++D;
- }
+ for (decl_iterator D = decls_begin(); D != decls_end(); )
+ (*D++)->Destroy(C);
}
bool DeclContext::isTransparentContext() const {