[llvm] WordPos should be less than BITWORDS_PER_ELEMENT (PR #142959)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 5 05:59:17 PDT 2025


https://github.com/SwayamInSync created https://github.com/llvm/llvm-project/pull/142959

Bits is declared as:
```
BitWord Bits[BITWORDS_PER_ELEMENT];
```
The change modifies an assert condition to ensure that `WordPos` is strictly less than `BITWORDS_PER_ELEMENT` rather than less than or equal to it.

>From 615b141cc63bcd4dba5b2e2ba9ccade4379595b7 Mon Sep 17 00:00:00 2001
From: Swayam <74960567+SwayamInSync at users.noreply.github.com>
Date: Thu, 5 Jun 2025 18:19:21 +0530
Subject: [PATCH] WordPos should be less than BITWORDS_PER_ELEMENT

---
 llvm/include/llvm/ADT/SparseBitVector.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/include/llvm/ADT/SparseBitVector.h b/llvm/include/llvm/ADT/SparseBitVector.h
index 7151af6146e6e..3fec695c6e461 100644
--- a/llvm/include/llvm/ADT/SparseBitVector.h
+++ b/llvm/include/llvm/ADT/SparseBitVector.h
@@ -152,7 +152,7 @@ template <unsigned ElementSize = 128> struct SparseBitVectorElement {
     unsigned WordPos = Curr / BITWORD_SIZE;
     unsigned BitPos = Curr % BITWORD_SIZE;
     BitWord Copy = Bits[WordPos];
-    assert(WordPos <= BITWORDS_PER_ELEMENT
+    assert(WordPos < BITWORDS_PER_ELEMENT
            && "Word Position outside of element");
 
     // Mask off previous bits.



More information about the llvm-commits mailing list