From: Manman Ren Date: Fri, 20 May 2016 17:29:43 +0000 (+0000) Subject: ObjectiveC: canonicalize "kindof id" to "id". X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4cf7242721a0349b4f025f5ca3e60d9dc4c89494;p=clang ObjectiveC: canonicalize "kindof id" to "id". 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 --- diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index 57295fde0b..d99d9521f4 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -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) { diff --git a/test/SemaObjC/kindof.m b/test/SemaObjC/kindof.m index aa5a0db331..63ba18fe89 100644 --- a/test/SemaObjC/kindof.m +++ b/test/SemaObjC/kindof.m @@ -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 : 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 : NSObject @end