[cfe-commits] r56771 - in /cfe/trunk: lib/Sema/Sema.h lib/Sema/SemaDeclObjC.cpp lib/Sema/SemaExprObjC.cpp test/SemaObjC/category-method-lookup.m

Steve Naroff snaroff at apple.com
Sun Sep 28 07:55:55 PDT 2008


Author: snaroff
Date: Sun Sep 28 09:55:53 2008
New Revision: 56771

URL: http://llvm.org/viewvc/llvm-project?rev=56771&view=rev
Log:
Fix <rdar://problem/6252129> implementation of method in category doesn't effectively declare it for methods below.

Added:
    cfe/trunk/test/SemaObjC/category-method-lookup.m
Modified:
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp
    cfe/trunk/lib/Sema/SemaExprObjC.cpp

Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=56771&r1=56770&r2=56771&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Sun Sep 28 09:55:53 2008
@@ -92,10 +92,14 @@
   /// This is only necessary for issuing pretty diagnostics.
   llvm::SmallVector<TypedefDecl*, 24> ExtVectorDecls;
 
-  /// ObjCImplementations - Keep track of all of the classes with
-  /// @implementation's, so that we can emit errors on duplicates.
+  /// ObjCImplementations - Keep track of all class @implementations
+  /// so we can emit errors on duplicates.
   llvm::DenseMap<IdentifierInfo*, ObjCImplementationDecl*> ObjCImplementations;
   
+  /// ObjCCategoryImpls - Maintain a list of category implementations so 
+  /// we can check for duplicates and find local method declarations.
+  llvm::SmallVector<ObjCCategoryImplDecl*, 8> ObjCCategoryImpls;
+  
   /// ObjCProtocols - Keep track of all protocol declarations declared
   /// with @protocol keyword, so that we can emit errors on duplicates and
   /// find the declarations when needed.

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Sun Sep 28 09:55:53 2008
@@ -429,6 +429,7 @@
 
   /// TODO: Check that CatName, category name, is not used in another
   // implementation.
+  ObjCCategoryImpls.push_back(CDecl);
   return CDecl;
 }
 

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Sun Sep 28 09:55:53 2008
@@ -233,6 +233,14 @@
     if (ObjCImplementationDecl *ImpDecl = 
         ObjCImplementations[ClassDecl->getIdentifier()])
       Method = ImpDecl->getClassMethod(Sel);
+      
+    // Look through local category implementations associated with the class.
+    if (!Method) {
+      for (unsigned i = 0; i < ObjCCategoryImpls.size() && !Method; i++) {
+        if (ObjCCategoryImpls[i]->getClassInterface() == ClassDecl)
+          Method = ObjCCategoryImpls[i]->getClassMethod(Sel);
+      }
+    }
   }
   // Before we give up, check if the selector is an instance method.
   if (!Method)

Added: cfe/trunk/test/SemaObjC/category-method-lookup.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/category-method-lookup.m?rev=56771&view=auto

==============================================================================
--- cfe/trunk/test/SemaObjC/category-method-lookup.m (added)
+++ cfe/trunk/test/SemaObjC/category-method-lookup.m Sun Sep 28 09:55:53 2008
@@ -0,0 +1,31 @@
+// RUN: clang -fsyntax-only -verify %s
+
+ at interface Foo
+ at end
+ at implementation Foo
+ at end
+
+ at implementation Foo(Whatever)
++(float)returnsFloat { return 7.0; }
+ at end
+
+ at interface Foo (MoreStuff)
++(int)returnsInt;
+ at end
+
+ at implementation Foo (MoreStuff)
++(int)returnsInt {
+  return 0;
+}
+
++(void)returnsNothing {
+}
+-(int)callsReturnsInt {
+  float f = [Foo returnsFloat]; // GCC doesn't find this method (which is a bug IMHO).
+  [Foo returnsNothing];
+  return [Foo returnsInt];
+}
+ at end
+
+int main() {return 0;}
+





More information about the cfe-commits mailing list