@@ -6458,6 +6458,18 @@ OpenCLCheckVectorConditional(Sema &S, ExprResult &Cond,
6458
6458
return OpenCLConvertScalarsToVectors(S, LHS, RHS, CondTy, QuestionLoc);
6459
6459
}
6460
6460
6461
+ /// \brief Return true if the Expr is block type
6462
+ static bool checkBlockType(Sema &S, const Expr *E) {
6463
+ if (const CallExpr *CE = dyn_cast<CallExpr>(E)) {
6464
+ QualType Ty = CE->getCallee()->getType();
6465
+ if (Ty->isBlockPointerType()) {
6466
+ S.Diag(E->getExprLoc(), diag::err_opencl_ternary_with_block);
6467
+ return true;
6468
+ }
6469
+ }
6470
+ return false;
6471
+ }
6472
+
6461
6473
/// Note that LHS is not null here, even if this is the gnu "x ?: y" extension.
6462
6474
/// In that case, LHS = cond.
6463
6475
/// C99 6.5.15
@@ -6507,6 +6519,13 @@ QualType Sema::CheckConditionalOperands(ExprResult &Cond, ExprResult &LHS,
6507
6519
QualType LHSTy = LHS.get()->getType();
6508
6520
QualType RHSTy = RHS.get()->getType();
6509
6521
6522
+ // OpenCL v2.0 s6.12.5 - Blocks cannot be used as expressions of the ternary
6523
+ // selection operator (?:).
6524
+ if (getLangOpts().OpenCL &&
6525
+ (checkBlockType(*this, LHS.get()) | checkBlockType(*this, RHS.get()))) {
6526
+ return QualType();
6527
+ }
6528
+
6510
6529
// If both operands have arithmetic type, do the usual arithmetic conversions
6511
6530
// to find a common type: C99 6.5.15p3,5.
6512
6531
if (LHSTy->isArithmeticType() && RHSTy->isArithmeticType()) {
@@ -10334,6 +10353,14 @@ QualType Sema::CheckAddressOfOperand(ExprResult &OrigOp, SourceLocation OpLoc) {
10334
10353
// If the operand has type "type", the result has type "pointer to type".
10335
10354
if (op->getType()->isObjCObjectType())
10336
10355
return Context.getObjCObjectPointerType(op->getType());
10356
+
10357
+ // OpenCL v2.0 s6.12.5 - The unary operators & cannot be used with a block.
10358
+ if (getLangOpts().OpenCL && OrigOp.get()->getType()->isBlockPointerType()) {
10359
+ Diag(OpLoc, diag::err_typecheck_unary_expr) << OrigOp.get()->getType()
10360
+ << op->getSourceRange();
10361
+ return QualType();
10362
+ }
10363
+
10337
10364
return Context.getPointerType(op->getType());
10338
10365
}
10339
10366
@@ -10375,7 +10402,15 @@ static QualType CheckIndirectionOperand(Sema &S, Expr *Op, ExprValueKind &VK,
10375
10402
}
10376
10403
10377
10404
if (const PointerType *PT = OpTy->getAs<PointerType>())
10405
+ {
10378
10406
Result = PT->getPointeeType();
10407
+ // OpenCL v2.0 s6.12.5 - The unary operators * cannot be used with a block.
10408
+ if (S.getLangOpts().OpenCLVersion >= 200 && Result->isBlockPointerType()) {
10409
+ S.Diag(OpLoc, diag::err_opencl_dereferencing) << OpTy
10410
+ << Op->getSourceRange();
10411
+ return QualType();
10412
+ }
10413
+ }
10379
10414
else if (const ObjCObjectPointerType *OPT =
10380
10415
OpTy->getAs<ObjCObjectPointerType>())
10381
10416
Result = OPT->getPointeeType();
0 commit comments