aboutsummaryrefslogtreecommitdiffstats
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
commitab2b2c827c4a60e558efaea3bfeb1ebd13b5985b (patch)
tree3dd257973b7033a15c426518840a16655cbe525e
parent62819f31440fe1b1415473a89b8683b5b690d5fa (diff)
downloadexternal_llvm-ab2b2c827c4a60e558efaea3bfeb1ebd13b5985b.zip
external_llvm-ab2b2c827c4a60e558efaea3bfeb1ebd13b5985b.tar.gz
external_llvm-ab2b2c827c4a60e558efaea3bfeb1ebd13b5985b.tar.bz2
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34483 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Support/APInt.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/lib/Support/APInt.cpp b/lib/Support/APInt.cpp
index a515366..c8ab2d7 100644
--- a/lib/Support/APInt.cpp
+++ b/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