[PATCH] D27917: [OpenCL] Improve diagnostics for double type
yaxunl added a comment. with the new pragma for associating types with extensions. This feature can be implemented by solely modify opencl-c.h by adding #pragma OPENCL EXTENSION cl_khr_fp64 : begin/end around vector double type definitions, e.g. #pragma OPENCL EXTENSION cl_khr_fp64 : begin typedef double double2 __attribute__((ext_vector_type(2))); typedef double double3 __attribute__((ext_vector_type(3))); typedef double double4 __attribute__((ext_vector_type(4))); typedef double double8 __attribute__((ext_vector_type(8))); typedef double double16 __attribute__((ext_vector_type(16))); #pragma OPENCL EXTENSION cl_khr_fp64 : end #ifdef cl_khr_fp64 #if __OPENCL_C_VERSION__ < CL_VERSION_1_2 #pragma OPENCL EXTENSION cl_khr_fp64 : enable #endif #endif The #pragma OPENCL EXTENSION cl_khr_fp64 : enable is for suppressing diagnostics due to using double type in builtin functions. Ideally they should also be surrounded by #pragma OPENCL EXTENSION cl_khr_fp64 : begin/end. https://reviews.llvm.org/D27917 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D27917: [OpenCL] Improve diagnostics for double type
echuraev added a comment. This diagnostic was added in this commit: https://reviews.llvm.org/rL289979 It is something like that: "use of undeclared identifier 'double2'; did you mean 'double'?" This message isn't clear enough and it is difficult to understand that I forgot to enable cl_khr_fp64 extension. May be it will be better to change this diagnostic message to something like that: "use of type 'double2' (vector of 2 'double' values) requires cl_khr_fp64 extension to be enabled" https://reviews.llvm.org/D27917 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D27917: [OpenCL] Improve diagnostics for double type
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@-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@-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(CanonicalType)) +return BT->getKind() >= BuiltinType::Double && + BT->getKind() <= BuiltinType::LongDouble; + return false; +} + +bool Type::isDoubleVecType() const { + if (const VectorType *VT = dyn_cast(CanonicalType)) +return VT->getElementType()->isDoubleType(); + return false; +} + bool Type::hasFloatingRepresentation() const { if (const VectorType *VT = dyn_cast(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 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@-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,
[PATCH] D27917: [OpenCL] Improve diagnostics for double type
yaxunl added inline comments. Comment at: lib/Sema/SemaType.cpp:1505 + S.getLangOpts().OpenCLVersion < 120 && + !S.getOpenCLOptions().cl_khr_fp64) { +S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_requires_extension) Please update with clang ToT since OpenCLOptions has interface changes. https://reviews.llvm.org/D27917 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D27917: [OpenCL] Improve diagnostics for double type
echuraev created this revision. echuraev added a reviewer: Anastasia. echuraev added subscribers: bader, cfe-commits, yaxunl. 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@-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@-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().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(CanonicalType)) +return BT->getKind() >= BuiltinType::Double && + BT->getKind() <= BuiltinType::LongDouble; + return false; +} + +bool Type::isDoubleVecType() const { + if (const VectorType *VT = dyn_cast(CanonicalType)) +return VT->getElementType()->isDoubleType(); + return false; +} + bool Type::hasFloatingRepresentation() const { if (const VectorType *VT = dyn_cast(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 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@-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,