]> granicus.if.org Git - clang/commitdiff
Fix <rdar://problem/6252216> compare block to NULL.
authorSteve Naroff <snaroff@apple.com>
Sun, 28 Sep 2008 01:11:11 +0000 (01:11 +0000)
committerSteve Naroff <snaroff@apple.com>
Sun, 28 Sep 2008 01:11:11 +0000 (01:11 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@56764 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/Sema/block-return.c

index dfa53ac4398651113eb97c0eccc1ae1be8a147d4..07ce6b0b2f0cfa51ee4277be36c541bd0831036e 100644 (file)
@@ -2034,6 +2034,17 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation loc,
     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)) {
index ba3a0d269faf49d07015a85c8f09b6ea1a627bbb..b88fb9b5be06d91a0deb34c485ed29b112120e0a 100644 (file)
@@ -72,7 +72,10 @@ int foo3() {
 }
 
 static int funk(char *s) {
-  return 1;
+  if (^{} == ((void*)0))
+    return 1;
+  else 
+    return 0;
 }
 void foo4() {
   int (^xx)(const char *s) = ^(char *s) { return 1; }; // expected-warning {{incompatible block pointer types initializing 'int (^)(char *)', expected 'int (^)(char const *)'}}