summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYaxun Liu <Yaxun.Liu@amd.com>2016-09-19 14:54:41 +0000
committerYaxun Liu <Yaxun.Liu@amd.com>2016-09-19 14:54:41 +0000
commit6aaa01b58e0fe1d78242426273b3840e71bce569 (patch)
treedb8d132866e8e708fdc73270cb3b95ba0cf84eec
parent2828b9be1ecf34cbe9ad4df68560131f619edaed (diff)
downloadbcm5719-llvm-6aaa01b58e0fe1d78242426273b3840e71bce569.tar.gz
bcm5719-llvm-6aaa01b58e0fe1d78242426273b3840e71bce569.zip
[OpenCL] Diagnose assignment to dereference of half type pointer
Differential Revision: https://reviews.llvm.org/D24626 llvm-svn: 281904
-rw-r--r--clang/include/clang/Basic/DiagnosticSemaKinds.td3
-rw-r--r--clang/lib/Sema/SemaExpr.cpp10
-rw-r--r--clang/test/SemaOpenCL/half.cl8
3 files changed, 18 insertions, 3 deletions
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index af333d38601..6090fc70536 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -659,7 +659,8 @@ def err_object_cannot_be_passed_returned_by_value : Error<
def err_parameters_retval_cannot_have_fp16_type : Error<
"%select{parameters|function return value}0 cannot have __fp16 type; did you forget * ?">;
def err_opencl_half_load_store : Error<
- "%select{loading directly from|assigning directly to}0 pointer to type %1 is not allowed">;
+ "%select{loading directly from|assigning directly to}0 pointer to type %1 requires "
+ "cl_khr_fp16. Use vector data %select{load|store}0 builtin functions instead">;
def err_opencl_cast_to_half : Error<"casting to type %0 is not allowed">;
def err_opencl_half_declaration : Error<
"declaring variable of type %0 is not allowed">;
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 72a35866ad6..f34263dba51 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -10100,6 +10100,16 @@ QualType Sema::CheckAssignmentOperands(Expr *LHSExpr, ExprResult &RHS,
QualType LHSType = LHSExpr->getType();
QualType RHSType = CompoundType.isNull() ? RHS.get()->getType() :
CompoundType;
+ // OpenCL v1.2 s6.1.1.1 p2:
+ // The half data type can only be used to declare a pointer to a buffer that
+ // contains half values
+ if (getLangOpts().OpenCL && !getOpenCLOptions().cl_khr_fp16 &&
+ LHSType->isHalfType()) {
+ Diag(Loc, diag::err_opencl_half_load_store) << 1
+ << LHSType.getUnqualifiedType();
+ return QualType();
+ }
+
AssignConvertType ConvTy;
if (CompoundType.isNull()) {
Expr *RHSCheck = RHS.get();
diff --git a/clang/test/SemaOpenCL/half.cl b/clang/test/SemaOpenCL/half.cl
index dd7bb9ab8c5..fe88cf1b954 100644
--- a/clang/test/SemaOpenCL/half.cl
+++ b/clang/test/SemaOpenCL/half.cl
@@ -8,8 +8,10 @@ half half_disabled(half *p, // expected-error{{declaring function return value o
{
half a[2]; // expected-error{{declaring variable of type 'half [2]' is not allowed}}
half b; // expected-error{{declaring variable of type 'half' is not allowed}}
- *p; // expected-error{{loading directly from pointer to type 'half' is not allowed}}
- p[1]; // expected-error{{loading directly from pointer to type 'half' is not allowed}}
+ *p; // expected-error{{loading directly from pointer to type 'half' requires cl_khr_fp16. Use vector data load builtin functions instead}}
+ *p = 0; // expected-error{{assigning directly to pointer to type 'half' requires cl_khr_fp16. Use vector data store builtin functions instead}}
+ p[1]; // expected-error{{loading directly from pointer to type 'half' requires cl_khr_fp16. Use vector data load builtin functions instead}}
+ p[1] = 0; // expected-error{{assigning directly to pointer to type 'half' requires cl_khr_fp16. Use vector data store builtin functions instead}}
float c = 1.0f;
b = (half) c; // expected-error{{casting to type 'half' is not allowed}}
@@ -31,7 +33,9 @@ half half_enabled(half *p, half h)
half a[2];
half b;
*p;
+ *p = 0;
p[1];
+ p[1] = 0;
float c = 1.0f;
b = (half) c;
OpenPOWER on IntegriCloud