summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/APInt.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-04-25 18:34:04 +0000
committerChris Lattner <sabre@nondot.org>2009-04-25 18:34:04 +0000
commitb869a0ade10a150b06b227572f5a19b9037fdde2 (patch)
treec9dc936805e97fb5f48bc4db96746e655f43fee3 /llvm/lib/Support/APInt.cpp
parent3ad60b18cb4567f1e2c971c900dfad4c7476afed (diff)
downloadbcm5719-llvm-b869a0ade10a150b06b227572f5a19b9037fdde2.tar.gz
bcm5719-llvm-b869a0ade10a150b06b227572f5a19b9037fdde2.zip
Fix PR4040: APInt's string constructor is too strict
patch by Jeff Yasskin! llvm-svn: 70058
Diffstat (limited to 'llvm/lib/Support/APInt.cpp')
-rw-r--r--llvm/lib/Support/APInt.cpp16
1 files changed, 9 insertions, 7 deletions
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index 1cabe0f03e7..8ac589c865f 100644
--- a/llvm/lib/Support/APInt.cpp
+++ b/llvm/lib/Support/APInt.cpp
@@ -1918,9 +1918,9 @@ void APInt::fromString(unsigned numbits, const char *str, unsigned slen,
if (isNeg)
str++, slen--;
assert((slen <= numbits || radix != 2) && "Insufficient bit width");
- assert((slen*3 <= numbits || radix != 8) && "Insufficient bit width");
- assert((slen*4 <= numbits || radix != 16) && "Insufficient bit width");
- assert(((slen*64)/22 <= numbits || radix != 10) && "Insufficient bit width");
+ assert(((slen-1)*3 <= numbits || radix != 8) && "Insufficient bit width");
+ assert(((slen-1)*4 <= numbits || radix != 16) && "Insufficient bit width");
+ assert((((slen-1)*64)/22 <= numbits || radix != 10) && "Insufficient bit width");
// Allocate memory
if (!isSingleWord())
@@ -1961,10 +1961,12 @@ void APInt::fromString(unsigned numbits, const char *str, unsigned slen,
}
// Shift or multiply the value by the radix
- if (shift)
- *this <<= shift;
- else
- *this *= apradix;
+ if (slen > 1) {
+ if (shift)
+ *this <<= shift;
+ else
+ *this *= apradix;
+ }
// Add in the digit we just interpreted
if (apdigit.isSingleWord())
OpenPOWER on IntegriCloud