Skip to content

Commit 8ea6b73

Browse files
authored
[libc] Fix alignment issue for HermeticTestUtils.cpp. (llvm#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 llvm#128185.
1 parent 65e44b4 commit 8ea6b73

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

libc/test/UnitTest/HermeticTestUtils.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ int atexit(void (*func)(void));
3333

3434
} // namespace LIBC_NAMESPACE_DECL
3535

36+
constexpr uint64_t ALIGNMENT = alignof(uintptr_t);
37+
3638
namespace {
3739

3840
// Integration tests cannot use the SCUDO standalone allocator as SCUDO pulls
@@ -42,7 +44,7 @@ namespace {
4244
// which just hands out continuous blocks from a statically allocated chunk of
4345
// memory.
4446
static constexpr uint64_t MEMORY_SIZE = 65336;
45-
static uint8_t memory[MEMORY_SIZE];
47+
alignas(ALIGNMENT) static uint8_t memory[MEMORY_SIZE];
4648
static uint8_t *ptr = memory;
4749

4850
} // anonymous namespace
@@ -74,8 +76,6 @@ void *memset(void *ptr, int value, size_t count) {
7476
// This is needed if the test was compiled with '-fno-use-cxa-atexit'.
7577
int atexit(void (*func)(void)) { return LIBC_NAMESPACE::atexit(func); }
7678

77-
constexpr uint64_t ALIGNMENT = alignof(uintptr_t);
78-
7979
void *malloc(size_t s) {
8080
// Keep the bump pointer aligned on an eight byte boundary.
8181
s = ((s + ALIGNMENT - 1) / ALIGNMENT) * ALIGNMENT;

0 commit comments

Comments
 (0)