Skip to content

Commit d74bdfa

Browse files
committed
[libc][malloc] Ensure a minimum block alignment of 4
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.
1 parent a27bb38 commit d74bdfa

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

libc/src/__support/block.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ using cpp::optional;
9090
///
9191
/// The next offset of a block matches the previous offset of its next block.
9292
/// The first block in a list is denoted by having a previous offset of `0`.
93-
class Block {
93+
///
94+
// Ensure a minimum alignment of 4, since at least 2 bits must be available in
95+
// block sizes for flags.
96+
class alignas(cpp::max(alignof(size_t), size_t{4})) Block {
9497
// Masks for the contents of the next_ field.
9598
static constexpr size_t PREV_FREE_MASK = 1 << 0;
9699
static constexpr size_t LAST_MASK = 1 << 1;
@@ -360,9 +363,6 @@ class Block {
360363
static constexpr size_t PREV_FIELD_SIZE = sizeof(prev_);
361364
};
362365

363-
static_assert(alignof(Block) >= 4,
364-
"at least 2 bits must be available in block sizes for flags");
365-
366366
LIBC_INLINE
367367
optional<Block *> Block::init(ByteSpan region) {
368368
if (!region.data())

0 commit comments

Comments
 (0)