From 81081daef0299ad59fca299c7cde3888fa691c6a Mon Sep 17 00:00:00 2001 From: Justas Janickas Date: Tue, 21 Sep 2021 12:47:00 +0100 Subject: [PATCH] [OpenCL] Allow optional __generic in __remove_address_space utility Clang builtin utility `__remove_address_space` now works if generic address space is not supported in C++ for OpenCL 2021. Differential Revision: https://reviews.llvm.org/D110155 --- clang/lib/Headers/opencl-c-base.h | 2 ++ clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/clang/lib/Headers/opencl-c-base.h b/clang/lib/Headers/opencl-c-base.h index 9c81ddb..7485386 100644 --- a/clang/lib/Headers/opencl-c-base.h +++ b/clang/lib/Headers/opencl-c-base.h @@ -600,9 +600,11 @@ typedef struct { // C++ for OpenCL - __remove_address_space #if defined(__OPENCL_CPP_VERSION__) template struct __remove_address_space { using type = _Tp; }; +#if defined(__opencl_c_generic_address_space) template struct __remove_address_space<__generic _Tp> { using type = _Tp; }; +#endif template struct __remove_address_space<__global _Tp> { using type = _Tp; }; diff --git a/clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp b/clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp index f6f0c32..9043a7d 100644 --- a/clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp +++ b/clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp @@ -1,4 +1,6 @@ -// RUN: %clang_cc1 %s -cl-std=clc++ -fdeclare-opencl-builtins -finclude-default-header +// RUN: %clang_cc1 %s -cl-std=clc++1.0 -fdeclare-opencl-builtins -finclude-default-header +// RUN: %clang_cc1 %s -cl-std=clc++2021 -fdeclare-opencl-builtins -finclude-default-header +// RUN: %clang_cc1 %s -cl-std=clc++2021 -cl-ext=-__opencl_c_generic_address_space,-__opencl_c_pipes -fdeclare-opencl-builtins -finclude-default-header template struct is_same { @@ -19,8 +21,10 @@ void test_is_same() { void test_remove_address_space() { static_assert(is_same<__remove_address_space::type, int>::value, "type without an address space unexpectedly modified by __remove_address_space"); +#if defined(__opencl_c_generic_address_space) static_assert(is_same<__remove_address_space<__generic int>::type, int>::value, "__generic address space not removed by __remove_address_space"); +#endif static_assert(is_same<__remove_address_space<__global char>::type, char>::value, "__global address space not removed by __remove_address_space"); static_assert(is_same<__remove_address_space<__private ulong>::type, ulong>::value, -- 2.7.4