From e18f94c20debd029b283e380665de3fe9fcd7b7c Mon Sep 17 00:00:00 2001 From: Steve Naroff Date: Sun, 28 Sep 2008 01:11:11 +0000 Subject: [PATCH] Fix compare block to NULL. llvm-svn: 56764 --- clang/lib/Sema/SemaExpr.cpp | 11 +++++++++++ clang/test/Sema/block-return.c | 5 ++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index dfa53ac43986..07ce6b0b2f0c 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -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)) { diff --git a/clang/test/Sema/block-return.c b/clang/test/Sema/block-return.c index ba3a0d269faf..b88fb9b5be06 100644 --- a/clang/test/Sema/block-return.c +++ b/clang/test/Sema/block-return.c @@ -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 *)'}}