[PATCH] D27917: [OpenCL] Improve diagnostics for double type

Egor Churaev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 20 04:42:27 PST 2016


echuraev updated this revision to Diff 82094.
echuraev marked an inline comment as done.

https://reviews.llvm.org/D27917

Files:
  include/clang/AST/Type.h
  lib/AST/Type.cpp
  lib/Sema/SemaType.cpp
  test/SemaOpenCL/unknown_type.cl


Index: test/SemaOpenCL/unknown_type.cl
===================================================================
--- /dev/null
+++ test/SemaOpenCL/unknown_type.cl
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -cl-std=CL1.1 -fsyntax-only -verify %s
+typedef double double2 __attribute__((ext_vector_type(2)));   // expected-error {{use of type 'double' requires cl_khr_fp64 extension to be enabled}}
+typedef double double16 __attribute__((ext_vector_type(16))); // expected-error {{use of type 'double' requires cl_khr_fp64 extension to be enabled}}
+#pragma OPENCL EXTENSION all : disable
+void foo()
+{
+    (double)(3.14); // expected-error {{use of type 'double' requires cl_khr_fp64 extension to be enabled}} // expected-warning {{double precision constant requires cl_khr_fp64, casting to single precision}}
+    (double2)(1.0, 3.14); // expected-error {{use of type 'double2' (vector of 2 'double' values) requires cl_khr_fp64 extension to be enabled}}
+    // expected-warning at -1 2{{double precision constant requires cl_khr_fp64, casting to single precision}}
+    (double16)(123455.134, 123455.134, 2.0, -12345.032, -12345.032, 1.0, 1.0, 2.0, 2.0, 0.0, 0.0, 0.0, -1.23, -1.23, 1.0, 123455.134); // expected-error {{use of type 'double16' (vector of 16 'double' values) requires cl_khr_fp64 extension to be enabled}}
+    // expected-warning at -1 16{{double precision constant requires cl_khr_fp64, casting to single precision}}
+}
Index: lib/Sema/SemaType.cpp
===================================================================
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -1500,6 +1500,12 @@
         S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_requires_extension)
             << Result << "cl_khr_gl_msaa_sharing";
         declarator.setInvalidType(true);
+      } else if ((Result->isDoubleType() || Result->isDoubleVecType()) &&
+                  S.getLangOpts().OpenCLVersion < 120 &&
+                  !S.getOpenCLOptions().isEnabled("cl_khr_fp64")) {
+        S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_requires_extension)
+            << Result << "cl_khr_fp64";
+        declarator.setInvalidType(true);
       }
     }
 
Index: lib/AST/Type.cpp
===================================================================
--- lib/AST/Type.cpp
+++ lib/AST/Type.cpp
@@ -1809,6 +1809,19 @@
   return false;
 }
 
+bool Type::isDoubleType() const {
+  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
+    return BT->getKind() >= BuiltinType::Double &&
+           BT->getKind() <= BuiltinType::LongDouble;
+  return false;
+}
+
+bool Type::isDoubleVecType() const {
+  if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
+    return VT->getElementType()->isDoubleType();
+  return false;
+}
+
 bool Type::hasFloatingRepresentation() const {
   if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
     return VT->getElementType()->isFloatingType();
Index: include/clang/AST/Type.h
===================================================================
--- include/clang/AST/Type.h
+++ include/clang/AST/Type.h
@@ -1649,6 +1649,8 @@
   bool isAnyComplexType() const;   // C99 6.2.5p11 (complex) + Complex Int.
   bool isFloatingType() const;     // C99 6.2.5p11 (real floating + complex)
   bool isHalfType() const;         // OpenCL 6.1.1.1, NEON (IEEE 754-2008 half)
+  bool isDoubleType() const;       // (double + long double)
+  bool isDoubleVecType() const;
   bool isRealType() const;         // C99 6.2.5p17 (real floating + integer)
   bool isArithmeticType() const;   // C99 6.2.5p18 (integer + floating)
   bool isVoidType() const;         // C99 6.2.5p19


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27917.82094.patch
Type: text/x-patch
Size: 3614 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161220/7345dc0c/attachment.bin>


More information about the cfe-commits mailing list