make bitvector &= do the right thing if vectors have mismatched length.
authorChris Lattner <sabre@nondot.org>
Thu, 11 Oct 2007 06:12:33 +0000 (06:12 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 11 Oct 2007 06:12:33 +0000 (06:12 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42860 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/BitVector.h

index 50ccdab159ead3ea6f0b66cfaee98cd0f3d032fa..dc408af4ae2ba90535c46a05cb80434c3cc48992 100644 (file)
@@ -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;
   }