[llvm] r275815 - [MathExtras] Fix UB in minIntN
David Majnemer via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 18 10:03:10 PDT 2016
Author: majnemer
Date: Mon Jul 18 12:03:09 2016
New Revision: 275815
URL: http://llvm.org/viewvc/llvm-project?rev=275815&view=rev
Log:
[MathExtras] Fix UB in minIntN
We negated a value with a signed type which invited problems when that
value was the most negative signed number. Use an unsigned type
for the value instead. It will compute the same twos complement
result without the UB.
Modified:
llvm/trunk/include/llvm/Support/MathExtras.h
Modified: llvm/trunk/include/llvm/Support/MathExtras.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/MathExtras.h?rev=275815&r1=275814&r2=275815&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/MathExtras.h (original)
+++ llvm/trunk/include/llvm/Support/MathExtras.h Mon Jul 18 12:03:09 2016
@@ -337,7 +337,7 @@ inline uint64_t maxUIntN(uint64_t N) {
inline int64_t minIntN(int64_t N) {
assert(N > 0 && N <= 64 && "integer width out of range");
- return -(INT64_C(1)<<(N-1));
+ return -(UINT64_C(1)<<(N-1));
}
/// Gets the maximum value for a N-bit signed integer.
More information about the llvm-commits
mailing list