diff options
author | Anastasia Stulova <anastasia.stulova@arm.com> | 2015-09-30 13:18:52 +0000 |
---|---|---|
committer | Anastasia Stulova <anastasia.stulova@arm.com> | 2015-09-30 13:18:52 +0000 |
commit | de0e424e8ae9f5463cfd284ca4694a2092f8b40f (patch) | |
tree | 759173b9532ce488fd8c1046cff22ed3da7aec6b /clang/lib/Sema/SemaExpr.cpp | |
parent | 08023c696da5f6f380cbbc3d1db160dfd5975e54 (diff) | |
download | bcm5719-llvm-de0e424e8ae9f5463cfd284ca4694a2092f8b40f.tar.gz bcm5719-llvm-de0e424e8ae9f5463cfd284ca4694a2092f8b40f.zip |
[OpenCL 2.0] This change adds extra diagnostics to atomic types
Applied restrictions from OpenCL v2.0 s6.13.11.8
that mainly disallow operations on atomic types (except for taking their address - &).
The patch is taken from SPIR2.0 provisional branch, contributed by Guy Benyei!
llvm-svn: 248896
Diffstat (limited to 'clang/lib/Sema/SemaExpr.cpp')
-rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 90f3c7c16a5..c2b3f29332b 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -10276,6 +10276,20 @@ ExprResult Sema::CreateBuiltinBinOp(SourceLocation OpLoc, return ExprError(); } + if (getLangOpts().OpenCL) { + // 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()) { + SourceRange SR(LHSExpr->getLocStart(), RHSExpr->getLocEnd()); + if (BO_Assign == Opc) + Diag(OpLoc, diag::err_atomic_init_constant) << SR; + else + ResultTy = InvalidOperands(OpLoc, LHS, RHS); + return ExprError(); + } + } + switch (Opc) { case BO_Assign: ResultTy = CheckAssignmentOperands(LHS.get(), RHS, OpLoc, QualType()); @@ -10748,6 +10762,14 @@ ExprResult Sema::CreateBuiltinUnaryOp(SourceLocation OpLoc, ExprValueKind VK = VK_RValue; ExprObjectKind OK = OK_Ordinary; QualType resultType; + if (getLangOpts().OpenCL) { + // The only legal unary operation for atomics is '&'. + if (Opc != UO_AddrOf && InputExpr->getType()->isAtomicType()) { + return ExprError(Diag(OpLoc, diag::err_typecheck_unary_expr) + << InputExpr->getType() + << Input.get()->getSourceRange()); + } + } switch (Opc) { case UO_PreInc: case UO_PreDec: |