[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.

llvm-svn: 275815
This commit is contained in:
David Majnemer 2016-07-18 17:03:09 +00:00
parent 301b1fa637
commit a2a218fbd4
1 changed files with 1 additions and 1 deletions

View File

@ -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.