From 5134443f6020a327f39e87a0db4ddbd9660befb0 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Fri, 18 Sep 2015 12:18:41 +0000 Subject: [PATCH] Reverting r247972 (and subordinate commit r247972) as the 32-bit left-shift is undefined behavior on implementations where uinptr_t is 32-bits. One such platform is Windows, MSVC, x86. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@247983 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ADT/SmallBitVector.h | 18 ++++++++++-------- unittests/ADT/BitVectorTest.cpp | 4 ++-- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/include/llvm/ADT/SmallBitVector.h b/include/llvm/ADT/SmallBitVector.h index 39d2e14a63d..ae3d645396f 100644 --- a/include/llvm/ADT/SmallBitVector.h +++ b/include/llvm/ADT/SmallBitVector.h @@ -553,15 +553,17 @@ public: private: template void applyMask(const uint32_t *Mask, unsigned MaskWords) { - uintptr_t M = Mask[0]; - if (MaskWords != 1) { - assert(NumBaseBits == 64 && MaskWords == 2 && - "Mask is larger than base!"); - M |= uintptr_t(Mask[1]) << 32; + if (NumBaseBits == 64 && MaskWords >= 2) { + uint64_t M = Mask[0] | (uint64_t(Mask[1]) << 32); + if (InvertMask) M = ~M; + if (AddBits) setSmallBits(getSmallBits() | M); + else setSmallBits(getSmallBits() & ~M); + } else { + uint32_t M = Mask[0]; + if (InvertMask) M = ~M; + if (AddBits) setSmallBits(getSmallBits() | M); + else setSmallBits(getSmallBits() & ~M); } - if (InvertMask) M = ~M; - if (AddBits) setSmallBits(getSmallBits() | M); - else setSmallBits(getSmallBits() & ~M); } }; diff --git a/unittests/ADT/BitVectorTest.cpp b/unittests/ADT/BitVectorTest.cpp index 95ff93fa9c4..3deaff0fe35 100644 --- a/unittests/ADT/BitVectorTest.cpp +++ b/unittests/ADT/BitVectorTest.cpp @@ -235,12 +235,12 @@ TYPED_TEST(BitVectorTest, PortableBitMask) { const uint32_t Mask1[] = { 0x80000000, 6, 5 }; A.resize(10); - A.setBitsInMask(Mask1, 1); + A.setBitsInMask(Mask1, 3); EXPECT_EQ(10u, A.size()); EXPECT_FALSE(A.test(0)); A.resize(32); - A.setBitsInMask(Mask1, 1); + A.setBitsInMask(Mask1, 3); EXPECT_FALSE(A.test(0)); EXPECT_TRUE(A.test(31)); EXPECT_EQ(1u, A.count()); -- 2.34.1