Skip to content

Commit fb321c2

Browse files
committed
[OpenCL] Define OpenCL 3.0 optional core features in C++ for OpenCL 2021
Modifies OpenCL 3.0 optional core feature macro definitions so that they are set analogously in C++ for OpenCL 2021. This change aims to achieve compatibility between C++ for OpenCL 2021 and OpenCL 3.0. Differential Revision: https://reviews.llvm.org/D108704
1 parent c568985 commit fb321c2

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

clang/lib/Headers/opencl-c-base.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#endif // (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)
3131

3232
// Define feature macros for OpenCL C 2.0
33-
#if (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ == 200)
33+
#if (__OPENCL_CPP_VERSION__ == 100 || __OPENCL_C_VERSION__ == 200)
3434
#define __opencl_c_pipes 1
3535
#define __opencl_c_generic_address_space 1
3636
#define __opencl_c_work_group_collective_functions 1
@@ -45,12 +45,12 @@
4545
#endif
4646

4747
// Define header-only feature macros for OpenCL C 3.0.
48-
#if (__OPENCL_C_VERSION__ == 300)
48+
#if (__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300)
4949
// For the SPIR target all features are supported.
5050
#if defined(__SPIR__)
5151
#define __opencl_c_atomic_scope_all_devices 1
5252
#endif // defined(__SPIR__)
53-
#endif // (__OPENCL_C_VERSION__ == 300)
53+
#endif // (__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300)
5454

5555
// built-in scalar data types:
5656

clang/test/Headers/opencl-c-header.cl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,13 @@ global atomic_int z = ATOMIC_VAR_INIT(99);
175175
#endif //(defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)
176176

177177
// OpenCL C features.
178-
#if (__OPENCL_C_VERSION__ == 300)
178+
#if (__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300)
179179

180180
#if __opencl_c_atomic_scope_all_devices != 1
181181
#error "Incorrectly defined feature macro __opencl_c_atomic_scope_all_devices"
182182
#endif
183183

184-
#elif (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ == 200)
184+
#elif (__OPENCL_CPP_VERSION__ == 100 || __OPENCL_C_VERSION__ == 200)
185185

186186
#ifndef __opencl_c_pipes
187187
#error "Feature macro __opencl_c_pipes should be defined"
@@ -262,6 +262,6 @@ global atomic_int z = ATOMIC_VAR_INIT(99);
262262
#error "Incorrect feature macro __opencl_c_subgroups define"
263263
#endif
264264

265-
#endif //(defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ == 200)
265+
#endif // (__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300)
266266

267267
#endif // defined(__SPIR__)

clang/test/SemaOpenCL/features.cl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66
// RUN: | FileCheck -match-full-lines %s --check-prefix=NO-FEATURES
77
// RUN: %clang_cc1 -triple r600-unknown-unknown %s -E -dM -o - -x cl -cl-std=CL3.0 -cl-ext=+all \
88
// RUN: | FileCheck -match-full-lines %s --check-prefix=FEATURES
9+
// RUN: %clang_cc1 -triple spir-unknown-unknown %s -E -dM -o - -x cl -cl-std=clc++2021 -cl-ext=-all \
10+
// RUN: | FileCheck -match-full-lines %s --check-prefix=NO-FEATURES
11+
// RUN: %clang_cc1 -triple spir-unknown-unknown %s -E -dM -o - -x cl -cl-std=clc++2021 -cl-ext=+all \
12+
// RUN: | FileCheck -match-full-lines %s --check-prefix=FEATURES
13+
// RUN: %clang_cc1 -triple r600-unknown-unknown %s -E -dM -o - -x cl -cl-std=clc++2021 \
14+
// RUN: | FileCheck -match-full-lines %s --check-prefix=NO-FEATURES
15+
// RUN: %clang_cc1 -triple r600-unknown-unknown %s -E -dM -o - -x cl -cl-std=clc++2021 -cl-ext=+all \
16+
// RUN: | FileCheck -match-full-lines %s --check-prefix=FEATURES
917

1018
// For OpenCL C 2.0 feature macros are defined only in header, so test that earlier OpenCL
1119
// versions don't define feature macros accidentally and CL2.0 don't define them without header
@@ -15,7 +23,7 @@
1523
// RUN: | FileCheck -match-full-lines %s --check-prefix=NO-FEATURES
1624
// RUN: %clang_cc1 -triple spir-unknown-unknown %s -E -dM -o - -x cl -cl-std=CL2.0 \
1725
// RUN: | FileCheck -match-full-lines %s --check-prefix=NO-FEATURES
18-
// RUN: %clang_cc1 -triple spir-unknown-unknown %s -E -dM -o - -x cl -cl-std=CLC++ \
26+
// RUN: %clang_cc1 -triple spir-unknown-unknown %s -E -dM -o - -x cl -cl-std=clc++1.0 \
1927
// RUN: | FileCheck -match-full-lines %s --check-prefix=NO-FEATURES
2028

2129
// Note that __opencl_c_int64 is always defined assuming

0 commit comments

Comments
 (0)