summaryrefslogtreecommitdiffstats
path: root/llvm/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
commitec39eb851984f5ddcabfcde7cb8e28bf4f442261 (patch)
tree3bf202eb0590baf6b92406f9750c8616fb0ca15a /llvm/lib/Support/APInt.cpp
parented2ba0fb015c02c5d6427b0b2b29143656cf54c1 (diff)
downloadbcm5719-llvm-ec39eb851984f5ddcabfcde7cb8e28bf4f442261.tar.gz
bcm5719-llvm-ec39eb851984f5ddcabfcde7cb8e28bf4f442261.zip
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
Diffstat (limited to 'llvm/lib/Support/APInt.cpp')
-rw-r--r--llvm/lib/Support/APInt.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index 367c75be1af..3d38a0c6066 100644
--- a/llvm/lib/Support/APInt.cpp
+++ b/llvm/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) {
OpenPOWER on IntegriCloud