From 773cdc7c0dd3546ff083a1370b7e3712e5e286be Mon Sep 17 00:00:00 2001 From: Steve Naroff Date: Mon, 17 Nov 2008 22:29:32 +0000 Subject: [PATCH] Fix [sema] message lookup on super is incorrect Missing special lookup rule in Sema::ActOnInstanceMessage(). llvm-svn: 59467 --- clang/lib/Sema/SemaExprObjC.cpp | 18 +++++++++++++++++- clang/test/Analysis/PR2978.m | 1 + clang/test/SemaObjC/super.m | 25 +++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 clang/test/SemaObjC/super.m diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp index bc2f7f2d6f74..f6f3202ddb02 100644 --- a/clang/lib/Sema/SemaExprObjC.cpp +++ b/clang/lib/Sema/SemaExprObjC.cpp @@ -278,7 +278,23 @@ Sema::ExprResult Sema::ActOnInstanceMessage(ExprTy *receiver, Selector Sel, QualType ReceiverCType = Context.getCanonicalType(RExpr->getType()).getUnqualifiedType(); - + + // Handle messages to 'super'. + if (isa(RExpr)) { + ObjCMethodDecl *Method = 0; + if (ObjCMethodDecl *CurMeth = getCurMethodDecl()) { + // If we have an interface in scope, check 'super' methods. + if (ObjCInterfaceDecl *ClassDecl = CurMeth->getClassInterface()) + if (ObjCInterfaceDecl *SuperDecl = ClassDecl->getSuperClass()) + Method = SuperDecl->lookupInstanceMethod(Sel); + } + if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, "-", + lbrac, rbrac, returnType)) + return true; + return new ObjCMessageExpr(RExpr, Sel, returnType, Method, lbrac, rbrac, + ArgExprs, NumArgs); + } + // Handle messages to id. if (ReceiverCType == Context.getCanonicalType(Context.getObjCIdType()) || ReceiverCType->getAsBlockPointerType()) { diff --git a/clang/test/Analysis/PR2978.m b/clang/test/Analysis/PR2978.m index 69deec9860d7..aa5d173807b2 100644 --- a/clang/test/Analysis/PR2978.m +++ b/clang/test/Analysis/PR2978.m @@ -5,6 +5,7 @@ @interface NSObject - (void)release; +- dealloc; @end @interface MyClass : NSObject { diff --git a/clang/test/SemaObjC/super.m b/clang/test/SemaObjC/super.m new file mode 100644 index 000000000000..46b8b4a09741 --- /dev/null +++ b/clang/test/SemaObjC/super.m @@ -0,0 +1,25 @@ +// RUN: clang -fsyntax-only -verify %s + +@interface Foo +- iMethod; ++ cMethod; +@end + +@interface A +@end + +@interface B : A +- (void)instanceMethod; ++ classMethod; +@end + +@implementation B + +- (void)instanceMethod { + [super iMethod]; // expected-warning{{method '-iMethod' not found (return type defaults to 'id')}} +} + ++ classMethod { + [super cMethod]; // expected-warning{{method '+cMethod' not found (return type defaults to 'id')}} +} +@end