On Oct 14, 2011, at 9:56 AM, jahanian wrote: > Don't we already have logic for finding previous declarations; say for ivars, > or c++ men functions?
No, because ivars and C++ member functions cannot be redeclared (wish it wasn't allowed for objc methods either..) For declarations that can get redeclared, like FunctionDecl, we use the Redeclarable template but I didn't want to increase the size of ObjC methods for such an uncommon case. -Argyrios > Can you use the same logic rather than using buffering of method decls? > > - fariborz > > On Oct 13, 2011, at 11:48 PM, Argyrios Kyrtzidis wrote: > >> Author: akirtzidis >> Date: Fri Oct 14 01:48:06 2011 >> New Revision: 141946 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=141946&view=rev >> Log: >> Keep track of objc method redeclarations in the same interface. >> >> Avoid possible infinite loop when iterating over an ObjCMethod's >> redeclarations. >> >> Added: >> cfe/trunk/test/PCH/method-redecls.m >> Modified: >> cfe/trunk/include/clang/AST/ASTContext.h >> cfe/trunk/lib/AST/DeclObjC.cpp >> cfe/trunk/lib/Sema/SemaDeclObjC.cpp >> >> Modified: cfe/trunk/include/clang/AST/ASTContext.h >> URL: >> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=141946&r1=141945&r2=141946&view=diff >> ============================================================================== >> --- cfe/trunk/include/clang/AST/ASTContext.h (original) >> +++ cfe/trunk/include/clang/AST/ASTContext.h Fri Oct 14 01:48:06 2011 >> @@ -150,6 +150,10 @@ >> >> /// \brief Mapping from ObjCContainers to their ObjCImplementations. >> llvm::DenseMap<ObjCContainerDecl*, ObjCImplDecl*> ObjCImpls; >> + >> + /// \brief Mapping from ObjCMethod to its duplicate declaration in the >> same >> + /// interface. >> + llvm::DenseMap<const ObjCMethodDecl*,const ObjCMethodDecl*> >> ObjCMethodRedecls; >> >> /// \brief Mapping from __block VarDecls to their copy initialization expr. >> llvm::DenseMap<const VarDecl*, Expr*> BlockVarCopyInits; >> @@ -1585,6 +1589,21 @@ >> /// \brief Set the implementation of ObjCCategoryDecl. >> void setObjCImplementation(ObjCCategoryDecl *CatD, >> ObjCCategoryImplDecl *ImplD); >> + >> + /// \brief Get the duplicate declaration of a ObjCMethod in the same >> + /// interface, or null if non exists. >> + const ObjCMethodDecl *getObjCMethodRedeclaration(ObjCMethodDecl *MD) >> const { >> + llvm::DenseMap<const ObjCMethodDecl*, const >> ObjCMethodDecl*>::const_iterator >> + I = ObjCMethodRedecls.find(MD); >> + if (I == ObjCMethodRedecls.end()) >> + return 0; >> + return I->second; >> + } >> + >> + void setObjCMethodRedeclaration(const ObjCMethodDecl *MD, >> + const ObjCMethodDecl *Redecl) { >> + ObjCMethodRedecls[MD] = Redecl; >> + } >> >> /// \brief Set the copy inialization expression of a block var decl. >> void setBlockVarCopyInits(VarDecl*VD, Expr* Init); >> >> Modified: cfe/trunk/lib/AST/DeclObjC.cpp >> URL: >> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=141946&r1=141945&r2=141946&view=diff >> ============================================================================== >> --- cfe/trunk/lib/AST/DeclObjC.cpp (original) >> +++ cfe/trunk/lib/AST/DeclObjC.cpp Fri Oct 14 01:48:06 2011 >> @@ -392,7 +392,11 @@ >> /// Otherwise it will return itself. >> ObjCMethodDecl *ObjCMethodDecl::getNextRedeclaration() { >> ASTContext &Ctx = getASTContext(); >> - ObjCMethodDecl *Redecl = 0; >> + ObjCMethodDecl *Redecl = >> + const_cast<ObjCMethodDecl*>(Ctx.getObjCMethodRedeclaration(this)); >> + if (Redecl) >> + return Redecl; >> + >> Decl *CtxD = cast<Decl>(getDeclContext()); >> >> if (ObjCInterfaceDecl *IFD = dyn_cast<ObjCInterfaceDecl>(CtxD)) { >> >> Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp >> URL: >> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=141946&r1=141945&r2=141946&view=diff >> ============================================================================== >> --- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original) >> +++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Fri Oct 14 01:48:06 2011 >> @@ -2167,6 +2167,8 @@ >> Diag(PrevMethod->getLocation(), diag::note_previous_declaration); >> Method->setInvalidDecl(); >> } else { >> + if (PrevMethod) >> + Context.setObjCMethodRedeclaration(PrevMethod, Method); >> InsMap[Method->getSelector()] = Method; >> /// The following allows us to typecheck messages to "id". >> AddInstanceMethodToGlobalPool(Method); >> @@ -2186,6 +2188,8 @@ >> Diag(PrevMethod->getLocation(), diag::note_previous_declaration); >> Method->setInvalidDecl(); >> } else { >> + if (PrevMethod) >> + Context.setObjCMethodRedeclaration(PrevMethod, Method); >> ClsMap[Method->getSelector()] = Method; >> /// The following allows us to typecheck messages to "Class". >> AddFactoryMethodToGlobalPool(Method); >> >> Added: cfe/trunk/test/PCH/method-redecls.m >> URL: >> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/method-redecls.m?rev=141946&view=auto >> ============================================================================== >> --- cfe/trunk/test/PCH/method-redecls.m (added) >> +++ cfe/trunk/test/PCH/method-redecls.m Fri Oct 14 01:48:06 2011 >> @@ -0,0 +1,13 @@ >> +// RUN: %clang_cc1 -x objective-c -emit-pch -o %t >> + >> +// Avoid infinite loop because of method redeclarations. >> + >> +@interface Foo >> +-(void)meth; >> +-(void)meth; >> +-(void)meth; >> +@end >> + >> +@implementation Foo >> +-(void)meth { } >> +@end >> >> >> _______________________________________________ >> cfe-commits mailing list >> [email protected] >> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits > _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
