Skip to content

Commit 5db2867

Browse files
committed
[libc] Fix malloc riscv32 test failures from #117815
1 parent 8b0c774 commit 5db2867

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

libc/test/src/__support/block_test.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,11 @@ TEST(LlvmLibcBlockTest, CannotCreateTooSmallBlock) {
7575

7676
TEST(LlvmLibcBlockTest, CanSplitBlock) {
7777
constexpr size_t kN = 1024;
78-
// Give the split position a large alignment.
79-
constexpr size_t kSplitN = 512 + Block::PREV_FIELD_SIZE;
78+
79+
// Choose a split position such that the next block's usable space is 512
80+
// bytes from this one's. This should be sufficient for any machine's
81+
// alignment.
82+
const size_t kSplitN = Block::inner_size(512);
8083

8184
array<byte, kN> bytes;
8285
auto result = Block::init(bytes);

libc/test/src/__support/freestore_test.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ TEST(LlvmLibcFreeStore, TooSmall) {
2626
Block *too_small = *maybeBlock;
2727
maybeBlock = too_small->split(Block::PREV_FIELD_SIZE);
2828
ASSERT_TRUE(maybeBlock.has_value());
29+
// On platforms with high alignment the smallest legal block may be large
30+
// enough for a node.
31+
if (too_small->outer_size() > sizeof(Block) + sizeof(FreeList::Node))
32+
return;
2933
Block *remainder = *maybeBlock;
3034

3135
FreeStore store;

0 commit comments

Comments
 (0)