[libc-commits] [libc] [libc][malloc] Ensure a minimum block alignment of 4 (PR #169447)
via libc-commits
libc-commits at lists.llvm.org
Mon Nov 24 19:12:50 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Daniel Thornburgh (mysterymath)
<details>
<summary>Changes</summary>
Most platforms inherently have a size_t alignment of 4, but this isn't true on every platform LLVM has some degree of backend support for. Accordingly, it's simple enough to just set the min alignment of Block to 4 and lose the static_assert.
---
Full diff: https://github.com/llvm/llvm-project/pull/169447.diff
1 Files Affected:
- (modified) libc/src/__support/block.h (+4-4)
``````````diff
diff --git a/libc/src/__support/block.h b/libc/src/__support/block.h
index b0d6576093244..faab409166c6e 100644
--- a/libc/src/__support/block.h
+++ b/libc/src/__support/block.h
@@ -90,7 +90,10 @@ using cpp::optional;
///
/// The next offset of a block matches the previous offset of its next block.
/// The first block in a list is denoted by having a previous offset of `0`.
-class Block {
+///
+// Ensure a minimum alignment of 4, since at least 2 bits must be available in
+// block sizes for flags.
+class alignas(cpp::max(alignof(size_t), size_t{4})) Block {
// Masks for the contents of the next_ field.
static constexpr size_t PREV_FREE_MASK = 1 << 0;
static constexpr size_t LAST_MASK = 1 << 1;
@@ -360,9 +363,6 @@ class Block {
static constexpr size_t PREV_FIELD_SIZE = sizeof(prev_);
};
-static_assert(alignof(Block) >= 4,
- "at least 2 bits must be available in block sizes for flags");
-
LIBC_INLINE
optional<Block *> Block::init(ByteSpan region) {
if (!region.data())
``````````
</details>
https://github.com/llvm/llvm-project/pull/169447
More information about the libc-commits
mailing list