r227565 - Fix OpenCL 1.2 double as an optional core feature behaviour

Fraser Cormack fraser at codeplay.com
Fri Jan 30 02:51:47 PST 2015


Author: fcormack
Date: Fri Jan 30 04:51:46 2015
New Revision: 227565

URL: http://llvm.org/viewvc/llvm-project?rev=227565&view=rev
Log:
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

Added:
    cfe/trunk/test/SemaOpenCL/extension-fp64-cl1.1.cl
    cfe/trunk/test/SemaOpenCL/optional-core-fp64-cl1.2.cl
    cfe/trunk/test/SemaOpenCL/optional-core-fp64-cl2.0.cl
Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/lib/Sema/SemaType.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=227565&r1=227564&r2=227565&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Jan 30 04:51:46 2015
@@ -3266,7 +3266,9 @@ ExprResult Sema::ActOnNumericConstant(co
     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();
       }

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=227565&r1=227564&r2=227565&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Fri Jan 30 04:51:46 2015
@@ -868,7 +868,9 @@ static QualType ConvertDeclSpecToType(Ty
     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);
     }

Added: cfe/trunk/test/SemaOpenCL/extension-fp64-cl1.1.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/extension-fp64-cl1.1.cl?rev=227565&view=auto
==============================================================================
--- cfe/trunk/test/SemaOpenCL/extension-fp64-cl1.1.cl (added)
+++ cfe/trunk/test/SemaOpenCL/extension-fp64-cl1.1.cl Fri Jan 30 04:51:46 2015
@@ -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}}
+}

Added: cfe/trunk/test/SemaOpenCL/optional-core-fp64-cl1.2.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/optional-core-fp64-cl1.2.cl?rev=227565&view=auto
==============================================================================
--- cfe/trunk/test/SemaOpenCL/optional-core-fp64-cl1.2.cl (added)
+++ cfe/trunk/test/SemaOpenCL/optional-core-fp64-cl1.2.cl Fri Jan 30 04:51:46 2015
@@ -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;
+}

Added: cfe/trunk/test/SemaOpenCL/optional-core-fp64-cl2.0.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/optional-core-fp64-cl2.0.cl?rev=227565&view=auto
==============================================================================
--- cfe/trunk/test/SemaOpenCL/optional-core-fp64-cl2.0.cl (added)
+++ cfe/trunk/test/SemaOpenCL/optional-core-fp64-cl2.0.cl Fri Jan 30 04:51:46 2015
@@ -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;
+}






More information about the cfe-commits mailing list