OSDN Git Service

Proper fix for the off-by-one bug in clear_unused_bits().
authorEvan Cheng <evan.cheng@apple.com>
Thu, 15 Feb 2007 21:38:15 +0000 (21:38 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Thu, 15 Feb 2007 21:38:15 +0000 (21:38 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34328 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/BitVector.h

index 79c3f58..2696213 100644 (file)
@@ -290,12 +290,10 @@ private:
 
   // Clear the unused top bits in the high word.
   void clear_unused_bits() {
-    if (Size) {
-      unsigned ExtraBits = Size % BITS_PER_WORD;
+    unsigned ExtraBits = Size % BITS_PER_WORD;
+    if (ExtraBits) {
       unsigned index = Size / BITS_PER_WORD;
-      if (Size % BITS_PER_WORD == 0)
-        index--;
-      Bits[index] &= ~(~0 << ExtraBits);
+      Bits[index] &= ~(~0L << ExtraBits);
     }
   }