[libc-commits] [libc] 5db2867 - [libc] Fix malloc riscv32 test failures from #117815

Daniel Thornburgh via libc-commits libc-commits at lists.llvm.org
Fri Jan 17 13:07:52 PST 2025


Author: Daniel Thornburgh
Date: 2025-01-17T13:07:46-08:00
New Revision: 5db28679da38bee65feb55b803a23aceee568f44

URL: https://github.com/llvm/llvm-project/commit/5db28679da38bee65feb55b803a23aceee568f44
DIFF: https://github.com/llvm/llvm-project/commit/5db28679da38bee65feb55b803a23aceee568f44.diff

LOG: [libc] Fix malloc riscv32 test failures from #117815

Added: 
    

Modified: 
    libc/test/src/__support/block_test.cpp
    libc/test/src/__support/freestore_test.cpp

Removed: 
    


################################################################################
diff  --git a/libc/test/src/__support/block_test.cpp b/libc/test/src/__support/block_test.cpp
index c2d9833fb94391..904ac5c66994d8 100644
--- a/libc/test/src/__support/block_test.cpp
+++ b/libc/test/src/__support/block_test.cpp
@@ -75,8 +75,11 @@ TEST(LlvmLibcBlockTest, CannotCreateTooSmallBlock) {
 
 TEST(LlvmLibcBlockTest, CanSplitBlock) {
   constexpr size_t kN = 1024;
-  // Give the split position a large alignment.
-  constexpr size_t kSplitN = 512 + Block::PREV_FIELD_SIZE;
+
+  // Choose a split position such that the next block's usable space is 512
+  // bytes from this one's. This should be sufficient for any machine's
+  // alignment.
+  const size_t kSplitN = Block::inner_size(512);
 
   array<byte, kN> bytes;
   auto result = Block::init(bytes);

diff  --git a/libc/test/src/__support/freestore_test.cpp b/libc/test/src/__support/freestore_test.cpp
index a32badb39b1e6f..468f0033aedc10 100644
--- a/libc/test/src/__support/freestore_test.cpp
+++ b/libc/test/src/__support/freestore_test.cpp
@@ -26,6 +26,10 @@ TEST(LlvmLibcFreeStore, TooSmall) {
   Block *too_small = *maybeBlock;
   maybeBlock = too_small->split(Block::PREV_FIELD_SIZE);
   ASSERT_TRUE(maybeBlock.has_value());
+  // On platforms with high alignment the smallest legal block may be large
+  // enough for a node.
+  if (too_small->outer_size() > sizeof(Block) + sizeof(FreeList::Node))
+    return;
   Block *remainder = *maybeBlock;
 
   FreeStore store;


        


More information about the libc-commits mailing list