aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan McKay <dylanmckay34@gmail.com>2016-06-01 11:15:25 +0000
committerDylan McKay <dylanmckay34@gmail.com>2016-06-01 11:15:25 +0000
commit0c16b49f10bd294f28d1b4e1e39c9d6281ac7d11 (patch)
tree5cf6054334bbd5b6f85bffb4794cdc40d0b48e47
parent9cc353e2b3d22cbafaed52c897d2356dd99a4630 (diff)
downloadllvm-0c16b49f10bd294f28d1b4e1e39c9d6281ac7d11.zip
llvm-0c16b49f10bd294f28d1b4e1e39c9d6281ac7d11.tar.gz
llvm-0c16b49f10bd294f28d1b4e1e39c9d6281ac7d11.tar.bz2
Fix off-by-one error in max integer functions
I recently added these functions, but implemented them poorly. This fixes that. Sorry for the spam. llvm-svn: 271380
-rw-r--r--llvm/include/llvm/Support/MathExtras.h8
1 files changed, 4 insertions, 4 deletions
diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h
index 10418e9..3b5cd36 100644
--- a/llvm/include/llvm/Support/MathExtras.h
+++ b/llvm/include/llvm/Support/MathExtras.h
@@ -312,22 +312,22 @@ inline bool isShiftedUInt(uint64_t x) {
}
/// Gets the maximum value for a N-bit unsigned integer.
-inline uint64_t maxUIntN(uint64_t N) { return UINT64_C(1) << N; }
+inline uint64_t maxUIntN(uint64_t N) { return (UINT64_C(1) << N) - 1; }
/// Gets the minimum value for a N-bit signed integer.
inline int64_t minIntN(int64_t N) { return -(INT64_C(1)<<(N-1)); }
/// Gets the maximum value for a N-bit signed integer.
-inline int64_t maxIntN(int64_t N) { return INT64_C(1)<<(N-1); }
+inline int64_t maxIntN(int64_t N) { return (INT64_C(1)<<(N-1)) - 1; }
/// isUIntN - Checks if an unsigned integer fits into the given (dynamic)
/// bit width.
inline bool isUIntN(unsigned N, uint64_t x) {
- return N >= 64 || x < maxUIntN(N);
+ return N >= 64 || x <= maxUIntN(N);
}
/// isIntN - Checks if an signed integer fits into the given (dynamic)
/// bit width.
inline bool isIntN(unsigned N, int64_t x) {
- return N >= 64 || (minIntN(N) <= x && x < maxIntN(N));
+ return N >= 64 || (minIntN(N) <= x && x <= maxIntN(N));
}
/// isMask_32 - This function returns true if the argument is a non-empty