summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/APInt.cpp
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2007-02-22 00:22:00 +0000
committerReid Spencer <rspencer@reidspencer.com>2007-02-22 00:22:00 +0000
commite4ce71d07aa1731d6c87bd43cc6440f724a21486 (patch)
tree92ae0881cfd5784deb9fa1bd40c85a91bdf6ddcf /llvm/lib/Support/APInt.cpp
parent3796abea0f01e2db3050b950a090e69dd56dd008 (diff)
downloadbcm5719-llvm-e4ce71d07aa1731d6c87bd43cc6440f724a21486.tar.gz
bcm5719-llvm-e4ce71d07aa1731d6c87bd43cc6440f724a21486.zip
Fix countLeadingZeros in the case that the bitwidth evenly divides the
word size. This fixes all reads of uninitialized data (buffer over read) and makes APInt.cpp memory clean, per valgrind. The only remaining problem is division in a few cases. llvm-svn: 34483
Diffstat (limited to 'llvm/lib/Support/APInt.cpp')
-rw-r--r--llvm/lib/Support/APInt.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index a515366db21..c8ab2d762b6 100644
--- a/llvm/lib/Support/APInt.cpp
+++ b/llvm/lib/Support/APInt.cpp
@@ -726,7 +726,10 @@ uint32_t APInt::countLeadingZeros() const {
}
}
}
- return Count - (APINT_BITS_PER_WORD - (BitWidth % APINT_BITS_PER_WORD));
+ uint32_t remainder = BitWidth % APINT_BITS_PER_WORD;
+ if (remainder)
+ Count -= APINT_BITS_PER_WORD - remainder;
+ return Count;
}
/// countTrailingZeros - This function is a APInt version corresponding to
OpenPOWER on IntegriCloud