[libc-commits] [libc] [libc] Add aligned_alloc (PR #96586)
Nick Desaulniers via libc-commits
libc-commits at lists.llvm.org
Tue Jun 25 09:02:00 PDT 2024
================
@@ -567,3 +569,201 @@ TEST_FOR_EACH_BLOCK_TYPE(CanGetConstBlockFromUsableSpace) {
const BlockType *block2 = BlockType::from_usable_space(ptr);
EXPECT_EQ(block1, block2);
}
+
+TEST_FOR_EACH_BLOCK_TYPE(CanAllocate) {
+ constexpr size_t kN = 1024;
+
+ // Ensure we can allocate everything up to the block size within this block.
+ for (size_t i = 0; i < kN - BlockType::BLOCK_OVERHEAD; ++i) {
+ alignas(BlockType::ALIGNMENT) array<byte, kN> bytes{};
+ auto result = BlockType::init(bytes);
+ ASSERT_TRUE(result.has_value());
+ BlockType *block = *result;
+
+ constexpr size_t kAlign = 1; // Effectively ignores alignmenr.
----------------
nickdesaulniers wrote:
```suggestion
constexpr size_t kAlign = 1; // Effectively ignores alignment.
```
https://github.com/llvm/llvm-project/pull/96586
More information about the libc-commits
mailing list