[libc-commits] [libc] 8ea6b73 - [libc] Fix alignment issue for HermeticTestUtils.cpp. (#128426)
via libc-commits
libc-commits at lists.llvm.org
Sun Feb 23 10:41:55 PST 2025
Author: lntue
Date: 2025-02-23T13:41:51-05:00
New Revision: 8ea6b735a64da7d97a556832209c0bb70ea00a21
URL: https://github.com/llvm/llvm-project/commit/8ea6b735a64da7d97a556832209c0bb70ea00a21
DIFF: https://github.com/llvm/llvm-project/commit/8ea6b735a64da7d97a556832209c0bb70ea00a21.diff
LOG: [libc] Fix alignment issue for HermeticTestUtils.cpp. (#128426)
Full build precommit bots were failing due to mis-alignment of atomics
in hermetic tests. This PR enforces the alignment for the bump allocator
of hermetic test framework.
Fixes https://github.com/llvm/llvm-project/issues/128185.
Added:
Modified:
libc/test/UnitTest/HermeticTestUtils.cpp
Removed:
################################################################################
diff --git a/libc/test/UnitTest/HermeticTestUtils.cpp b/libc/test/UnitTest/HermeticTestUtils.cpp
index 47f813b0b7a4e..a9494af746d52 100644
--- a/libc/test/UnitTest/HermeticTestUtils.cpp
+++ b/libc/test/UnitTest/HermeticTestUtils.cpp
@@ -33,6 +33,8 @@ int atexit(void (*func)(void));
} // namespace LIBC_NAMESPACE_DECL
+constexpr uint64_t ALIGNMENT = alignof(uintptr_t);
+
namespace {
// Integration tests cannot use the SCUDO standalone allocator as SCUDO pulls
@@ -42,7 +44,7 @@ namespace {
// which just hands out continuous blocks from a statically allocated chunk of
// memory.
static constexpr uint64_t MEMORY_SIZE = 65336;
-static uint8_t memory[MEMORY_SIZE];
+alignas(ALIGNMENT) static uint8_t memory[MEMORY_SIZE];
static uint8_t *ptr = memory;
} // anonymous namespace
@@ -74,8 +76,6 @@ 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 LIBC_NAMESPACE::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;
More information about the libc-commits
mailing list