diff options
| author | Anastasia Stulova <anastasia.stulova@arm.com> | 2016-07-11 13:46:02 +0000 |
|---|---|---|
| committer | Anastasia Stulova <anastasia.stulova@arm.com> | 2016-07-11 13:46:02 +0000 |
| commit | 4d8500396454334975ab8bb6766d6521c5140b13 (patch) | |
| tree | 7a98430197c60e9b0a425afd57ab5bac30c5225d /clang/lib/Sema/SemaExpr.cpp | |
| parent | c73301bbe3dbcd6253b22a09e6acdb30eae31581 (diff) | |
| download | bcm5719-llvm-4d8500396454334975ab8bb6766d6521c5140b13.tar.gz bcm5719-llvm-4d8500396454334975ab8bb6766d6521c5140b13.zip | |
[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
Diffstat (limited to 'clang/lib/Sema/SemaExpr.cpp')
| -rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 35 |
1 files changed, 19 insertions, 16 deletions
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<PointerType>()) { 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<ObjCObjectPointerType>()) @@ -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()); |

