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: 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: 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: 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}} +}