[cfe-commits] r127355 - in /cfe/trunk: include/clang/Sema/Sema.h lib/Sema/SemaExprObjC.cpp lib/Sema/SemaStmt.cpp test/SemaObjC/foreach.m

Fariborz Jahanian fjahanian at apple.com
Wed Mar 9 12:18:06 PST 2011


Author: fjahanian
Date: Wed Mar  9 14:18:06 2011
New Revision: 127355

URL: http://llvm.org/viewvc/llvm-project?rev=127355&view=rev
Log:
Lookup selector in protocol list of qualified objc type
to avoid a bogus warning. // rdar:// 9072298


Modified:
    cfe/trunk/include/clang/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaExprObjC.cpp
    cfe/trunk/lib/Sema/SemaStmt.cpp
    cfe/trunk/test/SemaObjC/foreach.m

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=127355&r1=127354&r2=127355&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Wed Mar  9 14:18:06 2011
@@ -4551,6 +4551,9 @@
                                            ObjCInterfaceDecl *CDecl);
   ObjCMethodDecl *LookupPrivateInstanceMethod(Selector Sel,
                                               ObjCInterfaceDecl *ClassDecl);
+  ObjCMethodDecl *LookupMethodInQualifiedType(Selector Sel,
+                                              const ObjCObjectPointerType *OPT,
+                                              bool IsInstance);
 
   ExprResult
   HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT,

Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=127355&r1=127354&r2=127355&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Wed Mar  9 14:18:06 2011
@@ -381,6 +381,23 @@
   return Method;
 }
 
+/// LookupMethodInQualifiedType - Lookups up a method in protocol qualifier 
+/// list of a qualified objective pointer type.
+ObjCMethodDecl *Sema::LookupMethodInQualifiedType(Selector Sel,
+                                              const ObjCObjectPointerType *OPT,
+                                              bool Instance)
+{
+  ObjCMethodDecl *MD = 0;
+  for (ObjCObjectPointerType::qual_iterator I = OPT->qual_begin(),
+       E = OPT->qual_end(); I != E; ++I) {
+    ObjCProtocolDecl *PROTO = (*I);
+    if ((MD = PROTO->lookupMethod(Sel, Instance))) {
+      return MD;
+    }
+  }
+  return 0;
+}
+
 /// HandleExprPropertyRefExpr - Handle foo.bar where foo is a pointer to an
 /// objective C interface.  This is a property reference expression.
 ExprResult Sema::

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=127355&r1=127354&r2=127355&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Wed Mar  9 14:18:06 2011
@@ -991,7 +991,8 @@
       Selector CSelector = Context.Selectors.getSelector(3, &KeyIdents[0]);
       if (ObjCInterfaceDecl *IDecl = OPT->getInterfaceDecl()) {
         if (!IDecl->isForwardDecl() &&
-            !IDecl->lookupInstanceMethod(CSelector)) {
+            !IDecl->lookupInstanceMethod(CSelector) &&
+            !LookupMethodInQualifiedType(CSelector, OPT, true)) {
           // Must further look into private implementation methods.
           if (!LookupPrivateInstanceMethod(CSelector, IDecl))
             Diag(ForLoc, diag::warn_collection_expr_type)

Modified: cfe/trunk/test/SemaObjC/foreach.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/foreach.m?rev=127355&r1=127354&r2=127355&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/foreach.m (original)
+++ cfe/trunk/test/SemaObjC/foreach.m Wed Mar  9 14:18:06 2011
@@ -16,3 +16,33 @@
   for (id thisKey in keys);
   for (id thisKey in keys);
 }
+
+/* // rdar://9072298 */
+ at protocol NSObject @end
+
+ at interface NSObject <NSObject> {
+    Class isa;
+}
+ at end
+
+typedef struct {
+    unsigned long state;
+    id *itemsPtr;
+    unsigned long *mutationsPtr;
+    unsigned long extra[5];
+} NSFastEnumerationState;
+
+ at protocol NSFastEnumeration
+
+- (unsigned long)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(unsigned long)len;
+
+ at end
+
+int main ()
+{
+ NSObject<NSFastEnumeration>* collection = ((void*)0);
+ for (id thing in collection) { }
+
+ return 0;
+}
+





More information about the cfe-commits mailing list