Fix the arithmetic overflow issue for MSVC (#27596)
Summary:
Fixes https://github.com/pytorch/pytorch/issues/27568.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/27596
Differential Revision: D17831612
Pulled By: ezyang
fbshipit-source-id: eff18095a74b6b82f70ed3f11d201483097205c5
diff --git a/c10/util/llvmMathExtras.h b/c10/util/llvmMathExtras.h
index 76ae3b2..4cda3cc 100644
--- a/c10/util/llvmMathExtras.h
+++ b/c10/util/llvmMathExtras.h
@@ -388,13 +388,23 @@
return UINT64_MAX >> (64 - N);
}
+ // Ignore the false warning "Arithmetic overflow" for MSVC
+ #ifdef _MSC_VER
+ # pragma warning(push)
+ # pragma warning(disable : 4146)
+ #endif
+
/// Gets the minimum value for a N-bit signed integer.
inline int64_t minIntN(int64_t N) {
assert(N > 0 && N <= 64 && "integer width out of range");
- return -(UINT64_C(1)<<(N-1));
+ return -(UINT64_C(1) << (N - 1));
}
+ #ifdef _MSC_VER
+ # pragma warning(pop)
+ #endif
+
/// Gets the maximum value for a N-bit signed integer.
inline int64_t maxIntN(int64_t N) {
assert(N > 0 && N <= 64 && "integer width out of range");