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 @@ -1721,11 +1721,25 @@ if (Result->containsErrors()) declarator.setInvalidType(); - if (S.getLangOpts().OpenCL && Result->isOCLImage3dWOType() && - !S.getOpenCLOptions().isSupported("cl_khr_3d_image_writes", S.getLangOpts())) { - S.Diag(DS.getTypeSpecTypeLoc(), diag::err_opencl_requires_extension) - << 0 << Result << "cl_khr_3d_image_writes"; - declarator.setInvalidType(); + if (S.getLangOpts().OpenCL) { + const auto &OpenCLOptions = S.getOpenCLOptions(); + StringRef OptName; + // OpenCL C v3.0 s6.3.3 - OpenCL image types require __opencl_c_images + // support + if ((Result->isImageType() || Result->isSamplerT()) && + (S.getLangOpts().OpenCLVersion >= 300 && + !OpenCLOptions.isSupported("__opencl_c_images", S.getLangOpts()))) + OptName = "__opencl_c_images"; + else if (Result->isOCLImage3dWOType() && + !OpenCLOptions.isSupported("cl_khr_3d_image_writes", + S.getLangOpts())) + OptName = "cl_khr_3d_image_writes"; + + if (!OptName.empty()) { + S.Diag(DS.getTypeSpecTypeLoc(), diag::err_opencl_requires_extension) + << 0 << Result << OptName; + declarator.setInvalidType(); + } } bool IsFixedPointType = DS.getTypeSpecType() == DeclSpec::TST_accum || diff --git a/clang/test/SemaOpenCL/unsupported-image.cl b/clang/test/SemaOpenCL/unsupported-image.cl new file mode 100644 --- /dev/null +++ b/clang/test/SemaOpenCL/unsupported-image.cl @@ -0,0 +1,61 @@ +// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=CL3.0 -cl-ext=-__opencl_c_images %s +// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=CL3.0 -cl-ext=+__opencl_c_images %s + +#ifdef __opencl_c_images +//expected-no-diagnostics +#endif + +void test1(image1d_t i) {} +#if !defined(__opencl_c_images) +// expected-error@-2{{use of type '__read_only image1d_t' requires __opencl_c_images support}} +#endif + +void test2(image2d_t i) {} +#if !defined(__opencl_c_images) +// expected-error@-2{{use of type '__read_only image2d_t' requires __opencl_c_images support}} +#endif + +void test3(image1d_array_t i) {} +#if !defined(__opencl_c_images) +// expected-error@-2{{use of type '__read_only image1d_array_t' requires __opencl_c_images support}} +#endif + +void test4(image2d_array_t i) {} +#if !defined(__opencl_c_images) +// expected-error@-2{{use of type '__read_only image2d_array_t' requires __opencl_c_images support}} +#endif + +void test5(image2d_depth_t i) {} +#if !defined(__opencl_c_images) +// expected-error@-2{{use of type '__read_only image2d_depth_t' requires __opencl_c_images support}} +#endif + +void test6(image1d_buffer_t i) {} +#if !defined(__opencl_c_images) +// expected-error@-2{{use of type '__read_only image1d_buffer_t' requires __opencl_c_images support}} +#endif + +void test7(image2d_msaa_t i) {} +#if !defined(__opencl_c_images) +// expected-error@-2{{use of type '__read_only image2d_msaa_t' requires __opencl_c_images support}} +#endif + +void test8(image2d_array_msaa_t i) {} +#if !defined(__opencl_c_images) +// expected-error@-2{{use of type '__read_only image2d_array_msaa_t' requires __opencl_c_images support}} +#endif + +void test9(image2d_msaa_depth_t i) {} +#if !defined(__opencl_c_images) +// expected-error@-2{{use of type '__read_only image2d_msaa_depth_t' requires __opencl_c_images support}} +#endif + +void test10(image2d_array_msaa_depth_t i) {} +#if !defined(__opencl_c_images) +// expected-error@-2{{use of type '__read_only image2d_array_msaa_depth_t' requires __opencl_c_images support}} +#endif + +void test11(sampler_t s) {} +#if !defined(__opencl_c_images) +// expected-error@-2{{use of type 'sampler_t' requires __opencl_c_images support}} +#endif