diff options
| author | Reid Spencer <rspencer@reidspencer.com> | 2007-05-16 19:18:22 +0000 |
|---|---|---|
| committer | Reid Spencer <rspencer@reidspencer.com> | 2007-05-16 19:18:22 +0000 |
| commit | a93c981f66b9ba8076519cd4cce5f29e7ce4b4f7 (patch) | |
| tree | 95e2333176ce2ea1792410db0189d3d03f525fc4 /llvm/lib | |
| parent | 138249b8cab15a7f37dd9928b11eacec3f2de8fb (diff) | |
| download | bcm5719-llvm-a93c981f66b9ba8076519cd4cce5f29e7ce4b4f7.tar.gz bcm5719-llvm-a93c981f66b9ba8076519cd4cce5f29e7ce4b4f7.zip | |
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.
llvm-svn: 37111
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Support/APInt.cpp | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp index c8c3c246274..460cf557610 100644 --- a/llvm/lib/Support/APInt.cpp +++ b/llvm/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; |

