diff --git a/clang/lib/Headers/opencl-c-base.h b/clang/lib/Headers/opencl-c-base.h --- a/clang/lib/Headers/opencl-c-base.h +++ b/clang/lib/Headers/opencl-c-base.h @@ -39,6 +39,14 @@ #define __opencl_c_images 1 #endif +// Define header-only feature macros for OpenCL C 3.0. +#if (__OPENCL_C_VERSION__ == 300) +// For the SPIR target all features are supported. +#if defined(__SPIR__) +#define __opencl_c_atomic_scope_all_devices 1 +#endif // defined(__SPIR__) +#endif // (__OPENCL_C_VERSION__ == 300) + // built-in scalar data types: /** @@ -312,7 +320,12 @@ memory_scope_work_item = __OPENCL_MEMORY_SCOPE_WORK_ITEM, memory_scope_work_group = __OPENCL_MEMORY_SCOPE_WORK_GROUP, memory_scope_device = __OPENCL_MEMORY_SCOPE_DEVICE, +#if defined(__opencl_c_atomic_scope_all_devices) memory_scope_all_svm_devices = __OPENCL_MEMORY_SCOPE_ALL_SVM_DEVICES, +#if (__OPENCL_C_VERSION__ >= CL_VERSION_3_0) + memory_scope_all_devices = memory_scope_all_svm_devices, +#endif // __OPENCL_C_VERSION__ >= CL_VERSION_3_0 +#endif // defined(__opencl_c_atomic_scope_all_devices) #if defined(cl_intel_subgroups) || defined(cl_khr_subgroups) memory_scope_sub_group = __OPENCL_MEMORY_SCOPE_SUB_GROUP #endif diff --git a/clang/test/Headers/opencl-c-header.cl b/clang/test/Headers/opencl-c-header.cl --- a/clang/test/Headers/opencl-c-header.cl +++ b/clang/test/Headers/opencl-c-header.cl @@ -151,7 +151,13 @@ #endif //(defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200) // OpenCL C features. -#if (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ == 200) +#if (__OPENCL_C_VERSION__ == 300) + +#if __opencl_c_atomic_scope_all_devices != 1 +#error "Incorrectly defined feature macro __opencl_c_atomic_scope_all_devices" +#endif + +#elif (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ == 200) #ifndef __opencl_c_pipes #error "Feature macro __opencl_c_pipes should be defined" diff --git a/clang/test/SemaOpenCL/atomic-ops.cl b/clang/test/SemaOpenCL/atomic-ops.cl --- a/clang/test/SemaOpenCL/atomic-ops.cl +++ b/clang/test/SemaOpenCL/atomic-ops.cl @@ -2,6 +2,7 @@ // RUN: -fsyntax-only -triple=spir64 -fdeclare-opencl-builtins -finclude-default-header // RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -fsyntax-only \ // RUN: -triple=amdgcn-amd-amdhsa -fdeclare-opencl-builtins -finclude-default-header +// TODO: add -cl-std=CL3.0 line when generic and psv are supported. // Basic parsing/Sema tests for __opencl_atomic_* @@ -161,6 +162,11 @@ (void)__opencl_atomic_load(Ap, memory_order_relaxed, memory_scope_work_group); (void)__opencl_atomic_load(Ap, memory_order_relaxed, memory_scope_device); (void)__opencl_atomic_load(Ap, memory_order_relaxed, memory_scope_all_svm_devices); + (void)__opencl_atomic_load(Ap, memory_order_relaxed, memory_scope_all_devices); +#if __OPENCL_C_VERSION__ < CL_VERSION_3_0 + // expected-error@-2{{use of undeclared identifier 'memory_scope_all_devices'}} + // expected-note@* {{'memory_scope_all_svm_devices' declared here}} +#endif (void)__opencl_atomic_load(Ap, memory_order_relaxed, memory_scope_sub_group); (void)__opencl_atomic_load(Ap, memory_order_relaxed, scope); (void)__opencl_atomic_load(Ap, memory_order_relaxed, 10); //expected-error{{synchronization scope argument to atomic operation is invalid}}