[llvm] [ADT] Tighten static_assert in Bitfields (PR #165099)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 25 07:51:52 PDT 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/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.
>From 7461b47753643ac3cbcc740b4764a3546f0a5c87 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
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 <typename Bitfield, typename StorageType> 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<StorageType>(Bitfield::Bits);
static constexpr StorageType Mask = LowMask << Bitfield::Shift;
More information about the llvm-commits
mailing list