Fix countLeadingZeros in the case that the bitwidth evenly divides the

word size. This fixes all reads of uninitialized data (buffer over read)
and makes APInt.cpp memory clean, per valgrind. The only remaining
problem is division in a few cases.

llvm-svn: 34483
This commit is contained in:
Reid Spencer 2007-02-22 00:22:00 +00:00
parent 3796abea0f
commit e4ce71d07a
1 changed files with 4 additions and 1 deletions

View File

@ -726,7 +726,10 @@ uint32_t APInt::countLeadingZeros() const {
}
}
}
return Count - (APINT_BITS_PER_WORD - (BitWidth % APINT_BITS_PER_WORD));
uint32_t remainder = BitWidth % APINT_BITS_PER_WORD;
if (remainder)
Count -= APINT_BITS_PER_WORD - remainder;
return Count;
}
/// countTrailingZeros - This function is a APInt version corresponding to