[clang] 4138e7b - [OpenCL] Add missing C++ legacy atomics with generic
Sven van Haastregt via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 22 07:08:46 PDT 2021
Author: Sven van Haastregt
Date: 2021-04-22T15:08:36+01:00
New Revision: 4138e7bd7692c27a4959191939bba899b4f240da
URL: https://github.com/llvm/llvm-project/commit/4138e7bd7692c27a4959191939bba899b4f240da
DIFF: https://github.com/llvm/llvm-project/commit/4138e7bd7692c27a4959191939bba899b4f240da.diff
LOG: [OpenCL] Add missing C++ legacy atomics with generic
https://reviews.llvm.org/D62335 added some C++ for OpenCL specific
builtins to opencl-c.h, but these were not mirrored to the TableGen
builtin functions yet.
The TableGen builtins machinery does not have dedicated version
handling for C++ for OpenCL at the moment: all builtin versioning is
tied to `LangOpts.OpenCLVersion` (i.e., the OpenCL C version). As a
workaround, to add builtins that are only available in C++ for OpenCL,
we define a function extension guarded by the __cplusplus macro.
Differential Revision: https://reviews.llvm.org/D100935
Fixes PR50041.
Added:
Modified:
clang/lib/Sema/OpenCLBuiltins.td
clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
Removed:
################################################################################
diff --git a/clang/lib/Sema/OpenCLBuiltins.td b/clang/lib/Sema/OpenCLBuiltins.td
index 5a9d9822dbfe3..eb8034ee630ce 100644
--- a/clang/lib/Sema/OpenCLBuiltins.td
+++ b/clang/lib/Sema/OpenCLBuiltins.td
@@ -82,6 +82,9 @@ def FuncExtKhrMipmapImage : FunctionExtension<"cl_khr_mipmap_imag
def FuncExtKhrMipmapImageWrites : FunctionExtension<"cl_khr_mipmap_image_writes">;
def FuncExtKhrGlMsaaSharing : FunctionExtension<"cl_khr_gl_msaa_sharing">;
+// Not a real extension, but a workaround to add C++ for OpenCL specific builtins.
+def FuncExtOpenCLCxx : FunctionExtension<"__cplusplus">;
+
// Multiple extensions
def FuncExtKhrMipmapWritesAndWrite3d : FunctionExtension<"cl_khr_mipmap_image_writes cl_khr_3d_image_writes">;
@@ -1077,6 +1080,17 @@ foreach AS = [GlobalAS, LocalAS] in {
}
}
}
+
+let Extension = FuncExtOpenCLCxx in {
+ foreach Type = [Int, UInt] in {
+ foreach name = ["atomic_add", "atomic_sub", "atomic_xchg",
+ "atomic_min", "atomic_max", "atomic_and",
+ "atomic_or", "atomic_xor"] in {
+ def : Builtin<name, [Type, PointerType<VolatileType<Type>, GenericAS>, Type]>;
+ }
+ }
+}
+
// OpenCL v2.0 s6.13.11 - Atomic Functions.
let MinVersion = CL20 in {
def : Builtin<"atomic_work_item_fence", [Void, MemFenceFlags, MemoryOrder, MemoryScope]>;
diff --git a/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl b/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
index 36bdcffbeca48..32457eb939c03 100644
--- a/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
+++ b/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
@@ -122,6 +122,17 @@ void test_atomic_fetch(volatile __generic atomic_int *a_int,
}
#endif
+// Test old atomic overloaded with generic address space in C++ for OpenCL.
+#if __OPENCL_C_VERSION__ >= 200
+void test_legacy_atomics_cpp(__generic volatile unsigned int *a) {
+ atomic_add(a, 1);
+#if !defined(__cplusplus)
+ // expected-error at -2{{no matching function for call to 'atomic_add'}}
+ // expected-note at -3 4 {{candidate function not viable}}
+#endif
+}
+#endif
+
kernel void basic_conversion() {
float f;
char2 c2;
More information about the cfe-commits
mailing list