[llvm-commits] [llvm] r42860 - /llvm/trunk/include/llvm/ADT/BitVector.h

Chris Lattner sabre at nondot.org
Wed Oct 10 23:12:34 PDT 2007


Author: lattner
Date: Thu Oct 11 01:12:33 2007
New Revision: 42860

URL: http://llvm.org/viewvc/llvm-project?rev=42860&view=rev
Log:
make bitvector  &= do the right thing if vectors have mismatched length.

Modified:
    llvm/trunk/include/llvm/ADT/BitVector.h

Modified: llvm/trunk/include/llvm/ADT/BitVector.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/BitVector.h?rev=42860&r1=42859&r2=42860&view=diff

==============================================================================
--- llvm/trunk/include/llvm/ADT/BitVector.h (original)
+++ llvm/trunk/include/llvm/ADT/BitVector.h Thu Oct 11 01:12:33 2007
@@ -274,9 +274,18 @@
 
   // 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;
   }
 





More information about the llvm-commits mailing list