[cfe-commits] r141950 - in /cfe/trunk: include/clang/AST/DeclObjC.h lib/AST/DeclObjC.cpp lib/Sema/SemaDeclObjC.cpp test/PCH/method-redecls.m
Argyrios Kyrtzidis
akyrtzi at gmail.com
Fri Oct 14 01:02:31 PDT 2011
Author: akirtzidis
Date: Fri Oct 14 03:02:31 2011
New Revision: 141950
URL: http://llvm.org/viewvc/llvm-project?rev=141950&view=rev
Log:
Really protect from infinite loop when there are objc method redeclarations.
Serialization part will come later.
Modified:
cfe/trunk/include/clang/AST/DeclObjC.h
cfe/trunk/lib/AST/DeclObjC.cpp
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
cfe/trunk/test/PCH/method-redecls.m
Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=141950&r1=141949&r2=141950&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Fri Oct 14 03:02:31 2011
@@ -128,6 +128,9 @@
// Method has a definition.
unsigned IsDefined : 1;
+ // Method redeclaration in the same interface.
+ unsigned IsRedeclaration : 1;
+
// NOTE: VC++ treats enums as signed, avoid using ImplementationControl enum
/// @required/@optional
unsigned DeclImplementation : 2;
@@ -220,7 +223,7 @@
DeclContext(ObjCMethod), Family(InvalidObjCMethodFamily),
IsInstance(isInstance), IsVariadic(isVariadic),
IsSynthesized(isSynthesized),
- IsDefined(isDefined),
+ IsDefined(isDefined), IsRedeclaration(0),
DeclImplementation(impControl), objcDeclQualifier(OBJC_TQ_None),
RelatedResultType(HasRelatedResultType),
SelLocsKind(SelLoc_StandardNoSpace),
@@ -267,6 +270,10 @@
/// \brief Note whether this method has a related result type.
void SetRelatedResultType(bool RRT = true) { RelatedResultType = RRT; }
+
+ /// \brief True if this is a method redeclaration in the same interface.
+ bool isRedeclaration() const { return IsRedeclaration; }
+ void setAsRedeclaration(const ObjCMethodDecl *PrevMethod);
// Location information, modeled after the Stmt API.
SourceLocation getLocStart() const { return getLocation(); }
Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=141950&r1=141949&r2=141950&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Fri Oct 14 03:02:31 2011
@@ -351,6 +351,12 @@
HasRelatedResultType);
}
+void ObjCMethodDecl::setAsRedeclaration(const ObjCMethodDecl *PrevMethod) {
+ assert(PrevMethod);
+ getASTContext().setObjCMethodRedeclaration(PrevMethod, this);
+ IsRedeclaration = true;
+}
+
void ObjCMethodDecl::setParamsAndSelLocs(ASTContext &C,
ArrayRef<ParmVarDecl*> Params,
ArrayRef<SourceLocation> SelLocs) {
@@ -418,6 +424,12 @@
Redecl = CatD->getMethod(getSelector(), isInstanceMethod());
}
+ if (!Redecl && isRedeclaration()) {
+ // This is the last redeclaration, go back to the first method.
+ return cast<ObjCContainerDecl>(CtxD)->getMethod(getSelector(),
+ isInstanceMethod());
+ }
+
return Redecl ? Redecl : this;
}
Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=141950&r1=141949&r2=141950&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Fri Oct 14 03:02:31 2011
@@ -2168,7 +2168,7 @@
Method->setInvalidDecl();
} else {
if (PrevMethod)
- Context.setObjCMethodRedeclaration(PrevMethod, Method);
+ Method->setAsRedeclaration(PrevMethod);
InsMap[Method->getSelector()] = Method;
/// The following allows us to typecheck messages to "id".
AddInstanceMethodToGlobalPool(Method);
@@ -2189,7 +2189,7 @@
Method->setInvalidDecl();
} else {
if (PrevMethod)
- Context.setObjCMethodRedeclaration(PrevMethod, Method);
+ Method->setAsRedeclaration(PrevMethod);
ClsMap[Method->getSelector()] = Method;
/// The following allows us to typecheck messages to "Class".
AddFactoryMethodToGlobalPool(Method);
Modified: cfe/trunk/test/PCH/method-redecls.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/method-redecls.m?rev=141950&r1=141949&r2=141950&view=diff
==============================================================================
--- cfe/trunk/test/PCH/method-redecls.m (original)
+++ cfe/trunk/test/PCH/method-redecls.m Fri Oct 14 03:02:31 2011
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 -x objective-c -emit-pch -o %t
+// RUN: %clang_cc1 -x objective-c -emit-pch -o %t -D IMPL
// Avoid infinite loop because of method redeclarations.
@@ -8,6 +9,10 @@
-(void)meth;
@end
+#ifdef IMPL
+
@implementation Foo
-(void)meth { }
@end
+
+#endif
More information about the cfe-commits
mailing list