summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFraser Cormack <fraser@codeplay.com>2015-01-30 10:51:46 +0000
committerFraser Cormack <fraser@codeplay.com>2015-01-30 10:51:46 +0000
commitcc6e894587ec5c4b995dc88d672556369bf833c7 (patch)
tree1b6856c8ef6e90af87230624adbc7c3a21a971ce
parent9469a592ba5f7fbe65c3cb62bdce6401c278ee75 (diff)
downloadbcm5719-llvm-cc6e894587ec5c4b995dc88d672556369bf833c7.tar.gz
bcm5719-llvm-cc6e894587ec5c4b995dc88d672556369bf833c7.zip
Fix OpenCL 1.2 double as an optional core feature behaviour
In OpenCL 1.2, using double no longer requires using the pragma cl_khr_fp64, instead a kernel is allowed to use double, but must first have queried clGetDeviceInfo's CL_DEVICE_DOUBLE_FP_CONFIG. Page 197, section 6.1.1 of the OpenCL 1.2 specification has a footnote 23 describing this behaviour. I've also added test cases such that the pragma must be used if targeting OpenCL 1.0 or 1.1, but is ignored in 1.2 and 2.0. Patch by Neil Henning! Reviewers: Pekka Jääskeläinen Differential Revision: http://reviews.llvm.org/D7245 llvm-svn: 227565
-rw-r--r--clang/lib/Sema/SemaExpr.cpp4
-rw-r--r--clang/lib/Sema/SemaType.cpp4
-rw-r--r--clang/test/SemaOpenCL/extension-fp64-cl1.1.cl19
-rw-r--r--clang/test/SemaOpenCL/optional-core-fp64-cl1.2.cl20
-rw-r--r--clang/test/SemaOpenCL/optional-core-fp64-cl2.0.cl20
5 files changed, 65 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 08b58850232..fb340e701b7 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -3266,7 +3266,9 @@ ExprResult Sema::ActOnNumericConstant(const Token &Tok, Scope *UDLScope) {
if (Ty == Context.DoubleTy) {
if (getLangOpts().SinglePrecisionConstants) {
Res = ImpCastExprToType(Res, Context.FloatTy, CK_FloatingCast).get();
- } else if (getLangOpts().OpenCL && !getOpenCLOptions().cl_khr_fp64) {
+ } else if (getLangOpts().OpenCL &&
+ !((getLangOpts().OpenCLVersion >= 120) ||
+ getOpenCLOptions().cl_khr_fp64)) {
Diag(Tok.getLocation(), diag::warn_double_const_requires_fp64);
Res = ImpCastExprToType(Res, Context.FloatTy, CK_FloatingCast).get();
}
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 73ecc5aaee2..8e86c73ccbe 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -868,7 +868,9 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) {
else
Result = Context.DoubleTy;
- if (S.getLangOpts().OpenCL && !S.getOpenCLOptions().cl_khr_fp64) {
+ if (S.getLangOpts().OpenCL &&
+ !((S.getLangOpts().OpenCLVersion >= 120) ||
+ S.getOpenCLOptions().cl_khr_fp64)) {
S.Diag(DS.getTypeSpecTypeLoc(), diag::err_double_requires_fp64);
declarator.setInvalidType(true);
}
diff --git a/clang/test/SemaOpenCL/extension-fp64-cl1.1.cl b/clang/test/SemaOpenCL/extension-fp64-cl1.1.cl
new file mode 100644
index 00000000000..7e852ae70eb
--- /dev/null
+++ b/clang/test/SemaOpenCL/extension-fp64-cl1.1.cl
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.1
+
+void f1(double da) { // expected-error {{type 'double' requires cl_khr_fp64 extension}}
+ double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}}
+ (void) 1.0; // expected-warning {{double precision constant requires cl_khr_fp64}}
+}
+
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+
+void f2(void) {
+ double d;
+ (void) 1.0;
+}
+
+#pragma OPENCL EXTENSION cl_khr_fp64 : disable
+
+void f3(void) {
+ double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}}
+}
diff --git a/clang/test/SemaOpenCL/optional-core-fp64-cl1.2.cl b/clang/test/SemaOpenCL/optional-core-fp64-cl1.2.cl
new file mode 100644
index 00000000000..e0f7f1db4ff
--- /dev/null
+++ b/clang/test/SemaOpenCL/optional-core-fp64-cl1.2.cl
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.2
+// expected-no-diagnostics
+
+void f1(double da) {
+ double d;
+ (void) 1.0;
+}
+
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+
+void f2(void) {
+ double d;
+ (void) 1.0;
+}
+
+#pragma OPENCL EXTENSION cl_khr_fp64 : disable
+
+void f3(void) {
+ double d;
+}
diff --git a/clang/test/SemaOpenCL/optional-core-fp64-cl2.0.cl b/clang/test/SemaOpenCL/optional-core-fp64-cl2.0.cl
new file mode 100644
index 00000000000..832529d4adf
--- /dev/null
+++ b/clang/test/SemaOpenCL/optional-core-fp64-cl2.0.cl
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0
+// expected-no-diagnostics
+
+void f1(double da) {
+ double d;
+ (void) 1.0;
+}
+
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+
+void f2(void) {
+ double d;
+ (void) 1.0;
+}
+
+#pragma OPENCL EXTENSION cl_khr_fp64 : disable
+
+void f3(void) {
+ double d;
+}
OpenPOWER on IntegriCloud