[libc-commits] [libc] [libc] Fix alignment issue for HermeticTestUtils.cpp. (PR #128426)

via libc-commits libc-commits at lists.llvm.org
Sun Feb 23 09:18:23 PST 2025


https://github.com/lntue updated https://github.com/llvm/llvm-project/pull/128426

>From a9a60907a06f727eb14f37864fc5d1614c9360ba Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue.h at gmail.com>
Date: Sun, 23 Feb 2025 17:06:25 +0000
Subject: [PATCH 1/2] [libc] Fix alignment issue for HermeticTestUtils.cpp.

---
 libc/test/UnitTest/HermeticTestUtils.cpp | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/libc/test/UnitTest/HermeticTestUtils.cpp b/libc/test/UnitTest/HermeticTestUtils.cpp
index 47f813b0b7a4e..343b622fd4f30 100644
--- a/libc/test/UnitTest/HermeticTestUtils.cpp
+++ b/libc/test/UnitTest/HermeticTestUtils.cpp
@@ -33,6 +33,10 @@ int atexit(void (*func)(void));
 
 } // namespace LIBC_NAMESPACE_DECL
 
+extern "C" {
+constexpr uint64_t ALIGNMENT = alignof(uintptr_t);
+}
+
 namespace {
 
 // Integration tests cannot use the SCUDO standalone allocator as SCUDO pulls
@@ -42,7 +46,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 +78,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;

>From dd66bf95763413fab2f90148246e3c84d3fcf6a1 Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue.h at gmail.com>
Date: Sun, 23 Feb 2025 17:17:44 +0000
Subject: [PATCH 2/2] Remove extern "C".

---
 libc/test/UnitTest/HermeticTestUtils.cpp | 2 --
 1 file changed, 2 deletions(-)

diff --git a/libc/test/UnitTest/HermeticTestUtils.cpp b/libc/test/UnitTest/HermeticTestUtils.cpp
index 343b622fd4f30..a9494af746d52 100644
--- a/libc/test/UnitTest/HermeticTestUtils.cpp
+++ b/libc/test/UnitTest/HermeticTestUtils.cpp
@@ -33,9 +33,7 @@ int atexit(void (*func)(void));
 
 } // namespace LIBC_NAMESPACE_DECL
 
-extern "C" {
 constexpr uint64_t ALIGNMENT = alignof(uintptr_t);
-}
 
 namespace {
 



More information about the libc-commits mailing list