From 1de0048311faf6ad9fba59842c809054ec072437 Mon Sep 17 00:00:00 2001 From: David Bayer Date: Thu, 21 Nov 2024 08:35:13 +0100 Subject: [PATCH 1/8] implement C++26 `std::ignore` --- .../include/cuda/std/__tuple_dir/ignore.h | 42 +++++++++++++++++ .../cuda/std/detail/libcxx/include/tuple | 16 +------ libcudacxx/include/cuda/std/utility | 3 ++ .../tuple/tuple.general/ignore.pass.cpp | 46 ++++++++++++++----- 4 files changed, 81 insertions(+), 26 deletions(-) create mode 100644 libcudacxx/include/cuda/std/__tuple_dir/ignore.h diff --git a/libcudacxx/include/cuda/std/__tuple_dir/ignore.h b/libcudacxx/include/cuda/std/__tuple_dir/ignore.h new file mode 100644 index 00000000000..98844b534c8 --- /dev/null +++ b/libcudacxx/include/cuda/std/__tuple_dir/ignore.h @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___TUPLE_IGNORE_H +#define _LIBCUDACXX___TUPLE_IGNORE_H + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +struct __ignore_t +{ + template + _LIBCUDACXX_HIDE_FROM_ABI constexpr const __ignore_t& operator=(const _Tp&) const noexcept + { + return *this; + } +}; + +namespace +{ +_CCCL_GLOBAL_CONSTANT __ignore_t ignore{}; +} // namespace + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___TUPLE_IGNORE_H diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/tuple b/libcudacxx/include/cuda/std/detail/libcxx/include/tuple index 9a2b39680e1..09bc351a3b9 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/tuple +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/tuple @@ -158,6 +158,7 @@ template #include #include #include +#include #include #include #include @@ -1116,21 +1117,6 @@ _LIBCUDACXX_HIDE_FROM_ABI _CCCL_CONSTEXPR_CXX14 tuple<_Tp&...> tie(_Tp&... __t) return tuple<_Tp&...>(__t...); } -template -struct __ignore_t -{ - template - _LIBCUDACXX_HIDE_FROM_ABI _CCCL_CONSTEXPR_CXX14 const __ignore_t& operator=(_Tp&&) const - { - return *this; - } -}; - -namespace -{ -_CCCL_GLOBAL_CONSTANT __ignore_t ignore{}; -} // namespace - template _LIBCUDACXX_HIDE_FROM_ABI _CCCL_CONSTEXPR_CXX14 tuple::type...> make_tuple(_Tp&&... __t) { diff --git a/libcudacxx/include/cuda/std/utility b/libcudacxx/include/cuda/std/utility index f0b6729d702..573cb04fda1 100644 --- a/libcudacxx/include/cuda/std/utility +++ b/libcudacxx/include/cuda/std/utility @@ -69,6 +69,9 @@ #endif // !_LIBCUDACXX_HAS_NO_SPACESHIP_OPERATOR #include +// [tuple.creation] +#include + // [tuple.helper] #include #include diff --git a/libcudacxx/test/libcudacxx/std/utilities/tuple/tuple.general/ignore.pass.cpp b/libcudacxx/test/libcudacxx/std/utilities/tuple/tuple.general/ignore.pass.cpp index 6e9e5713316..a6018d270e5 100644 --- a/libcudacxx/test/libcudacxx/std/utilities/tuple/tuple.general/ignore.pass.cpp +++ b/libcudacxx/test/libcudacxx/std/utilities/tuple/tuple.general/ignore.pass.cpp @@ -10,45 +10,69 @@ // constexpr unspecified ignore; -// UNSUPPORTED: c++98, c++03 - #include #include #include "test_macros.h" +static_assert(cuda::std::is_trivial::value, ""); + +#if TEST_STD_VER >= 2017 +[[nodiscard]] __host__ __device__ constexpr int test_nodiscard() +{ + return 8294; +} +#endif + __host__ __device__ TEST_CONSTEXPR_CXX14 bool test() { - { // Test that std::ignore provides constexpr converting assignment. + { + auto& ignore_v = cuda::std::ignore; + unused(ignore_v); + } + + { // Test that std::ignore provides converting assignment. auto& res = (cuda::std::ignore = 42); + static_assert(noexcept(res = (cuda::std::ignore = 42)), ""); assert(&res == &cuda::std::ignore); } - { // Test that cuda::std::ignore provides constexpr copy/move constructors + { // Test bit-field binding. + struct S + { + unsigned int bf : 3; + }; + S s{0b010}; + auto& res = (cuda::std::ignore = s.bf); + assert(&res == &cuda::std::ignore); + } + { // Test that std::ignore provides copy/move constructors auto copy = cuda::std::ignore; auto moved = cuda::std::move(copy); unused(moved); } - { // Test that cuda::std::ignore provides constexpr copy/move assignment + { // Test that std::ignore provides copy/move assignment auto copy = cuda::std::ignore; copy = cuda::std::ignore; auto moved = cuda::std::ignore; moved = cuda::std::move(copy); unused(moved); } + +#if TEST_STD_VER >= 2017 + { + cuda::std::ignore = test_nodiscard(); + } +#endif + return true; } -static_assert(cuda::std::is_trivial::value, ""); int main(int, char**) { - { - constexpr auto& ignore_v = cuda::std::ignore; - unused(ignore_v); - } test(); #if TEST_STD_VER >= 2014 static_assert(test(), ""); -#endif // TEST_STD_VER >= 2014 +#endif return 0; } From 9adccdbe77f4d58cbeb1aa720a81786fdbbb7907 Mon Sep 17 00:00:00 2001 From: David Bayer Date: Thu, 21 Nov 2024 10:39:42 +0100 Subject: [PATCH 2/8] replace binary literal with integer --- .../std/utilities/tuple/tuple.general/ignore.pass.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libcudacxx/test/libcudacxx/std/utilities/tuple/tuple.general/ignore.pass.cpp b/libcudacxx/test/libcudacxx/std/utilities/tuple/tuple.general/ignore.pass.cpp index a6018d270e5..a817241164b 100644 --- a/libcudacxx/test/libcudacxx/std/utilities/tuple/tuple.general/ignore.pass.cpp +++ b/libcudacxx/test/libcudacxx/std/utilities/tuple/tuple.general/ignore.pass.cpp @@ -31,7 +31,7 @@ __host__ __device__ TEST_CONSTEXPR_CXX14 bool test() unused(ignore_v); } - { // Test that std::ignore provides converting assignment. + { // Test that cuda::std::ignore provides converting assignment. auto& res = (cuda::std::ignore = 42); static_assert(noexcept(res = (cuda::std::ignore = 42)), ""); assert(&res == &cuda::std::ignore); @@ -41,16 +41,16 @@ __host__ __device__ TEST_CONSTEXPR_CXX14 bool test() { unsigned int bf : 3; }; - S s{0b010}; + S s{3}; auto& res = (cuda::std::ignore = s.bf); assert(&res == &cuda::std::ignore); } - { // Test that std::ignore provides copy/move constructors + { // Test that cuda::std::ignore provides constexpr copy/move constructors auto copy = cuda::std::ignore; auto moved = cuda::std::move(copy); unused(moved); } - { // Test that std::ignore provides copy/move assignment + { // Test that cuda::std::ignore provides constexpr copy/move assignment auto copy = cuda::std::ignore; copy = cuda::std::ignore; auto moved = cuda::std::ignore; From 56d2745cb2362b521101e47a7a57ae7c8316aa4c Mon Sep 17 00:00:00 2001 From: David Bayer Date: Thu, 21 Nov 2024 10:55:01 +0100 Subject: [PATCH 3/8] remove template from `__ignore_t` --- libcudacxx/include/cuda/std/__tuple_dir/ignore.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libcudacxx/include/cuda/std/__tuple_dir/ignore.h b/libcudacxx/include/cuda/std/__tuple_dir/ignore.h index 98844b534c8..535f4ea0e1d 100644 --- a/libcudacxx/include/cuda/std/__tuple_dir/ignore.h +++ b/libcudacxx/include/cuda/std/__tuple_dir/ignore.h @@ -22,7 +22,6 @@ _LIBCUDACXX_BEGIN_NAMESPACE_STD -template struct __ignore_t { template @@ -34,7 +33,7 @@ struct __ignore_t namespace { -_CCCL_GLOBAL_CONSTANT __ignore_t ignore{}; +_CCCL_GLOBAL_CONSTANT __ignore_t ignore{}; } // namespace _LIBCUDACXX_END_NAMESPACE_STD From 2aed90d2880a60b734469f6e5d36ed10d0dd51d5 Mon Sep 17 00:00:00 2001 From: David Bayer Date: Thu, 21 Nov 2024 11:00:40 +0100 Subject: [PATCH 4/8] fix nitpicks --- libcudacxx/include/cuda/std/__tuple_dir/ignore.h | 2 +- .../std/utilities/tuple/tuple.general/ignore.pass.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libcudacxx/include/cuda/std/__tuple_dir/ignore.h b/libcudacxx/include/cuda/std/__tuple_dir/ignore.h index 535f4ea0e1d..08237263c3e 100644 --- a/libcudacxx/include/cuda/std/__tuple_dir/ignore.h +++ b/libcudacxx/include/cuda/std/__tuple_dir/ignore.h @@ -3,7 +3,7 @@ // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. // //===----------------------------------------------------------------------===// diff --git a/libcudacxx/test/libcudacxx/std/utilities/tuple/tuple.general/ignore.pass.cpp b/libcudacxx/test/libcudacxx/std/utilities/tuple/tuple.general/ignore.pass.cpp index a817241164b..fc97b2b9ad0 100644 --- a/libcudacxx/test/libcudacxx/std/utilities/tuple/tuple.general/ignore.pass.cpp +++ b/libcudacxx/test/libcudacxx/std/utilities/tuple/tuple.general/ignore.pass.cpp @@ -22,7 +22,7 @@ static_assert(cuda::std::is_trivial::value, ""); { return 8294; } -#endif +#endif // TEST_STD_VER >= 2017 __host__ __device__ TEST_CONSTEXPR_CXX14 bool test() { @@ -62,7 +62,7 @@ __host__ __device__ TEST_CONSTEXPR_CXX14 bool test() { cuda::std::ignore = test_nodiscard(); } -#endif +#endif // TEST_STD_VER >= 2017 return true; } @@ -72,7 +72,7 @@ int main(int, char**) test(); #if TEST_STD_VER >= 2014 static_assert(test(), ""); -#endif +#endif // TEST_STD_VER >= 2014 return 0; } From 55c8e4b0fc898efa85c14cdbc09deaf80270edb0 Mon Sep 17 00:00:00 2001 From: David Bayer Date: Fri, 22 Nov 2024 09:45:34 +0100 Subject: [PATCH 5/8] implement `__ignore_t` constructors --- libcudacxx/include/cuda/std/__tuple_dir/ignore.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libcudacxx/include/cuda/std/__tuple_dir/ignore.h b/libcudacxx/include/cuda/std/__tuple_dir/ignore.h index 08237263c3e..35cffef7884 100644 --- a/libcudacxx/include/cuda/std/__tuple_dir/ignore.h +++ b/libcudacxx/include/cuda/std/__tuple_dir/ignore.h @@ -24,6 +24,12 @@ _LIBCUDACXX_BEGIN_NAMESPACE_STD struct __ignore_t { + __ignore_t() = default; + + template + _LIBCUDACXX_HIDE_FROM_ABI constexpr __ignore_t(const _Ts&...) noexcept + {} + template _LIBCUDACXX_HIDE_FROM_ABI constexpr const __ignore_t& operator=(const _Tp&) const noexcept { From 60a759d0296fe9069a86e9ec80c40b8819ffac41 Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Sun, 24 Nov 2024 10:17:08 -0800 Subject: [PATCH 6/8] require at least one arg to the non-trivial constructor this makes `__ignore_t` a trivial class type --- libcudacxx/include/cuda/std/__tuple_dir/ignore.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libcudacxx/include/cuda/std/__tuple_dir/ignore.h b/libcudacxx/include/cuda/std/__tuple_dir/ignore.h index 35cffef7884..5d3b3377646 100644 --- a/libcudacxx/include/cuda/std/__tuple_dir/ignore.h +++ b/libcudacxx/include/cuda/std/__tuple_dir/ignore.h @@ -26,8 +26,8 @@ struct __ignore_t { __ignore_t() = default; - template - _LIBCUDACXX_HIDE_FROM_ABI constexpr __ignore_t(const _Ts&...) noexcept + template + _LIBCUDACXX_HIDE_FROM_ABI constexpr __ignore_t(const _Tp&, const _Ts&...) noexcept {} template From c95a3705c511fe9199f2efaf5d915c9261ac7009 Mon Sep 17 00:00:00 2001 From: David Bayer Date: Sun, 24 Nov 2024 23:31:30 +0100 Subject: [PATCH 7/8] change ignore type requirements --- .../std/utilities/tuple/tuple.general/ignore.pass.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libcudacxx/test/libcudacxx/std/utilities/tuple/tuple.general/ignore.pass.cpp b/libcudacxx/test/libcudacxx/std/utilities/tuple/tuple.general/ignore.pass.cpp index fc97b2b9ad0..02852a163c9 100644 --- a/libcudacxx/test/libcudacxx/std/utilities/tuple/tuple.general/ignore.pass.cpp +++ b/libcudacxx/test/libcudacxx/std/utilities/tuple/tuple.general/ignore.pass.cpp @@ -15,7 +15,7 @@ #include "test_macros.h" -static_assert(cuda::std::is_trivial::value, ""); +static_assert(cuda::std::is_trivially_default_constructible::value, ""); #if TEST_STD_VER >= 2017 [[nodiscard]] __host__ __device__ constexpr int test_nodiscard() From b50844ded4ce4bbecbeb2648195051687acbd9f1 Mon Sep 17 00:00:00 2001 From: David Bayer Date: Tue, 26 Nov 2024 14:00:25 +0100 Subject: [PATCH 8/8] disable nodiscard assignment test for cuda before 11.3 --- .../utilities/tuple/tuple.general/ignore.pass.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/libcudacxx/test/libcudacxx/std/utilities/tuple/tuple.general/ignore.pass.cpp b/libcudacxx/test/libcudacxx/std/utilities/tuple/tuple.general/ignore.pass.cpp index 02852a163c9..d44b90dd8c1 100644 --- a/libcudacxx/test/libcudacxx/std/utilities/tuple/tuple.general/ignore.pass.cpp +++ b/libcudacxx/test/libcudacxx/std/utilities/tuple/tuple.general/ignore.pass.cpp @@ -15,14 +15,17 @@ #include "test_macros.h" -static_assert(cuda::std::is_trivially_default_constructible::value, ""); +static_assert(cuda::std::is_trivially_default_constructible::value + && cuda::std::is_empty::value, + ""); -#if TEST_STD_VER >= 2017 -[[nodiscard]] __host__ __device__ constexpr int test_nodiscard() +// constexpr variables are unavailable before 11.3 +#if TEST_STD_VER >= 2017 && _CCCL_CUDACC_AT_LEAST(11, 3) +TEST_NODISCARD __host__ __device__ constexpr int test_nodiscard() { return 8294; } -#endif // TEST_STD_VER >= 2017 +#endif // TEST_STD_VER >= 2017 && _CCCL_CUDACC_AT_LEAST(11, 3) __host__ __device__ TEST_CONSTEXPR_CXX14 bool test() { @@ -58,11 +61,11 @@ __host__ __device__ TEST_CONSTEXPR_CXX14 bool test() unused(moved); } -#if TEST_STD_VER >= 2017 +#if TEST_STD_VER >= 2017 && _CCCL_CUDACC_AT_LEAST(11, 3) { cuda::std::ignore = test_nodiscard(); } -#endif // TEST_STD_VER >= 2017 +#endif // TEST_STD_VER >= 2017 && _CCCL_CUDACC_AT_LEAST(11, 3) return true; }