From 44da8d612670f97633a5c2832f2ef037c508af9b Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Thu, 26 Sep 2024 23:09:25 -0700 Subject: [PATCH 1/6] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?= =?UTF-8?q?itial=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created using spr 1.3.4 --- .../string.capacity/deallocate_size.pass.cpp | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 libcxx/test/std/strings/basic.string/string.capacity/deallocate_size.pass.cpp diff --git a/libcxx/test/std/strings/basic.string/string.capacity/deallocate_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/deallocate_size.pass.cpp new file mode 100644 index 0000000000000..612b66195141c --- /dev/null +++ b/libcxx/test/std/strings/basic.string/string.capacity/deallocate_size.pass.cpp @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +// + +// allocate/deallocate must match. + +#include +#include +#include + +#include "test_macros.h" + +static int allocated_; + +template +struct test_alloc { + typedef Sz size_type; + typedef std::make_signed::type difference_type; + typedef T value_type; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef typename std::add_lvalue_reference::type reference; + typedef typename std::add_lvalue_reference::type const_reference; + + template + struct rebind { + typedef test_alloc other; + }; + + TEST_CONSTEXPR_CXX14 pointer allocate(size_type n, const void* = nullptr) { + allocated_ += n; + return std::allocator().allocate(n); + } + + TEST_CONSTEXPR_CXX14 void deallocate(pointer p, size_type s) { + allocated_ -= s; + std::allocator().deallocate(p, s); + } +}; + +template +void test() { + for (int i = 1; i < 1000; ++i) { + using Str = std::basic_string, test_alloc >; + { + Str s(i, 't'); + assert(allocated_ == 0 || allocated_ >= i); + } + } + assert(allocated_ == 0); +} + +int main(int, char**) { + test(); + test(); + test(); +} From efa9c509ff48bb71b809b00f6371321730db839b Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Thu, 26 Sep 2024 23:29:10 -0700 Subject: [PATCH 2/6] typename Created using spr 1.3.4 --- .../basic.string/string.capacity/deallocate_size.pass.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libcxx/test/std/strings/basic.string/string.capacity/deallocate_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/deallocate_size.pass.cpp index 612b66195141c..ad45aafc8832c 100644 --- a/libcxx/test/std/strings/basic.string/string.capacity/deallocate_size.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.capacity/deallocate_size.pass.cpp @@ -21,7 +21,7 @@ static int allocated_; template struct test_alloc { typedef Sz size_type; - typedef std::make_signed::type difference_type; + typedef typename std::make_signed::type difference_type; typedef T value_type; typedef value_type* pointer; typedef const value_type* const_pointer; From 6f9e92671cffb46996b1d30da60232c73c7c7bad Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Thu, 26 Sep 2024 23:49:03 -0700 Subject: [PATCH 3/6] #include Created using spr 1.3.4 --- .../basic.string/string.capacity/deallocate_size.pass.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libcxx/test/std/strings/basic.string/string.capacity/deallocate_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/deallocate_size.pass.cpp index ad45aafc8832c..4536a0514b133 100644 --- a/libcxx/test/std/strings/basic.string/string.capacity/deallocate_size.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.capacity/deallocate_size.pass.cpp @@ -12,6 +12,7 @@ #include #include +#include #include #include "test_macros.h" From dfff4019fcbdf7128dc597ed18a83eb81bf66256 Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Mon, 30 Sep 2024 10:43:40 -0700 Subject: [PATCH 4/6] Update libcxx/test/std/strings/basic.string/string.capacity/deallocate_size.pass.cpp Co-authored-by: Louis Dionne --- .../basic.string/string.capacity/deallocate_size.pass.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libcxx/test/std/strings/basic.string/string.capacity/deallocate_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/deallocate_size.pass.cpp index 4536a0514b133..23a71c8e9044c 100644 --- a/libcxx/test/std/strings/basic.string/string.capacity/deallocate_size.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.capacity/deallocate_size.pass.cpp @@ -61,4 +61,6 @@ int main(int, char**) { test(); test(); test(); + + return 0; } From d9d53b961a6fecfe748c09f1cbfb2c0c9b036665 Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Mon, 30 Sep 2024 10:43:49 -0700 Subject: [PATCH 5/6] Update libcxx/test/std/strings/basic.string/string.capacity/deallocate_size.pass.cpp Co-authored-by: Louis Dionne --- .../basic.string/string.capacity/deallocate_size.pass.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libcxx/test/std/strings/basic.string/string.capacity/deallocate_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/deallocate_size.pass.cpp index 23a71c8e9044c..8556b31fa6274 100644 --- a/libcxx/test/std/strings/basic.string/string.capacity/deallocate_size.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.capacity/deallocate_size.pass.cpp @@ -8,7 +8,7 @@ // -// allocate/deallocate must match. +// Make sure the size we allocate and deallocate match. See https://github.com/llvm/llvm-project/pull/90292. #include #include From 1f4743a23a00504d738c53d51def24266ce70a5e Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Mon, 30 Sep 2024 15:16:10 -0700 Subject: [PATCH 6/6] Update deallocate_size.pass.cpp --- .../basic.string/string.capacity/deallocate_size.pass.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libcxx/test/std/strings/basic.string/string.capacity/deallocate_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/deallocate_size.pass.cpp index 8556b31fa6274..1203b2f3ec18f 100644 --- a/libcxx/test/std/strings/basic.string/string.capacity/deallocate_size.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.capacity/deallocate_size.pass.cpp @@ -61,6 +61,6 @@ int main(int, char**) { test(); test(); test(); - + return 0; }