More semantic analysis for blocks...
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@56064 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp
index 8c59039..00b469b 100644
--- a/lib/Sema/SemaChecking.cpp
+++ b/lib/Sema/SemaChecking.cpp
@@ -717,7 +717,7 @@
DR->getDecl()->getIdentifier()->getName(),
RetValExp->getSourceRange());
- if (BlockExpr *C = dyn_cast_or_null<BlockExpr>(EvalAddr(RetValExp)))
+ if (BlockExpr *C = dyn_cast_or_null<BlockExpr>(RetValExp))
Diag(C->getLocStart(), diag::err_ret_local_block,
C->getSourceRange());
}
@@ -797,7 +797,7 @@
assert (Base->getType()->isPointerType());
return EvalAddr(Base);
}
-
+
// For conditional operators we need to see if either the LHS or RHS are
// valid DeclRefExpr*s. If one of them is valid, we return it.
case Stmt::ConditionalOperatorClass: {
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 80b33f2..aa8f194 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -1296,11 +1296,13 @@
}
// C99 6.5.15p6 - "if one operand is a null pointer constant, the result has
// the type of the other operand."
- if (lexT->isPointerType() && rex->isNullPointerConstant(Context)) {
+ if ((lexT->isPointerType() || lexT->isBlockPointerType()) &&
+ rex->isNullPointerConstant(Context)) {
ImpCastExprToType(rex, lexT); // promote the null to a pointer.
return lexT;
}
- if (rexT->isPointerType() && lex->isNullPointerConstant(Context)) {
+ if ((rexT->isPointerType() || rexT->isBlockPointerType()) &&
+ lex->isNullPointerConstant(Context)) {
ImpCastExprToType(lex, rexT); // promote the null to a pointer.
return rexT;
}
@@ -1381,6 +1383,11 @@
return compositeType;
}
}
+ // Selection between block pointer types is ok as long as they are the same.
+ if (lexT->isBlockPointerType() && rexT->isBlockPointerType() &&
+ Context.getCanonicalType(lexT) == Context.getCanonicalType(rexT))
+ return lexT;
+
// Otherwise, the operands are not compatible.
Diag(questionLoc, diag::err_typecheck_cond_incompatible_operands,
lexT.getAsString(), rexT.getAsString(),