diff options
author | Joseph Huber <jhuber6@vols.utk.edu> | 2023-05-04 11:22:38 -0500 |
---|---|---|
committer | Joseph Huber <jhuber6@vols.utk.edu> | 2023-05-04 13:22:20 -0500 |
commit | cbcf55d32b62aad9b516cd201de73cb13fbda030 (patch) | |
tree | e36fa129673ec06164ad15e2d4ec771aae97dc20 /libc/test | |
parent | 5337cd897fecf52f6d4ca45f85e9b68bc48af2c9 (diff) | |
download | llvm-cbcf55d32b62aad9b516cd201de73cb13fbda030.tar.gz |
[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
Diffstat (limited to 'libc/test')
-rw-r--r-- | libc/test/UnitTest/HermeticTestUtils.cpp | 4 | ||||
-rw-r--r-- | libc/test/src/__support/CMakeLists.txt | 21 |
2 files changed, 13 insertions, 12 deletions
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 |