[libc-commits] [libc] [libc] Fix malloc Block alignment issue on riscv32 (PR #117815)
Nick Desaulniers via libc-commits
libc-commits at lists.llvm.org
Fri Jan 17 10:23:24 PST 2025
================
@@ -186,11 +174,19 @@ class Block {
}
/// @returns A pointer to the usable space inside this block.
+ ///
+ /// Aligned to some multiple of max_align_t.
LIBC_INLINE cpp::byte *usable_space() {
- return reinterpret_cast<cpp::byte *>(this) + BLOCK_OVERHEAD;
+ auto *s = reinterpret_cast<cpp::byte *>(this) + BLOCK_OVERHEAD;
+ LIBC_ASSERT(reinterpret_cast<uintptr_t>(s) % alignof(max_align_t) == 0 &&
+ "usable space must be aligned to a multiple of max_align_t");
+ return s;
}
LIBC_INLINE const cpp::byte *usable_space() const {
- return reinterpret_cast<const cpp::byte *>(this) + BLOCK_OVERHEAD;
+ const auto *s = reinterpret_cast<const cpp::byte *>(this) + BLOCK_OVERHEAD;
+ LIBC_ASSERT(reinterpret_cast<uintptr_t>(s) % alignof(max_align_t) == 0 &&
+ "usable space must be aligned to a multiple of max_align_t");
----------------
nickdesaulniers wrote:
```
llvm-project/libc/src/__support/block.h:188: Assertion failed: 'reinterpret_cast<uintptr_t>(s) % alignof(max_align_t) == 0 && "usable space must be aligned to a multiple of max_align_t"' in function: 'const cpp::byte *__llvm_libc_20_0_0_git::Block::usable_space() const'
```
https://github.com/llvm/llvm-project/pull/117815
More information about the libc-commits
mailing list