summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/APInt.cpp
diff options
context:
space:
mode:
authorDmitry Venikov <quolyk@gmail.com>2019-06-29 11:38:12 +0000
committerDmitry Venikov <quolyk@gmail.com>2019-06-29 11:38:12 +0000
commit9e9eb62f9fd75706377ac6cf3abffad1328d0d4f (patch)
tree2c7c9df61ee027da81be92cc5e68970d3d1cbc8c /llvm/lib/Support/APInt.cpp
parent2d756c4feb69e4fe0ed8556e05bc2ff3c7bc1007 (diff)
downloadbcm5719-llvm-9e9eb62f9fd75706377ac6cf3abffad1328d0d4f.tar.gz
bcm5719-llvm-9e9eb62f9fd75706377ac6cf3abffad1328d0d4f.zip
[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 llvm-svn: 364710
Diffstat (limited to 'llvm/lib/Support/APInt.cpp')
-rw-r--r--llvm/lib/Support/APInt.cpp5
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;
}
OpenPOWER on IntegriCloud