[libc-commits] [libc] cbcf55d - [libc] Maintain proper alignment for the hermetic tests malloc
Joseph Huber via libc-commits
libc-commits at lists.llvm.org
Thu May 4 11:22:28 PDT 2023
Author: Joseph Huber
Date: 2023-05-04T13:22:20-05:00
New Revision: cbcf55d32b62aad9b516cd201de73cb13fbda030
URL: https://github.com/llvm/llvm-project/commit/cbcf55d32b62aad9b516cd201de73cb13fbda030
DIFF: https://github.com/llvm/llvm-project/commit/cbcf55d32b62aad9b516cd201de73cb13fbda030.diff
LOG: [libc] Maintain proper alignment for the hermetic tests malloc
We use a bump pointer to implement malloc for the hermetic tests.
Currently, we bump the pointer up by any amount. This means that calling
`malloc(1)` will misalign the buffer so any following `malloc(8)`
accesses will not be aligned. This causes problems in architectures
which require alignment.
Reviewed By: sivachandra
Differential Revision: https://reviews.llvm.org/D149863
Added:
Modified:
libc/test/UnitTest/HermeticTestUtils.cpp
libc/test/src/__support/CMakeLists.txt
Removed:
################################################################################
diff --git a/libc/test/UnitTest/HermeticTestUtils.cpp b/libc/test/UnitTest/HermeticTestUtils.cpp
index 32e0044a4ee4..c8279e54e15d 100644
--- a/libc/test/UnitTest/HermeticTestUtils.cpp
+++ b/libc/test/UnitTest/HermeticTestUtils.cpp
@@ -61,7 +61,11 @@ void *memset(void *ptr, int value, size_t count) {
// This is needed if the test was compiled with '-fno-use-cxa-atexit'.
int atexit(void (*func)(void)) { return __llvm_libc::atexit(func); }
+constexpr uint64_t ALIGNMENT = alignof(uintptr_t);
+
void *malloc(size_t s) {
+ // Keep the bump pointer aligned on an eight byte boundary.
+ s = ((s + ALIGNMENT - 1) / ALIGNMENT) * ALIGNMENT;
void *mem = ptr;
ptr += s;
return mem;
diff --git a/libc/test/src/__support/CMakeLists.txt b/libc/test/src/__support/CMakeLists.txt
index f0192c24b300..7390ed2471f7 100644
--- a/libc/test/src/__support/CMakeLists.txt
+++ b/libc/test/src/__support/CMakeLists.txt
@@ -1,17 +1,14 @@
add_custom_target(libc-support-tests)
-# This test fails with a misaigned address on NVPTX.
-if(NOT LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX)
- add_libc_test(
- blockstore_test
- SUITE
- libc-support-tests
- SRCS
- blockstore_test.cpp
- DEPENDS
- libc.src.__support.blockstore
- )
-endif()
+add_libc_test(
+ blockstore_test
+ SUITE
+ libc-support-tests
+ SRCS
+ blockstore_test.cpp
+ DEPENDS
+ libc.src.__support.blockstore
+)
add_libc_test(
endian_test
More information about the libc-commits
mailing list