diff options
Diffstat (limited to 'llvm/lib/Support/APInt.cpp')
-rw-r--r-- | llvm/lib/Support/APInt.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp index d008055bd45..3b40d9bd734 100644 --- a/llvm/lib/Support/APInt.cpp +++ b/llvm/lib/Support/APInt.cpp @@ -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; } |