llvm.org GIT mirror llvm / 9b4b520
[SmallBitVector] Fix bug in find_next_unset for small types with indices >=32 We were creating a bitmask from a shift of unsigned instead of uintptr_t, meaning we couldn't create masks for indices above 31. Noticed due to a MSVC analyzer warning. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@366657 91177308-0d34-0410-b5e6-96231b3b80d8 Simon Pilgrim 29 days ago
2 changed file(s) with 33 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
289289 ++Prev;
290290 uintptr_t Bits = getSmallBits();
291291 // Mask in previous bits.
292 uintptr_t Mask = (1 << Prev) - 1;
292 uintptr_t Mask = (uintptr_t(1) << Prev) - 1;
293293 Bits |= Mask;
294294
295295 if (Bits == ~uintptr_t(0) || Prev + 1 >= getSmallSize())
227227 EXPECT_EQ(99, A.find_next_unset(98));
228228 }
229229
230 // Test finding next set and unset bits in a BitVector/SmallBitVector within a
231 // uintptr_t - check both 32-bit (Multi) and 64-bit (Small) targets.
232 TYPED_TEST(BitVectorTest, SimpleFindOps64Bit) {
233 TypeParam A;
234
235 A.resize(57);
236 A.set(12);
237 A.set(13);
238 A.set(47);
239
240 EXPECT_EQ(47, A.find_last());
241 EXPECT_EQ(12, A.find_first());
242 EXPECT_EQ(13, A.find_next(12));
243 EXPECT_EQ(47, A.find_next(13));
244 EXPECT_EQ(-1, A.find_next(47));
245
246 EXPECT_EQ(-1, A.find_prev(12));
247 EXPECT_EQ(12, A.find_prev(13));
248 EXPECT_EQ(13, A.find_prev(47));
249 EXPECT_EQ(47, A.find_prev(56));
250
251 EXPECT_EQ(0, A.find_first_unset());
252 EXPECT_EQ(56, A.find_last_unset());
253 EXPECT_EQ(14, A.find_next_unset(11));
254 EXPECT_EQ(14, A.find_next_unset(12));
255 EXPECT_EQ(14, A.find_next_unset(13));
256 EXPECT_EQ(16, A.find_next_unset(15));
257 EXPECT_EQ(48, A.find_next_unset(46));
258 EXPECT_EQ(48, A.find_next_unset(47));
259 EXPECT_EQ(-1, A.find_next_unset(56));
260 }
261
230262 // Check if a SmallBitVector is in small mode. This check is used in tests
231263 // that run for both SmallBitVector and BitVector. This check doesn't apply
232264 // to BitVector so we provide an overload that returns true to get the tests