Skip to content

Commit a427390

Browse files
committed
[OpenCL] Add support of __opencl_c_images feature macro
Reviewed By: svenvh Differential Revision: https://reviews.llvm.org/D103911
1 parent 5958dc7 commit a427390

File tree

2 files changed

+80
-5
lines changed

2 files changed

+80
-5
lines changed

clang/lib/Sema/SemaType.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,11 +1721,25 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) {
17211721
if (Result->containsErrors())
17221722
declarator.setInvalidType();
17231723

1724-
if (S.getLangOpts().OpenCL && Result->isOCLImage3dWOType() &&
1725-
!S.getOpenCLOptions().isSupported("cl_khr_3d_image_writes", S.getLangOpts())) {
1726-
S.Diag(DS.getTypeSpecTypeLoc(), diag::err_opencl_requires_extension)
1727-
<< 0 << Result << "cl_khr_3d_image_writes";
1728-
declarator.setInvalidType();
1724+
if (S.getLangOpts().OpenCL) {
1725+
const auto &OpenCLOptions = S.getOpenCLOptions();
1726+
StringRef OptName;
1727+
// OpenCL C v3.0 s6.3.3 - OpenCL image types require __opencl_c_images
1728+
// support
1729+
if ((Result->isImageType() || Result->isSamplerT()) &&
1730+
(S.getLangOpts().OpenCLVersion >= 300 &&
1731+
!OpenCLOptions.isSupported("__opencl_c_images", S.getLangOpts())))
1732+
OptName = "__opencl_c_images";
1733+
else if (Result->isOCLImage3dWOType() &&
1734+
!OpenCLOptions.isSupported("cl_khr_3d_image_writes",
1735+
S.getLangOpts()))
1736+
OptName = "cl_khr_3d_image_writes";
1737+
1738+
if (!OptName.empty()) {
1739+
S.Diag(DS.getTypeSpecTypeLoc(), diag::err_opencl_requires_extension)
1740+
<< 0 << Result << OptName;
1741+
declarator.setInvalidType();
1742+
}
17291743
}
17301744

17311745
bool IsFixedPointType = DS.getTypeSpecType() == DeclSpec::TST_accum ||
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=CL3.0 -cl-ext=-__opencl_c_images %s
2+
// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=CL3.0 -cl-ext=+__opencl_c_images %s
3+
4+
#ifdef __opencl_c_images
5+
//expected-no-diagnostics
6+
#endif
7+
8+
void test1(image1d_t i) {}
9+
#if !defined(__opencl_c_images)
10+
// expected-error@-2{{use of type '__read_only image1d_t' requires __opencl_c_images support}}
11+
#endif
12+
13+
void test2(image2d_t i) {}
14+
#if !defined(__opencl_c_images)
15+
// expected-error@-2{{use of type '__read_only image2d_t' requires __opencl_c_images support}}
16+
#endif
17+
18+
void test3(image1d_array_t i) {}
19+
#if !defined(__opencl_c_images)
20+
// expected-error@-2{{use of type '__read_only image1d_array_t' requires __opencl_c_images support}}
21+
#endif
22+
23+
void test4(image2d_array_t i) {}
24+
#if !defined(__opencl_c_images)
25+
// expected-error@-2{{use of type '__read_only image2d_array_t' requires __opencl_c_images support}}
26+
#endif
27+
28+
void test5(image2d_depth_t i) {}
29+
#if !defined(__opencl_c_images)
30+
// expected-error@-2{{use of type '__read_only image2d_depth_t' requires __opencl_c_images support}}
31+
#endif
32+
33+
void test6(image1d_buffer_t i) {}
34+
#if !defined(__opencl_c_images)
35+
// expected-error@-2{{use of type '__read_only image1d_buffer_t' requires __opencl_c_images support}}
36+
#endif
37+
38+
void test7(image2d_msaa_t i) {}
39+
#if !defined(__opencl_c_images)
40+
// expected-error@-2{{use of type '__read_only image2d_msaa_t' requires __opencl_c_images support}}
41+
#endif
42+
43+
void test8(image2d_array_msaa_t i) {}
44+
#if !defined(__opencl_c_images)
45+
// expected-error@-2{{use of type '__read_only image2d_array_msaa_t' requires __opencl_c_images support}}
46+
#endif
47+
48+
void test9(image2d_msaa_depth_t i) {}
49+
#if !defined(__opencl_c_images)
50+
// expected-error@-2{{use of type '__read_only image2d_msaa_depth_t' requires __opencl_c_images support}}
51+
#endif
52+
53+
void test10(image2d_array_msaa_depth_t i) {}
54+
#if !defined(__opencl_c_images)
55+
// expected-error@-2{{use of type '__read_only image2d_array_msaa_depth_t' requires __opencl_c_images support}}
56+
#endif
57+
58+
void test11(sampler_t s) {}
59+
#if !defined(__opencl_c_images)
60+
// expected-error@-2{{use of type 'sampler_t' requires __opencl_c_images support}}
61+
#endif

0 commit comments

Comments
 (0)