[llvm-commits] CVS: llvm/lib/Support/APInt.cpp

Reid Spencer reid at x10sys.com
Wed May 16 12:18:40 PDT 2007



Changes in directory llvm/lib/Support:

APInt.cpp updated: 1.82 -> 1.83
---
Log message:

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.


---
Diffs of the changes:  (+13 -8)

 APInt.cpp |   21 +++++++++++++--------
 1 files changed, 13 insertions(+), 8 deletions(-)


Index: llvm/lib/Support/APInt.cpp
diff -u llvm/lib/Support/APInt.cpp:1.82 llvm/lib/Support/APInt.cpp:1.83
--- llvm/lib/Support/APInt.cpp:1.82	Sun May 13 19:15:28 2007
+++ llvm/lib/Support/APInt.cpp	Wed May 16 14:18:22 2007
@@ -1861,21 +1861,26 @@
     // 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;
 






More information about the llvm-commits mailing list