]> granicus.if.org Git - clang/commitdiff
ObjectiveC: canonicalize "kindof id" to "id".
authorManman Ren <manman.ren@gmail.com>
Fri, 20 May 2016 17:29:43 +0000 (17:29 +0000)
committerManman Ren <manman.ren@gmail.com>
Fri, 20 May 2016 17:29:43 +0000 (17:29 +0000)
There is no need to apply kindof on an unqualified id type.

rdar://24753825

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@270241 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaType.cpp
test/SemaObjC/kindof.m

index 57295fde0b42ad33852c2fb17fc3fbbb89f03b07..d99d9521f47bac165f38d80b1890f69405be6417 100644 (file)
@@ -5900,10 +5900,11 @@ bool Sema::checkObjCKindOfType(QualType &type, SourceLocation loc) {
 
   // Rebuild the "equivalent" type, which pushes __kindof down into
   // the object type.
-  QualType equivType = Context.getObjCObjectType(objType->getBaseType(),
-                                                 objType->getTypeArgsAsWritten(),
-                                                 objType->getProtocols(),
-                                                 /*isKindOf=*/true);
+  // There is no need to apply kindof on an unqualified id type.
+  QualType equivType = Context.getObjCObjectType(
+      objType->getBaseType(), objType->getTypeArgsAsWritten(),
+      objType->getProtocols(),
+      /*isKindOf=*/objType->isObjCUnqualifiedId() ? false : true);
 
   // If we started with an object pointer type, rebuild it.
   if (ptrType) {
index aa5a0db331fd1a0fd531b7c003342703ebbb4edd..63ba18fe89bc0111326e8ee0c64fd0742e677026 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fblocks -fsyntax-only %s -verify
+// RUN: %clang_cc1 -fblocks -fsyntax-only %s -verify -Wmethod-signatures
 
 // Tests Objective-C 'kindof' types.
 
@@ -374,6 +374,27 @@ void testNullability() {
   processCopyable(0); // expected-warning{{null passed to a callee that requires a non-null argument}}
 }
 
+// Make sure that we don't emit a warning about conflicting parameter types
+// between __kindof id and id.
+@interface A2 : NSObject
+- (void)test:(__kindof id)T;
+@end
+@implementation A2
+- (void)test:(id)T {
+}
+@end
+
+@interface NSGeneric<ObjectType> : NSObject
+- (void)test:(__kindof ObjectType)T;
+- (void)mapUsingBlock:(id (^)(__kindof ObjectType))block;
+@end
+@implementation NSGeneric
+- (void)test:(id)T {
+}
+- (void)mapUsingBlock:(id (^)(id))block {
+}
+@end
+
 // Check that clang doesn't crash when a type parameter is illegal.
 @interface Array1<T> : NSObject
 @end