summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustin Lebar <jlebar@google.com>2016-07-18 20:40:35 +0000
committerJustin Lebar <jlebar@google.com>2016-07-18 20:40:35 +0000
commit413358450445619ef514ab9e94374dbd8fd6c3e3 (patch)
tree6c540a354b99011d6a30ec844e23489320ad56de
parentdbf44f501624b610797bf411d6aa4e76fb0c9db8 (diff)
downloadbcm5719-llvm-413358450445619ef514ab9e94374dbd8fd6c3e3.tar.gz
bcm5719-llvm-413358450445619ef514ab9e94374dbd8fd6c3e3.zip
Write isUInt using template specializations to work around an incorrect MSVC warning.
Summary: Per D22441, MSVC warns on our old implementation of isUInt<64>. It sees uint64_t(1) << 64 and doesn't realize that it's not going to be executed. Writing as a template specialization is ugly, but prevents the warning. Reviewers: RKSimon Subscribers: majnemer, llvm-commits Differential Revision: https://reviews.llvm.org/D22472 llvm-svn: 275909
-rw-r--r--llvm/include/llvm/Support/MathExtras.h19
1 files changed, 15 insertions, 4 deletions
diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h
index 5c816ac9df9..42e92203ef9 100644
--- a/llvm/include/llvm/Support/MathExtras.h
+++ b/llvm/include/llvm/Support/MathExtras.h
@@ -290,10 +290,21 @@ inline bool isShiftedInt(int64_t x) {
}
/// isUInt - Checks if an unsigned integer fits into the given bit width.
-template<unsigned N>
-inline bool isUInt(uint64_t x) {
- static_assert(N > 0, "isUInt<0> doesn't make sense.");
- return N >= 64 || x < (UINT64_C(1)<<(N));
+///
+/// This is written as two functions rather than as simply
+///
+/// return N >= 64 || X < (UINT64_C(1) << N);
+///
+/// to keep MSVC from (incorrectly) warning on isUInt<64> that we're shifting
+/// left too many places.
+template <unsigned N>
+inline typename std::enable_if<(N < 64), bool>::type isUInt(uint64_t X) {
+ static_assert(N > 0, "isUInt<0> doesn't make sense");
+ return X < (UINT64_C(1) << N);
+}
+template <unsigned N>
+inline typename std::enable_if<N >= 64, bool>::type isUInt(uint64_t X) {
+ return true;
}
// Template specializations to get better code for common cases.
OpenPOWER on IntegriCloud