diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -10023,6 +10023,9 @@ "invalid prototype, variadic arguments are not allowed in OpenCL">; def err_opencl_requires_extension : Error< "use of %select{type|declaration}0 %1 requires %2 support">; +def ext_opencl_double_without_pragma : Extension< + "Clang permits use of type 'double' regardless pragma if 'cl_khr_fp64' is" + " supported">; def warn_opencl_generic_address_space_arg : Warning< "passing non-generic address space pointer to %0" " may cause dynamic conversion affecting performance">, diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp --- a/clang/lib/Sema/Sema.cpp +++ b/clang/lib/Sema/Sema.cpp @@ -366,7 +366,6 @@ "cl_khr_int64_base_atomics cl_khr_int64_extended_atomics"); } - setOpenCLExtensionForType(Context.DoubleTy, "cl_khr_fp64"); #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ if (getOpenCLOptions().isSupported(#Ext, getLangOpts())) { \ diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -1524,6 +1524,13 @@ break; case DeclSpec::TST_float: Result = Context.FloatTy; break; case DeclSpec::TST_double: + if (S.getLangOpts().OpenCL) { + if (!S.getOpenCLOptions().isSupported("cl_khr_fp64", S.getLangOpts())) + S.Diag(DS.getTypeSpecTypeLoc(), diag::err_opencl_requires_extension) + << 0 << Context.DoubleTy << "cl_khr_fp64"; + else if (!S.getOpenCLOptions().isAvailableOption("cl_khr_fp64", S.getLangOpts())) + S.Diag(DS.getTypeSpecTypeLoc(), diag::ext_opencl_double_without_pragma); + } if (DS.getTypeSpecWidth() == TypeSpecifierWidth::Long) Result = Context.LongDoubleTy; else diff --git a/clang/test/Misc/warning-flags.c b/clang/test/Misc/warning-flags.c --- a/clang/test/Misc/warning-flags.c +++ b/clang/test/Misc/warning-flags.c @@ -91,4 +91,4 @@ The list of warnings in -Wpedantic should NEVER grow. -CHECK: Number in -Wpedantic (not covered by other -W flags): 26 +CHECK: Number in -Wpedantic (not covered by other -W flags): 27 diff --git a/clang/test/SemaOpenCL/extensions.cl b/clang/test/SemaOpenCL/extensions.cl --- a/clang/test/SemaOpenCL/extensions.cl +++ b/clang/test/SemaOpenCL/extensions.cl @@ -1,5 +1,6 @@ // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.1 +// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -fsyntax-only -cl-std=CL1.1 -DNOPEDANTIC // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.2 -DFP64 // Test with a target not supporting fp64. @@ -43,8 +44,20 @@ #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 f1(double da) { +#ifdef NOFP64 +// expected-error@-2 {{type 'double' requires cl_khr_fp64 support}} +#elif !defined(NOPEDANTIC) +// expected-warning@-4{{Clang permits use of type 'double' regardless pragma if 'cl_khr_fp64' is supported}} +#endif + double d; +#ifdef NOFP64 +// expected-error@-2 {{type 'double' requires cl_khr_fp64 support}} +#elif !defined(NOPEDANTIC) +// expected-warning@-4{{Clang permits use of type 'double' regardless pragma if 'cl_khr_fp64' is supported}} +#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 +92,11 @@ double4 d4 = {0.0f, 2.0f, 3.0f, 1.0f}; #ifdef NOFP64 // expected-error@-3 {{use of type 'double' requires cl_khr_fp64 support}} -// expected-error@-3 {{use of type 'double4' (vector of 4 'double' values) requires cl_khr_fp64 support}} #endif (void) 1.0; - #ifdef NOFP64 -// expected-warning@-3{{double precision constant requires cl_khr_fp64, casting to single precision}} +// expected-warning@-2{{double precision constant requires cl_khr_fp64, casting to single precision}} #endif } @@ -96,6 +107,11 @@ #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@-2 {{type 'double' requires cl_khr_fp64 support}} +#elif !defined(NOPEDANTIC) +// expected-warning@-4 {{Clang permits use of type 'double' regardless pragma if 'cl_khr_fp64' is supported}} +#endif } #endif