mirror of
https://github.com/RPCS3/llvm.git
synced 2026-07-18 21:24:32 -04:00
[APInt] Fix getBitsNeeded for INT_MIN values
Summary: This patch fixes behaviour of APInt::getBitsNeeded for INT_MIN 10 bits values. Reviewers: regehr, RKSimon Reviewed By: RKSimon Subscribers: grandinj, dexonsmith, kristina, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D63691 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@364710 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -482,10 +482,13 @@ unsigned APInt::getBitsNeeded(StringRef str, uint8_t radix) {
|
||||
APInt tmp(sufficient, StringRef(p, slen), radix);
|
||||
|
||||
// Compute how many bits are required. If the log is infinite, assume we need
|
||||
// just bit.
|
||||
// just bit. If the log is exact and value is negative, then the value is
|
||||
// MinSignedValue with (log + 1) bits.
|
||||
unsigned log = tmp.logBase2();
|
||||
if (log == (unsigned)-1) {
|
||||
return isNegative + 1;
|
||||
} else if (isNegative && tmp.isPowerOf2()) {
|
||||
return isNegative + log;
|
||||
} else {
|
||||
return isNegative + log + 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user