llvm.org GIT mirror llvm / a9c9423
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275815 91177308-0d34-0410-b5e6-96231b3b80d8 David Majnemer 4 years ago
1 changed file(s) with 1 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
336336 inline int64_t minIntN(int64_t N) {
337337 assert(N > 0 && N <= 64 && "integer width out of range");
339 return -(INT64_C(1)<<(N-1));
339 return -(UINT64_C(1)<<(N-1));
340340 }
342342 /// Gets the maximum value for a N-bit signed integer.