Fix APInt::countTrailingZeros to return BitWidth if the input is zero instead of...
authorChris Lattner <sabre@nondot.org>
Fri, 23 Nov 2007 22:36:25 +0000 (22:36 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 23 Nov 2007 22:36:25 +0000 (22:36 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44294 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/APInt.cpp

index c5abf4bf1634d86b9217addf2716c13875092394..7af0101ece81d8247f0ab1e5ee0c0731bcc66988 100644 (file)
@@ -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 {