aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2011-03-09 20:18:06 +0000
committerFariborz Jahanian <fjahanian@apple.com>2011-03-09 20:18:06 +0000
commit61478065fbcafcf5295bb0fb796c9a92f2d861e0 (patch)
tree755e8e3f217853f32ad83d56fe868a1234e30322
parentb0f4b9a558933b307073f7cd7753602f94354ae9 (diff)
Lookup selector in protocol list of qualified objc type
to avoid a bogus warning. // rdar:// 9072298 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@127355 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Sema/Sema.h3
-rw-r--r--lib/Sema/SemaExprObjC.cpp17
-rw-r--r--lib/Sema/SemaStmt.cpp3
-rw-r--r--test/SemaObjC/foreach.m30
4 files changed, 52 insertions, 1 deletions
diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h
index f7d9e80c7b..b3761f36da 100644
--- a/include/clang/Sema/Sema.h
+++ b/include/clang/Sema/Sema.h
@@ -4551,6 +4551,9 @@ public:
ObjCInterfaceDecl *CDecl);
ObjCMethodDecl *LookupPrivateInstanceMethod(Selector Sel,
ObjCInterfaceDecl *ClassDecl);
+ ObjCMethodDecl *LookupMethodInQualifiedType(Selector Sel,
+ const ObjCObjectPointerType *OPT,
+ bool IsInstance);
ExprResult
HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT,
diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp
index 3d8d42fa00..5826f296c1 100644
--- a/lib/Sema/SemaExprObjC.cpp
+++ b/lib/Sema/SemaExprObjC.cpp
@@ -381,6 +381,23 @@ ObjCMethodDecl *Sema::LookupPrivateInstanceMethod(Selector Sel,
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::
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp
index ca37df9438..dae6bce626 100644
--- a/lib/Sema/SemaStmt.cpp
+++ b/lib/Sema/SemaStmt.cpp
@@ -991,7 +991,8 @@ Sema::ActOnObjCForCollectionStmt(SourceLocation ForLoc,
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)
diff --git a/test/SemaObjC/foreach.m b/test/SemaObjC/foreach.m
index 0f7fd9eea9..c865374e61 100644
--- a/test/SemaObjC/foreach.m
+++ b/test/SemaObjC/foreach.m
@@ -16,3 +16,33 @@ void f(NSArray *a) {
for (id thisKey in keys);
for (id thisKey in keys);
}
+
+/* // rdar://9072298 */
+@protocol NSObject @end
+
+@interface NSObject <NSObject> {
+ Class isa;
+}
+@end
+
+typedef struct {
+ unsigned long state;
+ id *itemsPtr;
+ unsigned long *mutationsPtr;
+ unsigned long extra[5];
+} NSFastEnumerationState;
+
+@protocol NSFastEnumeration
+
+- (unsigned long)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(unsigned long)len;
+
+@end
+
+int main ()
+{
+ NSObject<NSFastEnumeration>* collection = ((void*)0);
+ for (id thing in collection) { }
+
+ return 0;
+}
+