r270241 - ObjectiveC: canonicalize "kindof id" to "id".

Manman Ren via cfe-commits cfe-commits at lists.llvm.org
Fri May 20 10:29:45 PDT 2016


Author: mren
Date: Fri May 20 12:29:43 2016
New Revision: 270241

URL: http://llvm.org/viewvc/llvm-project?rev=270241&view=rev
Log:
ObjectiveC: canonicalize "kindof id" to "id".

There is no need to apply kindof on an unqualified id type.

rdar://24753825

Modified:
    cfe/trunk/lib/Sema/SemaType.cpp
    cfe/trunk/test/SemaObjC/kindof.m

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=270241&r1=270240&r2=270241&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Fri May 20 12:29:43 2016
@@ -5900,10 +5900,11 @@ bool Sema::checkObjCKindOfType(QualType
 
   // 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) {

Modified: cfe/trunk/test/SemaObjC/kindof.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/kindof.m?rev=270241&r1=270240&r2=270241&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/kindof.m (original)
+++ cfe/trunk/test/SemaObjC/kindof.m Fri May 20 12:29:43 2016
@@ -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.
+ at interface A2 : NSObject
+- (void)test:(__kindof id)T;
+ at end
+ at implementation A2
+- (void)test:(id)T {
+}
+ at end
+
+ at interface NSGeneric<ObjectType> : NSObject
+- (void)test:(__kindof ObjectType)T;
+- (void)mapUsingBlock:(id (^)(__kindof ObjectType))block;
+ at end
+ at implementation NSGeneric
+- (void)test:(id)T {
+}
+- (void)mapUsingBlock:(id (^)(id))block {
+}
+ at end
+
 // Check that clang doesn't crash when a type parameter is illegal.
 @interface Array1<T> : NSObject
 @end




More information about the cfe-commits mailing list