From 7461b47753643ac3cbcc740b4764a3546f0a5c87 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Mon, 13 Oct 2025 09:44:09 -0700 Subject: [PATCH] [ADT] Tighten static_assert in Bitfields 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. --- llvm/include/llvm/ADT/Bitfields.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llvm/include/llvm/ADT/Bitfields.h b/llvm/include/llvm/ADT/Bitfields.h index 1fbc41c472581..be9546e9cc4cb 100644 --- a/llvm/include/llvm/ADT/Bitfields.h +++ b/llvm/include/llvm/ADT/Bitfields.h @@ -100,8 +100,8 @@ template struct Impl { using IntegerType = typename Bitfield::IntegerType; static constexpr size_t StorageBits = sizeof(StorageType) * CHAR_BIT; - static_assert(Bitfield::FirstBit <= StorageBits, "Data must fit in mask"); - static_assert(Bitfield::LastBit <= StorageBits, "Data must fit in mask"); + static_assert(Bitfield::FirstBit < StorageBits, "Data must fit in mask"); + static_assert(Bitfield::LastBit < StorageBits, "Data must fit in mask"); static constexpr StorageType LowMask = maskTrailingOnes(Bitfield::Bits); static constexpr StorageType Mask = LowMask << Bitfield::Shift;