aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Support
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-11-23 22:36:25 +0000
committerChris Lattner <sabre@nondot.org>2007-11-23 22:36:25 +0000
commit9ee26cf5e78b1f5440f366c2332e29f68e4ba33b (patch)
treecdeb0242e8f408689767d847bed6bc03e9d00c56 /lib/Support
parenta03930e2abe0b98f7a9fb63ac96e9bf2eda30a24 (diff)
downloadexternal_llvm-9ee26cf5e78b1f5440f366c2332e29f68e4ba33b.zip
external_llvm-9ee26cf5e78b1f5440f366c2332e29f68e4ba33b.tar.gz
external_llvm-9ee26cf5e78b1f5440f366c2332e29f68e4ba33b.tar.bz2
Fix APInt::countTrailingZeros to return BitWidth if the input is zero instead of returning some random large number.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44294 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support')
-rw-r--r--lib/Support/APInt.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/Support/APInt.cpp b/lib/Support/APInt.cpp
index c5abf4b..7af0101 100644
--- a/lib/Support/APInt.cpp
+++ b/lib/Support/APInt.cpp
@@ -782,14 +782,14 @@ uint32_t APInt::countLeadingOnes() const {
uint32_t APInt::countTrailingZeros() const {
if (isSingleWord())
- return CountTrailingZeros_64(VAL);
+ return std::min(CountTrailingZeros_64(VAL), BitWidth);
uint32_t Count = 0;
uint32_t i = 0;
for (; i < getNumWords() && pVal[i] == 0; ++i)
Count += APINT_BITS_PER_WORD;
if (i < getNumWords())
Count += CountTrailingZeros_64(pVal[i]);
- return Count;
+ return std::min(Count, BitWidth);
}
uint32_t APInt::countPopulation() const {