Skip to content

Commit 7b9cf0f

Browse files
[ADT] Tighten static_assert in Bitfields (#165099)
This patch tightens the static_assert. FirstBit and LastBit are 0-based bit indices of a bitfield, so they must be strictly less than StorageBits.
1 parent 5113ca0 commit 7b9cf0f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

llvm/include/llvm/ADT/Bitfields.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ template <typename Bitfield, typename StorageType> struct Impl {
100100
using IntegerType = typename Bitfield::IntegerType;
101101

102102
static constexpr size_t StorageBits = sizeof(StorageType) * CHAR_BIT;
103-
static_assert(Bitfield::FirstBit <= StorageBits, "Data must fit in mask");
104-
static_assert(Bitfield::LastBit <= StorageBits, "Data must fit in mask");
103+
static_assert(Bitfield::FirstBit < StorageBits, "Data must fit in mask");
104+
static_assert(Bitfield::LastBit < StorageBits, "Data must fit in mask");
105105
static constexpr StorageType LowMask =
106106
maskTrailingOnes<StorageType>(Bitfield::Bits);
107107
static constexpr StorageType Mask = LowMask << Bitfield::Shift;

0 commit comments

Comments
 (0)