aboutsummaryrefslogtreecommitdiff
path: root/lib/Support/APInt.cpp
diff options
context:
space:
mode:
authorTorok Edwin <edwintorok@gmail.com>2009-01-27 18:06:03 +0000
committerTorok Edwin <edwintorok@gmail.com>2009-01-27 18:06:03 +0000
commit2d0f1c57c3f95e43a8b18bfe8481d90b665d5efe (patch)
tree72e1a5c7d8ff8f4caa92d81768de94e6e64bacb1 /lib/Support/APInt.cpp
parent101a90f3d3c3ad9159676ba744b59b3a9d0b4af5 (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@63107 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/APInt.cpp')
-rw-r--r--lib/Support/APInt.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/Support/APInt.cpp b/lib/Support/APInt.cpp
index 367c75be1a..3d38a0c606 100644
--- a/lib/Support/APInt.cpp
+++ b/lib/Support/APInt.cpp
@@ -683,7 +683,13 @@ unsigned APInt::countLeadingOnes() const {
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) {