Skip to content

Commit 343fba4

Browse files
committed
Fixes
1 parent af14cc4 commit 343fba4

File tree

5 files changed

+41
-60
lines changed

5 files changed

+41
-60
lines changed

libc/config/baremetal/aarch64/entrypoints.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ set(TARGET_LIBC_ENTRYPOINTS
182182
libc.src.stdlib.div
183183
libc.src.stdlib.exit
184184
libc.src.stdlib.free
185-
libc.src.stdlib.freelist_malloc
186185
libc.src.stdlib.labs
187186
libc.src.stdlib.ldiv
188187
libc.src.stdlib.llabs

libc/src/__support/CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ add_object_library(
5454
freelist_heap.cpp
5555
HDRS
5656
freelist_heap.h
57+
COMPILE_OPTIONS
58+
-DLIBC_FREELIST_MALLOC_SIZE=${LIBC_CONF_FREELIST_MALLOC_BUFFER_SIZE}
5759
DEPENDS
5860
.block
5961
.freelist
@@ -66,9 +68,6 @@ add_object_library(
6668
libc.src.__support.libc_assert
6769
libc.src.string.memory_utils.inline_memcpy
6870
libc.src.string.memory_utils.inline_memset
69-
COMPILE_OPTIONS
70-
-DLIBC_FREELIST_MALLOC_SIZE=${LIBC_CONF_FREELIST_MALLOC_BUFFER_SIZE}
71-
7271
)
7372

7473
add_header_library(

libc/test/src/__support/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,13 @@ if(LLVM_LIBC_FULL_BUILD)
6363
SRCS
6464
fake_heap.s
6565
freelist_heap_test.cpp
66-
freelist_malloc_test.cpp
6766
DEPENDS
6867
libc.src.__support.CPP.span
6968
libc.src.__support.freelist_heap
70-
libc.src.stdlib.freelist_malloc
69+
libc.src.stdlib.aligned_alloc
70+
libc.src.stdlib.calloc
71+
libc.src.stdlib.free
72+
libc.src.stdlib.malloc
7173
libc.src.string.memcmp
7274
libc.src.string.memcpy
7375
)

libc/test/src/__support/freelist_heap_test.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,3 +288,38 @@ TEST_FOR_EACH_ALLOCATOR(InvalidAlignedAllocAlignment, 2048) {
288288
ptr = allocator.aligned_allocate(0, 8);
289289
EXPECT_EQ(ptr, static_cast<void *>(nullptr));
290290
}
291+
292+
TEST(LlvmLibcFreeListHeap, Malloc) {
293+
constexpr size_t kAllocSize = 256;
294+
constexpr size_t kCallocNum = 4;
295+
constexpr size_t kCallocSize = 64;
296+
297+
void *ptr1 = LIBC_NAMESPACE::malloc(kAllocSize);
298+
auto *block = Block::from_usable_space(ptr1);
299+
EXPECT_GE(block->inner_size(), kAllocSize);
300+
301+
LIBC_NAMESPACE::free(ptr1);
302+
ASSERT_NE(block->next(), static_cast<Block *>(nullptr));
303+
ASSERT_EQ(block->next()->next(), static_cast<Block *>(nullptr));
304+
size_t heap_size = block->inner_size();
305+
306+
void *ptr2 = LIBC_NAMESPACE::calloc(kCallocNum, kCallocSize);
307+
ASSERT_EQ(ptr2, ptr1);
308+
EXPECT_GE(block->inner_size(), kCallocNum * kCallocSize);
309+
310+
for (size_t i = 0; i < kCallocNum * kCallocSize; ++i)
311+
EXPECT_EQ(reinterpret_cast<uint8_t *>(ptr2)[i], uint8_t(0));
312+
313+
LIBC_NAMESPACE::free(ptr2);
314+
EXPECT_EQ(block->inner_size(), heap_size);
315+
316+
constexpr size_t ALIGN = kAllocSize;
317+
void *ptr3 = LIBC_NAMESPACE::aligned_alloc(ALIGN, kAllocSize);
318+
EXPECT_NE(ptr3, static_cast<void *>(nullptr));
319+
EXPECT_EQ(reinterpret_cast<uintptr_t>(ptr3) % ALIGN, size_t(0));
320+
auto *aligned_block = reinterpret_cast<Block *>(ptr3);
321+
EXPECT_GE(aligned_block->inner_size(), kAllocSize);
322+
323+
LIBC_NAMESPACE::free(ptr3);
324+
EXPECT_EQ(block->inner_size(), heap_size);
325+
}

libc/test/src/__support/freelist_malloc_test.cpp

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)