diff options
| author | Chris Lattner <sabre@nondot.org> | 2007-10-11 06:12:33 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2007-10-11 06:12:33 +0000 |
| commit | bbd55307547c471444aecddb5aeda3b2adc60127 (patch) | |
| tree | 17f6bf30838351cddbd87982cfb42629ec2dab6f | |
| parent | fc668d1233758fbb2c440376e5639ebb142a30ec (diff) | |
| download | bcm5719-llvm-bbd55307547c471444aecddb5aeda3b2adc60127.tar.gz bcm5719-llvm-bbd55307547c471444aecddb5aeda3b2adc60127.zip | |
make bitvector &= do the right thing if vectors have mismatched length.
llvm-svn: 42860
| -rw-r--r-- | llvm/include/llvm/ADT/BitVector.h | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/llvm/include/llvm/ADT/BitVector.h b/llvm/include/llvm/ADT/BitVector.h index 50ccdab159e..dc408af4ae2 100644 --- a/llvm/include/llvm/ADT/BitVector.h +++ b/llvm/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; } |

