From 4d8500396454334975ab8bb6766d6521c5140b13 Mon Sep 17 00:00:00 2001 From: Anastasia Stulova Date: Mon, 11 Jul 2016 13:46:02 +0000 Subject: [OpenCL] Improved diagnostics of OpenCL types. - Changes diagnostics for Blocks to be implicitly const qualified OpenCL v2.0 s6.12.5. - Added and unified diagnostics of some OpenCL special types: blocks, images, samplers, pipes. These types are intended for use with the OpenCL builtin functions only and, therefore, most regular uses are not allowed including assignments, arithmetic operations, pointer dereferencing, etc. Review: http://reviews.llvm.org/D21989 llvm-svn: 275061 --- clang/lib/Sema/SemaExpr.cpp | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) (limited to 'clang/lib/Sema/SemaExpr.cpp') diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 3619834fce6..0c8a9136948 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -10534,13 +10534,6 @@ QualType Sema::CheckAddressOfOperand(ExprResult &OrigOp, SourceLocation OpLoc) { if (op->getType()->isObjCObjectType()) return Context.getObjCObjectPointerType(op->getType()); - // OpenCL v2.0 s6.12.5 - The unary operators & cannot be used with a block. - if (getLangOpts().OpenCL && OrigOp.get()->getType()->isBlockPointerType()) { - Diag(OpLoc, diag::err_typecheck_unary_expr) << OrigOp.get()->getType() - << op->getSourceRange(); - return QualType(); - } - return Context.getPointerType(op->getType()); } @@ -10584,12 +10577,6 @@ static QualType CheckIndirectionOperand(Sema &S, Expr *Op, ExprValueKind &VK, if (const PointerType *PT = OpTy->getAs()) { Result = PT->getPointeeType(); - // OpenCL v2.0 s6.12.5 - The unary operators * cannot be used with a block. - if (S.getLangOpts().OpenCLVersion >= 200 && Result->isBlockPointerType()) { - S.Diag(OpLoc, diag::err_opencl_dereferencing) << OpTy - << Op->getSourceRange(); - return QualType(); - } } else if (const ObjCObjectPointerType *OPT = OpTy->getAs()) @@ -10828,10 +10815,11 @@ ExprResult Sema::CreateBuiltinBinOp(SourceLocation OpLoc, } if (getLangOpts().OpenCL) { + QualType LHSTy = LHSExpr->getType(); + QualType RHSTy = RHSExpr->getType(); // OpenCLC v2.0 s6.13.11.1 allows atomic variables to be initialized by // the ATOMIC_VAR_INIT macro. - if (LHSExpr->getType()->isAtomicType() || - RHSExpr->getType()->isAtomicType()) { + if (LHSTy->isAtomicType() || RHSTy->isAtomicType()) { SourceRange SR(LHSExpr->getLocStart(), RHSExpr->getLocEnd()); if (BO_Assign == Opc) Diag(OpLoc, diag::err_atomic_init_constant) << SR; @@ -10839,6 +10827,16 @@ ExprResult Sema::CreateBuiltinBinOp(SourceLocation OpLoc, ResultTy = InvalidOperands(OpLoc, LHS, RHS); return ExprError(); } + + // OpenCL special types - image, sampler, pipe, and blocks are to be used + // only with a builtin functions and therefore should be disallowed here. + if (LHSTy->isImageType() || RHSTy->isImageType() || + LHSTy->isSamplerT() || RHSTy->isSamplerT() || + LHSTy->isPipeType() || RHSTy->isPipeType() || + LHSTy->isBlockPointerType() || RHSTy->isBlockPointerType()) { + ResultTy = InvalidOperands(OpLoc, LHS, RHS); + return ExprError(); + } } switch (Opc) { @@ -11309,8 +11307,13 @@ ExprResult Sema::CreateBuiltinUnaryOp(SourceLocation OpLoc, ExprObjectKind OK = OK_Ordinary; QualType resultType; if (getLangOpts().OpenCL) { + QualType Ty = InputExpr->getType(); // The only legal unary operation for atomics is '&'. - if (Opc != UO_AddrOf && InputExpr->getType()->isAtomicType()) { + if ((Opc != UO_AddrOf && Ty->isAtomicType()) || + // OpenCL special types - image, sampler, pipe, and blocks are to be used + // only with a builtin functions and therefore should be disallowed here. + (Ty->isImageType() || Ty->isSamplerT() || Ty->isPipeType() + || Ty->isBlockPointerType())) { return ExprError(Diag(OpLoc, diag::err_typecheck_unary_expr) << InputExpr->getType() << Input.get()->getSourceRange()); -- cgit v1.2.3