forked from OSchip/llvm-project
[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:
parent
301b1fa637
commit
a2a218fbd4
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue