diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2007-03-24 23:35:54 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2007-03-24 23:35:54 +0000 |
commit | ca76fc2cd3b97e4821e7d8247bc03bbbd2789ad9 (patch) | |
tree | 663bb4c09cde4e55ef16e8bd89f9cde1f5ecfb9d /include/llvm | |
parent | 8f969ee62c3fed26f835a37c41f7c009f99ea3bf (diff) | |
download | external_llvm-ca76fc2cd3b97e4821e7d8247bc03bbbd2789ad9.zip external_llvm-ca76fc2cd3b97e4821e7d8247bc03bbbd2789ad9.tar.gz external_llvm-ca76fc2cd3b97e4821e7d8247bc03bbbd2789ad9.tar.bz2 |
Don't invoke undefined behavior in shifts in the functions getHighBitsSet
and getLowBitsSet.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35311 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm')
-rw-r--r-- | include/llvm/ADT/APInt.h | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/include/llvm/ADT/APInt.h b/include/llvm/ADT/APInt.h index 4ceef2d..fb6246d 100644 --- a/include/llvm/ADT/APInt.h +++ b/include/llvm/ADT/APInt.h @@ -357,12 +357,11 @@ public: /// @brief Get a value with high bits set static APInt getHighBitsSet(uint32_t numBits, uint32_t hiBitsSet) { assert(hiBitsSet <= numBits && "Too many bits to set!"); - uint32_t mvBits = numBits - hiBitsSet; + uint32_t shiftAmt = numBits - hiBitsSet; // For small values, return quickly if (numBits <= APINT_BITS_PER_WORD) - return APInt(numBits, ((1ULL << hiBitsSet) - 1) << mvBits); - APInt Result(numBits, 1); - return (APInt(numBits, 1).shl(hiBitsSet) - APInt(numBits, 1)).shl(mvBits); + return APInt(numBits, ~0ULL << shiftAmt); + return (~APInt(numBits, 0)).shl(shiftAmt); } /// Constructs an APInt value that has the bottom loBitsSet bits set. @@ -371,10 +370,11 @@ public: /// @brief Get a value with low bits set static APInt getLowBitsSet(uint32_t numBits, uint32_t loBitsSet) { assert(loBitsSet <= numBits && "Too many bits to set!"); + uint32_t shiftAmt = numBits - loBitsSet; // For small values, return quickly if (numBits <= APINT_BITS_PER_WORD) - return APInt(numBits, (1ULL << loBitsSet) - 1ULL); - return APInt(numBits, 1).shl(loBitsSet) - APInt(numBits, 1); + return APInt(numBits, ~0ULL >> shiftAmt); + return (~APInt(numBits, 0)).lshr(shiftAmt); } /// The hash value is computed as the sum of the words and the bit width. |