Author: vsapsai Date: Tue Aug 27 17:25:06 2019 New Revision: 370130 URL: http://llvm.org/viewvc/llvm-project?rev=370130&view=rev Log: [ObjC] Fix type checking for qualified id block parameters.
When checking if block types are compatible, we are checking for compatibility their return types and parameters' types. As these types have different variance, we need to check them in different order. rdar://problem/52788423 Reviewers: erik.pilkington, arphaman Reviewed By: arphaman Subscribers: jkorous, dexonsmith, ributzka, cfe-commits Differential Revision: https://reviews.llvm.org/D66831 Modified: cfe/trunk/lib/AST/ASTContext.cpp cfe/trunk/test/SemaObjC/block-type-safety.m Modified: cfe/trunk/lib/AST/ASTContext.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=370130&r1=370129&r2=370130&view=diff ============================================================================== --- cfe/trunk/lib/AST/ASTContext.cpp (original) +++ cfe/trunk/lib/AST/ASTContext.cpp Tue Aug 27 17:25:06 2019 @@ -8191,9 +8191,9 @@ bool ASTContext::canAssignObjCInterfaces } if (LHSOPT->isObjCQualifiedIdType() || RHSOPT->isObjCQualifiedIdType()) - return finish(ObjCQualifiedIdTypesAreCompatible(QualType(LHSOPT,0), - QualType(RHSOPT,0), - false)); + return finish(ObjCQualifiedIdTypesAreCompatible( + QualType(BlockReturnType ? LHSOPT : RHSOPT, 0), + QualType(BlockReturnType ? RHSOPT : LHSOPT, 0), false)); const ObjCInterfaceType* LHS = LHSOPT->getInterfaceType(); const ObjCInterfaceType* RHS = RHSOPT->getInterfaceType(); Modified: cfe/trunk/test/SemaObjC/block-type-safety.m URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/block-type-safety.m?rev=370130&r1=370129&r2=370130&view=diff ============================================================================== --- cfe/trunk/test/SemaObjC/block-type-safety.m (original) +++ cfe/trunk/test/SemaObjC/block-type-safety.m Tue Aug 27 17:25:06 2019 @@ -133,9 +133,20 @@ int test4 () { @end int test5() { + // Returned value is used outside of a block, so error on changing + // a return type to a more general than expected. NSAllArray *(^block)(id); id <Foo> (^genericBlock)(id); genericBlock = block; + block = genericBlock; // expected-error {{incompatible block pointer types assigning to 'NSAllArray *(^)(id)' from 'id<Foo> (^)(id)'}} + + // A parameter is used inside a block, so error on changing a parameter type + // to a more specific than an argument type it will be called with. + // rdar://problem/52788423 + void (^blockWithParam)(NSAllArray *); + void (^genericBlockWithParam)(id<Foo>); + genericBlockWithParam = blockWithParam; // expected-error {{incompatible block pointer types assigning to 'void (^)(id<Foo>)' from 'void (^)(NSAllArray *)'}} + blockWithParam = genericBlockWithParam; return 0; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits