[cfe-commits] r59467 - in /cfe/trunk: lib/Sema/SemaExprObjC.cpp test/Analysis/PR2978.m test/SemaObjC/super.m

Steve Naroff snaroff at apple.com
Mon Nov 17 14:29:41 PST 2008


Author: snaroff
Date: Mon Nov 17 16:29:32 2008
New Revision: 59467

URL: http://llvm.org/viewvc/llvm-project?rev=59467&view=rev
Log:
Fix <rdar://problem/6333904> [sema] message lookup on super is incorrect

Missing special lookup rule in Sema::ActOnInstanceMessage().

Added:
    cfe/trunk/test/SemaObjC/super.m
Modified:
    cfe/trunk/lib/Sema/SemaExprObjC.cpp
    cfe/trunk/test/Analysis/PR2978.m

Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=59467&r1=59466&r2=59467&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Mon Nov 17 16:29:32 2008
@@ -278,7 +278,23 @@
 
   QualType ReceiverCType =
     Context.getCanonicalType(RExpr->getType()).getUnqualifiedType();
-  
+
+  // Handle messages to 'super'.
+  if (isa<ObjCSuperExpr>(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()) {

Modified: cfe/trunk/test/Analysis/PR2978.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/PR2978.m?rev=59467&r1=59466&r2=59467&view=diff

==============================================================================
--- cfe/trunk/test/Analysis/PR2978.m (original)
+++ cfe/trunk/test/Analysis/PR2978.m Mon Nov 17 16:29:32 2008
@@ -5,6 +5,7 @@
 
 @interface NSObject
 - (void)release;
+- dealloc;
 @end
 
 @interface MyClass : NSObject {

Added: cfe/trunk/test/SemaObjC/super.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/super.m?rev=59467&view=auto

==============================================================================
--- cfe/trunk/test/SemaObjC/super.m (added)
+++ cfe/trunk/test/SemaObjC/super.m Mon Nov 17 16:29:32 2008
@@ -0,0 +1,25 @@
+// RUN: clang -fsyntax-only -verify %s
+
+ at interface Foo
+- iMethod;
++ cMethod;
+ at end
+
+ at interface A
+ at end
+
+ at interface B : A
+- (void)instanceMethod;
++ classMethod;
+ at end
+
+ at 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')}}
+}
+ at end





More information about the cfe-commits mailing list