Fix <rdar://problem/6252216> compare block to NULL.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@56764 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index dfa53ac..07ce6b0 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -2034,6 +2034,17 @@
ImpCastExprToType(rex, lType); // promote the pointer to pointer
return Context.IntTy;
}
+ // Allow block pointers to be compared with null pointer constants.
+ if ((lType->isBlockPointerType() && rType->isPointerType()) ||
+ (lType->isPointerType() && rType->isBlockPointerType())) {
+ if (!LHSIsNull && !RHSIsNull) {
+ Diag(loc, diag::err_typecheck_comparison_of_distinct_blocks,
+ lType.getAsString(), rType.getAsString(),
+ lex->getSourceRange(), rex->getSourceRange());
+ }
+ ImpCastExprToType(rex, lType); // promote the pointer to pointer
+ return Context.IntTy;
+ }
if ((lType->isObjCQualifiedIdType() || rType->isObjCQualifiedIdType())) {
if (ObjCQualifiedIdTypesAreCompatible(lType, rType, true)) {