[PATCH] D100980: [OpenCL] Allow use of double type without extension pragma

Anastasia Stulova via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 21 10:31:55 PDT 2021


Anastasia created this revision.
Anastasia added reviewers: svenvh, azabaznov.
Herald added subscribers: ebevhan, yaxunl.
Anastasia requested review of this revision.

OpenCL specification doesn't require the pragma for the uses of `double` type when it is supported by the targets. The wording in the spec is as follows:

> 80. Only if double precision is supported. In OpenCL C 3.0 this will be indicated by the presence of the __opencl_c_fp64 feature macro.

in contrast to `half` type

> 79. Only if the cl_khr_fp16 extension is supported and has been enabled.

This is primarily due to the fact that `double` is a type from C99 spec where it can be used without any pragmas. This is to align the core OpenCL behavior with C.


https://reviews.llvm.org/D100980

Files:
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/SemaOpenCL/extensions.cl


Index: clang/test/SemaOpenCL/extensions.cl
===================================================================
--- clang/test/SemaOpenCL/extensions.cl
+++ clang/test/SemaOpenCL/extensions.cl
@@ -43,9 +43,17 @@
 #endif
 
 #if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ < 120)
-void f1(double da) { // expected-error {{type 'double' requires cl_khr_fp64 support}}
-  double d; // expected-error {{type 'double' requires cl_khr_fp64 support}}
-  (void) 1.0; // expected-warning {{double precision constant requires cl_khr_fp64}}
+void f1(double da) {
+#ifdef NOFP64
+// expected-error at -2 {{type 'double' requires cl_khr_fp64 support}}
+#endif
+  double d;
+#ifdef NOFP64
+// expected-error at -2 {{type 'double' requires cl_khr_fp64 support}}
+#endif
+  // FIXME: this diagnostic depends on the extension pragma in the earlier versions.
+  // There is no indication that this behavior is expected.
+  (void)1.0; // expected-warning {{double precision constant requires cl_khr_fp64}}
 }
 #endif
 
@@ -79,13 +87,11 @@
   double4 d4 = {0.0f, 2.0f, 3.0f, 1.0f};
 #ifdef NOFP64
 // expected-error at -3 {{use of type 'double' requires cl_khr_fp64 support}}
-// expected-error at -3 {{use of type 'double4' (vector of 4 'double' values) requires cl_khr_fp64 support}}
 #endif
 
-  (void) 1.0;
-
+  (void)1.0;
 #ifdef NOFP64
-// expected-warning at -3{{double precision constant requires cl_khr_fp64, casting to single precision}}
+// expected-warning at -2{{double precision constant requires cl_khr_fp64, casting to single precision}}
 #endif
 }
 
@@ -96,6 +102,9 @@
 
 #if (defined(__OPENCL_C_VERSION__) && __OPENCL_C_VERSION__ < 120)
 void f3(void) {
-  double d; // expected-error {{type 'double' requires cl_khr_fp64 support}}
+  double d;
+#ifdef NOFP64
+// expected-error at -2 {{type 'double' requires cl_khr_fp64 support}}
+#endif
 }
 #endif
Index: clang/lib/Sema/SemaType.cpp
===================================================================
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -1524,6 +1524,10 @@
     break;
   case DeclSpec::TST_float:   Result = Context.FloatTy; break;
   case DeclSpec::TST_double:
+    if (S.getLangOpts().OpenCL &&
+        !S.getOpenCLOptions().isSupported("cl_khr_fp64", S.getLangOpts()))
+      S.Diag(DS.getTypeSpecTypeLoc(), diag::err_opencl_requires_extension)
+          << 0 << Context.DoubleTy << "cl_khr_fp64";
     if (DS.getTypeSpecWidth() == TypeSpecifierWidth::Long)
       Result = Context.LongDoubleTy;
     else
Index: clang/lib/Sema/Sema.cpp
===================================================================
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -363,7 +363,6 @@
       }
     }
 
-    setOpenCLExtensionForType(Context.DoubleTy, "cl_khr_fp64");
 
 #define GENERIC_IMAGE_TYPE_EXT(Type, Id, Ext) \
     setOpenCLExtensionForType(Context.Id, Ext);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100980.339307.patch
Type: text/x-patch
Size: 2839 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210421/7799af37/attachment.bin>


More information about the cfe-commits mailing list