APInt's countLeadingOnes() was broken for negative i128 values,
causing assertion failures in getSExtValue().
Fix it by making highWordBits actually contain what its name says,
and add some more unit-tests for APInt.
This fixes PR3419.
llvm-svn: 63107
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index 367c75b..3d38a0c 100644
--- a/llvm/lib/Support/APInt.cpp
+++ b/llvm/lib/Support/APInt.cpp
@@ -683,7 +683,13 @@
return countLeadingOnes_64(VAL, APINT_BITS_PER_WORD - BitWidth);
unsigned highWordBits = BitWidth % APINT_BITS_PER_WORD;
- unsigned shift = (highWordBits == 0 ? 0 : APINT_BITS_PER_WORD - highWordBits);
+ unsigned shift;
+ if (!highWordBits) {
+ highWordBits = APINT_BITS_PER_WORD;
+ shift = 0;
+ } else {
+ shift = APINT_BITS_PER_WORD - highWordBits;
+ }
int i = getNumWords() - 1;
unsigned Count = countLeadingOnes_64(pVal[i], shift);
if (Count == highWordBits) {