[cfe-commits] r110964 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaStmt.cpp test/CodeGenObjC/for-in.m test/SemaObjCXX/instantiate-stmt.mm

Fariborz Jahanian fjahanian at apple.com
Thu Aug 12 15:25:43 PDT 2010


Author: fjahanian
Date: Thu Aug 12 17:25:42 2010
New Revision: 110964

URL: http://llvm.org/viewvc/llvm-project?rev=110964&view=rev
Log:
Patch to issue warning when colllection expresion's type
does not implement 'countByEnumeratingWithState' API.
Implements radar 7634669.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaStmt.cpp
    cfe/trunk/test/CodeGenObjC/for-in.m
    cfe/trunk/test/SemaObjCXX/instantiate-stmt.mm

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=110964&r1=110963&r2=110964&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Aug 12 17:25:42 2010
@@ -3170,6 +3170,8 @@
   "selector element type %0 is not a valid object">;
 def err_collection_expr_type : Error<
   "collection expression type %0 is not a valid object">;
+def warn_collection_expr_type : Warning<
+  "collection expression type %0 may not respond to %1">;
 
 def err_invalid_conversion_between_ext_vectors : Error<
   "invalid conversion between ext-vector type %0 and %1">;

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=110964&r1=110963&r2=110964&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Thu Aug 12 17:25:42 2010
@@ -941,6 +941,27 @@
     if (!SecondType->isObjCObjectPointerType())
       Diag(ForLoc, diag::err_collection_expr_type)
         << SecondType << Second->getSourceRange();
+    else if (const ObjCObjectPointerType *OPT =
+             SecondType->getAsObjCInterfacePointerType()) {
+      llvm::SmallVector<IdentifierInfo *, 4> KeyIdents;
+      IdentifierInfo* selIdent = 
+        &Context.Idents.get("countByEnumeratingWithState");
+      KeyIdents.push_back(selIdent);
+      selIdent = &Context.Idents.get("objects");
+      KeyIdents.push_back(selIdent);
+      selIdent = &Context.Idents.get("count");
+      KeyIdents.push_back(selIdent);
+      Selector CSelector = Context.Selectors.getSelector(3, &KeyIdents[0]);
+      if (ObjCInterfaceDecl *IDecl = OPT->getInterfaceDecl()) {
+        if (!IDecl->isForwardDecl() && 
+            !IDecl->lookupInstanceMethod(CSelector)) {
+          // Must further look into privaye implementation methods.
+          if (!LookupPrivateInstanceMethod(CSelector, IDecl))
+            Diag(ForLoc, diag::warn_collection_expr_type)
+              << SecondType << CSelector << Second->getSourceRange();
+        }
+      }
+    }
   }
   first.release();
   second.release();

Modified: cfe/trunk/test/CodeGenObjC/for-in.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/for-in.m?rev=110964&r1=110963&r2=110964&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenObjC/for-in.m (original)
+++ cfe/trunk/test/CodeGenObjC/for-in.m Thu Aug 12 17:25:42 2010
@@ -23,7 +23,7 @@
 
   p("array.length: %d\n", [array count]);
   unsigned index = 0;
-  for (NSString *i in array) {
+  for (NSString *i in array) {	// expected-warning {{collection expression type 'NSArray *' may not respond}}
     p("element %d: %s\n", index++, [i cString]);
   }
 }
@@ -33,7 +33,7 @@
 
   p("array.length: %d\n", [array count]);
   unsigned index = 0;
-  for (NSString *i in array) {
+  for (NSString *i in array) {	// expected-warning {{collection expression type 'NSArray *' may not respond}}
     index++;
     if (index == 10)
       continue;

Modified: cfe/trunk/test/SemaObjCXX/instantiate-stmt.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/instantiate-stmt.mm?rev=110964&r1=110963&r2=110964&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjCXX/instantiate-stmt.mm (original)
+++ cfe/trunk/test/SemaObjCXX/instantiate-stmt.mm Thu Aug 12 17:25:42 2010
@@ -25,6 +25,7 @@
 
 // fast enumeration
 @interface NSArray
+- (unsigned int)countByEnumeratingWithState:  (struct __objcFastEnumerationState *)state objects:  (id *)items count:(unsigned int)stackcount;
 @end
 
 @interface NSString





More information about the cfe-commits mailing list