aboutsummaryrefslogtreecommitdiff
path: root/lib/Support/APInt.cpp
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2007-05-16 19:18:22 +0000
committerReid Spencer <rspencer@reidspencer.com>2007-05-16 19:18:22 +0000
commit6551dcdd8a6a28e060a9d6562a381220597dcae3 (patch)
tree939ed45a654b1bc6bedbb7907ecb10224c4f00b5 /lib/Support/APInt.cpp
parent2b91631e449376aae5f5cd84b5957cfae4ac5e53 (diff)
Fix a bug in the "fromString" method where radix 2,8 and 16 values were
not being generated correctly because the shl operator does not mutate its object but returns a new value. Also, make the distinction between radix 16 and the others more clear. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37111 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/APInt.cpp')
-rw-r--r--lib/Support/APInt.cpp21
1 files changed, 13 insertions, 8 deletions
diff --git a/lib/Support/APInt.cpp b/lib/Support/APInt.cpp
index c8c3c24627..460cf55761 100644
--- a/lib/Support/APInt.cpp
+++ b/lib/Support/APInt.cpp
@@ -1861,21 +1861,26 @@ void APInt::fromString(uint32_t numbits, const char *str, uint32_t slen,
// Get a digit
uint32_t digit = 0;
char cdigit = str[i];
- if (isdigit(cdigit))
- digit = cdigit - '0';
- else if (isxdigit(cdigit))
- if (cdigit >= 'a')
+ if (radix == 16) {
+ if (!isxdigit(cdigit))
+ assert(0 && "Invalid hex digit in string");
+ if (isdigit(cdigit))
+ digit = cdigit - '0';
+ else if (cdigit >= 'a')
digit = cdigit - 'a' + 10;
else if (cdigit >= 'A')
digit = cdigit - 'A' + 10;
else
- assert(0 && "huh?");
- else
+ assert(0 && "huh? we shouldn't get here");
+ } else if (isdigit(cdigit)) {
+ digit = cdigit - '0';
+ } else {
assert(0 && "Invalid character in digit string");
+ }
- // Shift or multiple the value by the radix
+ // Shift or multiply the value by the radix
if (shift)
- this->shl(shift);
+ *this <<= shift;
else
*this *= apradix;