summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2007-03-24 23:35:54 +0000
committerReid Spencer <rspencer@reidspencer.com>2007-03-24 23:35:54 +0000
commitcf3a678d40539278394befaea9016466c9c44621 (patch)
treea6b2a07f85b90a9873cd6ab9c1af776fcd6f66f3 /llvm
parentb334e8ac573ecfe92a20bdf1dadeac205a6843df (diff)
downloadbcm5719-llvm-cf3a678d40539278394befaea9016466c9c44621.tar.gz
bcm5719-llvm-cf3a678d40539278394befaea9016466c9c44621.zip
Don't invoke undefined behavior in shifts in the functions getHighBitsSet
and getLowBitsSet. llvm-svn: 35311
Diffstat (limited to 'llvm')
-rw-r--r--llvm/include/llvm/ADT/APInt.h12
1 files changed, 6 insertions, 6 deletions
diff --git a/llvm/include/llvm/ADT/APInt.h b/llvm/include/llvm/ADT/APInt.h
index 4ceef2df3ca..fb6246d0084 100644
--- a/llvm/include/llvm/ADT/APInt.h
+++ b/llvm/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.
OpenPOWER on IntegriCloud