[llvm-commits] [llvm] r166015 - in /llvm/trunk: include/llvm/ADT/BitVector.h unittests/ADT/BitVectorTest.cpp
Owen Anderson
resistor at mac.com
Mon Oct 15 23:04:27 PDT 2012
Author: resistor
Date: Tue Oct 16 01:04:27 2012
New Revision: 166015
URL: http://llvm.org/viewvc/llvm-project?rev=166015&view=rev
Log:
Fix a bug in the set(I,E)/reset(I,E) methods that I recently added. The boundary condition for checking if I and E were in the same word were incorrect, and, beyond that, the mask computation was not using a wide enough constant.
Modified:
llvm/trunk/include/llvm/ADT/BitVector.h
llvm/trunk/unittests/ADT/BitVectorTest.cpp
Modified: llvm/trunk/include/llvm/ADT/BitVector.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/BitVector.h?rev=166015&r1=166014&r2=166015&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/BitVector.h (original)
+++ llvm/trunk/include/llvm/ADT/BitVector.h Tue Oct 16 01:04:27 2012
@@ -244,9 +244,9 @@
if (I == E) return *this;
- if (I / BITWORD_SIZE == (E-1) / BITWORD_SIZE) {
- BitWord EMask = 1 << (E % BITWORD_SIZE);
- BitWord IMask = 1 << (I % BITWORD_SIZE);
+ if (I / BITWORD_SIZE == E / BITWORD_SIZE) {
+ BitWord EMask = 1UL << (E % BITWORD_SIZE);
+ BitWord IMask = 1UL << (I % BITWORD_SIZE);
BitWord Mask = EMask - IMask;
Bits[I / BITWORD_SIZE] |= Mask;
return *this;
@@ -282,9 +282,9 @@
if (I == E) return *this;
- if (I / BITWORD_SIZE == (E-1) / BITWORD_SIZE) {
- BitWord EMask = 1 << (E % BITWORD_SIZE);
- BitWord IMask = 1 << (I % BITWORD_SIZE);
+ if (I / BITWORD_SIZE == E / BITWORD_SIZE) {
+ BitWord EMask = 1UL << (E % BITWORD_SIZE);
+ BitWord IMask = 1UL << (I % BITWORD_SIZE);
BitWord Mask = EMask - IMask;
Bits[I / BITWORD_SIZE] &= ~Mask;
return *this;
Modified: llvm/trunk/unittests/ADT/BitVectorTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/BitVectorTest.cpp?rev=166015&r1=166014&r2=166015&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/BitVectorTest.cpp (original)
+++ llvm/trunk/unittests/ADT/BitVectorTest.cpp Tue Oct 16 01:04:27 2012
@@ -322,6 +322,16 @@
EXPECT_FALSE(D.test(0));
EXPECT_TRUE( D.test(1));
EXPECT_TRUE( D.test(2));
+
+ TypeParam E;
+ E.resize(128);
+ E.reset();
+ E.set(1, 33);
+
+ EXPECT_FALSE(E.test(0));
+ EXPECT_TRUE( E.test(1));
+ EXPECT_TRUE( E.test(32));
+ EXPECT_FALSE(E.test(33));
}
}
#endif
More information about the llvm-commits
mailing list