summaryrefslogtreecommitdiff
path: root/include/llvm/ADT/BitVector.h
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-10-11 06:12:33 +0000
committerChris Lattner <sabre@nondot.org>2007-10-11 06:12:33 +0000
commit343960af3177b056266fc719489e6ec7a5d869de (patch)
treef3fb171763659a43c2b5782703d07faebbdd3574 /include/llvm/ADT/BitVector.h
parent3ef437d137afe7409b93310a2092a2f8a8dbfcca (diff)
downloadllvm-343960af3177b056266fc719489e6ec7a5d869de.tar.gz
llvm-343960af3177b056266fc719489e6ec7a5d869de.tar.bz2
llvm-343960af3177b056266fc719489e6ec7a5d869de.tar.xz
make bitvector &= do the right thing if vectors have mismatched length.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42860 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/ADT/BitVector.h')
-rw-r--r--include/llvm/ADT/BitVector.h13
1 files changed, 11 insertions, 2 deletions
diff --git a/include/llvm/ADT/BitVector.h b/include/llvm/ADT/BitVector.h
index 50ccdab159..dc408af4ae 100644
--- a/include/llvm/ADT/BitVector.h
+++ b/include/llvm/ADT/BitVector.h
@@ -274,9 +274,18 @@ public:
// Intersection, union, disjoint union.
BitVector operator&=(const BitVector &RHS) {
- assert(Size == RHS.Size && "Illegal operation!");
- for (unsigned i = 0; i < NumBitWords(size()); ++i)
+ unsigned ThisWords = NumBitWords(size());
+ unsigned RHSWords = NumBitWords(RHS.size());
+ unsigned i;
+ for (i = 0; i != std::min(ThisWords, RHSWords); ++i)
Bits[i] &= RHS.Bits[i];
+
+ // Any bits that are just in this bitvector become zero, because they aren't
+ // in the RHS bit vector. Any words only in RHS are ignored because they
+ // are already zero in the LHS.
+ for (; i != ThisWords; ++i)
+ Bits[i] = 0;
+
return *this;
}