aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/Decl.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2008-05-20 00:43:19 +0000
committerTed Kremenek <kremenek@apple.com>2008-05-20 00:43:19 +0000
commit27f8a28bee33bb0e857cfe1a61c281bbc234b338 (patch)
tree5e0cc27d9b0948a8cd6bc99306411a03d35d49fe /lib/AST/Decl.cpp
parent017cbdfd5417d4d31ae6406421276f90269f75e2 (diff)
Try to plug some memory leaks...
1) Sema::ParseAST now constructs a TranslationUnit object to own the top-level Decls, which releases the top-level Decls upon exiting ParseAST. 2) Bug fix: TranslationUnit::~TranslationUnit handles the case where a Decl is added more than once as a top-level Decl. 3) Decl::Destroy is now a virtual method, obviating the need for a special dispatch based on DeclKind. 3) FunctionDecl::Destroy now releases its Body using its Destroy method. 4) Added Stmt::Destroy and Stmt::DestroyChildren, which recursively delete the child ASTs of a Stmt and call their dstors. We may need to special case dstor/Destroy methods for particular Stmt subclasses that own other dynamically allocated objects besides AST nodes. 5) REGRESSION: We temporarily are not deallocating attributes; a FIXME is provided. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51286 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/Decl.cpp')
-rw-r--r--lib/AST/Decl.cpp54
1 files changed, 13 insertions, 41 deletions
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp
index 1a7eecac32..a831c4ff9a 100644
--- a/lib/AST/Decl.cpp
+++ b/lib/AST/Decl.cpp
@@ -16,6 +16,8 @@
#include "clang/AST/Attr.h"
#include "clang/Basic/IdentifierTable.h"
#include "llvm/ADT/DenseMap.h"
+
+#include <stdio.h>
using namespace clang;
//===----------------------------------------------------------------------===//
@@ -314,8 +316,10 @@ Decl::~Decl() {
DeclAttrMapTy::iterator it = DeclAttrs->find(this);
assert(it != DeclAttrs->end() && "No attrs found but HasAttrs is true!");
- delete it->second;
+ // FIXME: Properly release attributes.
+ // delete it->second;
DeclAttrs->erase(it);
+
if (DeclAttrs->empty()) {
delete DeclAttrs;
DeclAttrs = 0;
@@ -366,47 +370,11 @@ void Decl::swapAttrs(Decl *RHS) {
}
-#define CASE(KIND) \
- case KIND: \
- static_cast<KIND##Decl *>(const_cast<Decl *>(this))->~KIND##Decl(); \
- break
-
-void Decl::Destroy(ASTContext& C) const {
- switch (getKind()) {
- CASE(TranslationUnit);
- CASE(Field);
- CASE(ObjCIvar);
- CASE(ObjCCategory);
- CASE(ObjCCategoryImpl);
- CASE(ObjCImplementation);
- CASE(ObjCProtocol);
- CASE(ObjCProperty);
- CASE(Namespace);
- CASE(Typedef);
- CASE(Enum);
- CASE(EnumConstant);
- CASE(Function);
- CASE(Var);
- CASE(ParmVar);
- CASE(ObjCInterface);
- CASE(ObjCCompatibleAlias);
- CASE(ObjCMethod);
- CASE(ObjCClass);
- CASE(ObjCForwardProtocol);
- CASE(LinkageSpec);
-
- case Struct: case Union: case Class:
- static_cast<RecordDecl *>(const_cast<Decl *>(this))->~RecordDecl();
- break;
-
- default: assert(0 && "Unknown decl kind!");
- }
-
+void Decl::Destroy(ASTContext& C) {
+ this->~Decl();
C.getAllocator().Deallocate((void *)this);
}
-#undef CASE
-
//===----------------------------------------------------------------------===//
// DeclContext Implementation
//===----------------------------------------------------------------------===//
@@ -442,10 +410,14 @@ const char *NamedDecl::getName() const {
FunctionDecl::~FunctionDecl() {
delete[] ParamInfo;
- delete Body;
- delete PreviousDeclaration;
}
+void FunctionDecl::Destroy(ASTContext& C) {
+ if (Body) Body->Destroy(C);
+ Decl::Destroy(C);
+}
+
+
Stmt *FunctionDecl::getBody(const FunctionDecl *&Definition) const {
for (const FunctionDecl *FD = this; FD != 0; FD = FD->PreviousDeclaration) {
if (FD->Body) {