Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[libc++] Implement P0339R6 (polymorphic_allocator<> as a vocabulary t…
…ype) Reviewed By: ldionne, #libc Spies: LRFLEW, libcxx-commits, arichardson, krytarowski, jdoerfert Differential Revision: https://reviews.llvm.org/D137739
- Loading branch information
1 parent
0f6dbb5
commit 181cce6
Showing
25 changed files
with
397 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...mem.poly.allocator.class/mem.poly.allocator.mem/allocate_vocabulary.attributes.verify.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// UNSUPPORTED: c++03, c++11, c++14, c++17 | ||
|
||
// check that clang warns on non-power-of-two alignment | ||
|
||
#include <memory_resource> | ||
|
||
void func() { | ||
std::pmr::polymorphic_allocator<> allocator; | ||
(void)allocator.allocate_bytes(0, 3); // expected-warning {{requested alignment is not a power of 2}} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...em.res/mem.poly.allocator.class/mem.poly.allocator.mem/allocate_deallocate_bytes.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// UNSUPPORTED: c++03, c++11, c++14, c++17 | ||
// XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11|12|13|14|15}} | ||
// XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx{{11.0|12.0}} | ||
|
||
// test_memory_resource requires RTTI for dynamic_cast | ||
// UNSUPPORTED: no-rtti | ||
|
||
// <memory_resource> | ||
|
||
// polymorphic_allocator::allocate_bytes() | ||
// polymorphic_allocator::deallocate_bytes() | ||
|
||
#include <algorithm> | ||
#include <cassert> | ||
#include <concepts> | ||
#include <memory_resource> | ||
|
||
#include "tracking_mem_res.h" | ||
|
||
template <class T> | ||
void test() { | ||
size_t last_size = 0; | ||
size_t last_alignment = 0; | ||
TrackingMemRes resource(&last_size, &last_alignment); | ||
|
||
std::pmr::polymorphic_allocator<T> allocator(&resource); | ||
|
||
{ | ||
std::same_as<void*> decltype(auto) allocation = allocator.allocate_bytes(13); | ||
auto ptr = static_cast<char*>(allocation); | ||
std::fill(ptr, ptr + 13, '0'); | ||
assert(last_size == 13); | ||
assert(last_alignment == alignof(max_align_t)); | ||
allocator.deallocate_bytes(allocation, 13); | ||
assert(last_size == 13); | ||
assert(last_alignment == alignof(max_align_t)); | ||
} | ||
{ | ||
void* allocation = allocator.allocate_bytes(13, 64); | ||
auto ptr = static_cast<char*>(allocation); | ||
std::fill(ptr, ptr + 13, '0'); | ||
assert(last_size == 13); | ||
assert(last_alignment == 64); | ||
allocator.deallocate_bytes(allocation, 13, 64); | ||
assert(last_size == 13); | ||
assert(last_alignment == 64); | ||
} | ||
} | ||
|
||
struct S {}; | ||
|
||
int main(int, char**) { | ||
test<std::byte>(); | ||
test<S>(); | ||
|
||
return 0; | ||
} |
Oops, something went wrong.