From 85933688e0642aa9563ad03ea3fc3b3d70c1c910 Mon Sep 17 00:00:00 2001 From: Peng Xie Date: Tue, 19 Nov 2024 16:24:00 +0800 Subject: [PATCH 1/2] [libc++] Update the status for lwg-3120 Current implementation already have struct __initial_descriptor which saves the initial state. When release() called, we will reset ptr __initial_descriptor.__cur_, next buffer size never changed. This patch update the lwg 3120 issue latest status and add test. --- libcxx/docs/Status/Cxx23Issues.csv | 2 +- .../release_reset_initial_status.pass.cpp | 49 +++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 libcxx/test/std/utilities/utility/mem.res/mem.res.monotonic.buffer/mem.res.monotonic.buffer.mem/release_reset_initial_status.pass.cpp diff --git a/libcxx/docs/Status/Cxx23Issues.csv b/libcxx/docs/Status/Cxx23Issues.csv index 1215f21985eb9..421ae8c8e3d71 100644 --- a/libcxx/docs/Status/Cxx23Issues.csv +++ b/libcxx/docs/Status/Cxx23Issues.csv @@ -14,7 +14,7 @@ "`LWG2731 `__","Existence of ``lock_guard::mutex_type`` typedef unclear","2020-11 (Virtual)","|Complete|","5","" "`LWG2743 `__","P0083R3 ``node_handle`` private members missing ""exposition only"" comment","2020-11 (Virtual)","|Nothing To Do|","","" "`LWG2820 `__","Clarify ```` macros","2020-11 (Virtual)","|Nothing To Do|","","" -"`LWG3120 `__","Unclear behavior of ``monotonic_buffer_resource::release()``","2020-11 (Virtual)","","","" +"`LWG3120 `__","Unclear behavior of ``monotonic_buffer_resource::release()``","2020-11 (Virtual)","|Complete|","16","" "`LWG3170 `__","``is_always_equal`` added to ``std::allocator`` makes the standard library treat derived types as always equal","2020-11 (Virtual)","|Complete|","18","" "`LWG3036 `__","``polymorphic_allocator::destroy`` is extraneous","2020-11 (Virtual)","|Nothing To Do|","","Reverted by P2875R4" "`LWG3171 `__","LWG2989 breaks ``directory_entry`` stream insertion","2020-11 (Virtual)","|Complete|","14","" diff --git a/libcxx/test/std/utilities/utility/mem.res/mem.res.monotonic.buffer/mem.res.monotonic.buffer.mem/release_reset_initial_status.pass.cpp b/libcxx/test/std/utilities/utility/mem.res/mem.res.monotonic.buffer/mem.res.monotonic.buffer.mem/release_reset_initial_status.pass.cpp new file mode 100644 index 0000000000000..765a5a8f0326d --- /dev/null +++ b/libcxx/test/std/utilities/utility/mem.res/mem.res.monotonic.buffer/mem.res.monotonic.buffer.mem/release_reset_initial_status.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +// REQUIRES: std-at-least-c++17 +// UNSUPPORTED: availability-pmr-missing + +// + +// class monotonic_buffer_resource + +#include +#include + +#include "count_new.h" +#include "test_macros.h" + +int main(int, char**) { + { + { + // When ctor with a next buffer size. After release(), check whether the next buffer size has been reset after release() + constexpr size_t expect_next_buffer_size = 512; + std::pmr::monotonic_buffer_resource mr{nullptr, expect_next_buffer_size, std::pmr::new_delete_resource()}; + + for (int i = 0; i < 100; ++i) { + (void)mr.allocate(1); + mr.release(); + ASSERT_WITH_LIBRARY_INTERNAL_ALLOCATIONS(globalMemCounter.checkLastNewSizeGe(expect_next_buffer_size)); + } + } + { + // Check whether the offset of the initial buffer has been reset after release() + constexpr size_t buffer_size = 100; + char buffer[buffer_size]; + std::pmr::monotonic_buffer_resource mr{buffer, buffer_size, std::pmr::null_memory_resource()}; + + mr.release(); + auto expect_mem_start = mr.allocate(60); + mr.release(); + auto ths_mem_start = mr.allocate(60); + assert(expect_mem_start == ths_mem_start); + } + } + return 0; +} From ab42706dc55d180213aad5f9555690e19baf65d2 Mon Sep 17 00:00:00 2001 From: Louis Dionne Date: Tue, 25 Mar 2025 20:23:50 -0400 Subject: [PATCH 2/2] Update libcxx/test/std/utilities/utility/mem.res/mem.res.monotonic.buffer/mem.res.monotonic.buffer.mem/release_reset_initial_status.pass.cpp --- .../release_reset_initial_status.pass.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libcxx/test/std/utilities/utility/mem.res/mem.res.monotonic.buffer/mem.res.monotonic.buffer.mem/release_reset_initial_status.pass.cpp b/libcxx/test/std/utilities/utility/mem.res/mem.res.monotonic.buffer/mem.res.monotonic.buffer.mem/release_reset_initial_status.pass.cpp index 765a5a8f0326d..61406f1d5ffe5 100644 --- a/libcxx/test/std/utilities/utility/mem.res/mem.res.monotonic.buffer/mem.res.monotonic.buffer.mem/release_reset_initial_status.pass.cpp +++ b/libcxx/test/std/utilities/utility/mem.res/mem.res.monotonic.buffer/mem.res.monotonic.buffer.mem/release_reset_initial_status.pass.cpp @@ -13,6 +13,8 @@ // class monotonic_buffer_resource +// This test checks the behavior required by LWG3120. + #include #include