[cfe-commits] r52063 - in /cfe/trunk: include/clang/AST/DeclObjC.h lib/AST/DeclObjC.cpp lib/AST/TranslationUnit.cpp
Ted Kremenek
kremenek at apple.com
Fri Jun 6 14:05:33 PDT 2008
Author: kremenek
Date: Fri Jun 6 16:05:33 2008
New Revision: 52063
URL: http://llvm.org/viewvc/llvm-project?rev=52063&view=rev
Log:
Reclaim memory owned by ObjCForwardProtocolDecls.
Modified:
cfe/trunk/include/clang/AST/DeclObjC.h
cfe/trunk/lib/AST/DeclObjC.cpp
cfe/trunk/lib/AST/TranslationUnit.cpp
Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=52063&r1=52062&r2=52063&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Fri Jun 6 16:05:33 2008
@@ -692,6 +692,9 @@
ReferencedProtocols = 0;
}
}
+
+ virtual ~ObjCForwardProtocolDecl();
+
public:
static ObjCForwardProtocolDecl *Create(ASTContext &C, SourceLocation L,
ObjCProtocolDecl **Elts, unsigned Num);
@@ -713,6 +716,10 @@
return ReferencedProtocols[idx];
}
+ typedef ObjCProtocolDecl * const * iterator;
+ iterator begin() const { return ReferencedProtocols; }
+ iterator end() const { return ReferencedProtocols+NumReferencedProtocols; }
+
static bool classof(const Decl *D) {
return D->getKind() == ObjCForwardProtocol;
}
Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=52063&r1=52062&r2=52063&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Fri Jun 6 16:05:33 2008
@@ -159,6 +159,10 @@
return new (Mem) ObjCForwardProtocolDecl(L, Elts, NumElts);
}
+ObjCForwardProtocolDecl::~ObjCForwardProtocolDecl() {
+ delete [] ReferencedProtocols;
+}
+
ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C,
SourceLocation L,
IdentifierInfo *Id) {
Modified: cfe/trunk/lib/AST/TranslationUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TranslationUnit.cpp?rev=52063&r1=52062&r2=52063&view=diff
==============================================================================
--- cfe/trunk/lib/AST/TranslationUnit.cpp (original)
+++ cfe/trunk/lib/AST/TranslationUnit.cpp Fri Jun 6 16:05:33 2008
@@ -66,8 +66,9 @@
// FIXME: There is no clear ownership policy now for ObjCInterfaceDecls
// referenced by ObjCClassDecls. Some of them can be forward decls that
- // are never later defined (in which case the ObjCClassDecl owns them)
- // or the ObjCInterfaceDecl later becomes a real definition later.
+ // are never later defined (and forward decls can be referenced by
+ // multiple ObjCClassDecls) or the ObjCInterfaceDecl later
+ // becomes a real definition.
// Ideally we should have separate objects for forward declarations and
// definitions, obviating this problem. Because of this situation,
// referenced ObjCInterfaceDecls are destroyed here.
@@ -78,6 +79,23 @@
Killed.insert(*ID);
(*ID)->Destroy(*Context);
}
+
+ // FIXME: There is no clear ownership policy now for ObjCProtocolDecls
+ // referenced by ObjCForwardProtocolDecl. Some of them can be forward
+ // decls that are never later defined (and forward decls can be
+ // referenced by multiple ObjCClassDecls) or the ObjCProtocolDecl
+ // later becomes a real definition.
+ // Ideally we should have separate objects for forward declarations and
+ // definitions, obviating this problem. Because of this situation,
+ // referenced ObjCProtocolDecls are destroyed here.
+ if (ObjCForwardProtocolDecl* FDec = dyn_cast<ObjCForwardProtocolDecl>(*I))
+ for (ObjCForwardProtocolDecl::iterator ID=FDec->begin(),
+ ED=FDec->end(); ID!=ED; ++ID) {
+ if (!*ID || Killed.count(*ID)) continue;
+ Killed.insert(*ID);
+ (*ID)->Destroy(*Context);
+ }
+
(*I)->Destroy(*Context);
}
More information about the cfe-commits
mailing list