[PATCH] D79511: [ObjC] Add compatibility mode for type checking of qualified id block parameters.

Volodymyr Sapsai via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue May 12 15:38:36 PDT 2020


vsapsai updated this revision to Diff 263544.
vsapsai added a comment.

Make compatibility mode accept correct types per James' Y Knight helpful suggestion.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79511/new/

https://reviews.llvm.org/D79511

Files:
  clang/lib/AST/ASTContext.cpp
  clang/test/SemaObjC/block-type-safety.m


Index: clang/test/SemaObjC/block-type-safety.m
===================================================================
--- clang/test/SemaObjC/block-type-safety.m
+++ clang/test/SemaObjC/block-type-safety.m
@@ -167,7 +167,7 @@
     void (^blockWithParam)(NSAllArray *);
     void (^genericBlockWithParam)(id<Foo>);
     genericBlockWithParam = blockWithParam;
-    blockWithParam = genericBlockWithParam; // expected-error {{incompatible block pointer types assigning to 'void (^)(NSAllArray *)' from 'void (^)(id<Foo>)'}}
+    blockWithParam = genericBlockWithParam;
     return 0;
 }
 #endif
Index: clang/lib/AST/ASTContext.cpp
===================================================================
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -8501,7 +8501,11 @@
 
   if (LHSOPT->isObjCQualifiedIdType() || RHSOPT->isObjCQualifiedIdType()) {
     if (getLangOpts().CompatibilityQualifiedIdBlockParamTypeChecking)
-      return finish(ObjCQualifiedIdTypesAreCompatible(LHSOPT, RHSOPT, false));
+      // Use for block parameters previous type checking for compatibility.
+      return finish(ObjCQualifiedIdTypesAreCompatible(LHSOPT, RHSOPT, false) ||
+                    // Or corrected type checking as in non-compat mode.
+                    (!BlockReturnType &&
+                     ObjCQualifiedIdTypesAreCompatible(RHSOPT, LHSOPT, false)));
     else
       return finish(ObjCQualifiedIdTypesAreCompatible(
           (BlockReturnType ? LHSOPT : RHSOPT),


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79511.263544.patch
Type: text/x-patch
Size: 1483 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200512/7047183b/attachment.bin>


More information about the cfe-commits mailing list