stomp some more undefined behavior, PR7775.
authorChris Lattner <sabre@nondot.org>
Wed, 18 Aug 2010 00:33:47 +0000 (00:33 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 18 Aug 2010 00:33:47 +0000 (00:33 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@111337 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/APInt.cpp

index 262fa42ab2ced3988c44a5043aba7a268bd82c55..8a212a291f24d777750ed39eb1e46e3692829cff 100644 (file)
@@ -2123,15 +2123,16 @@ void APInt::toString(SmallVectorImpl<char> &Str, unsigned Radix,
     char *BufPtr = Buffer+65;
 
     uint64_t N;
-    if (Signed) {
+    if (!Signed) {
+      N = getZExtValue();
+    } else {
       int64_t I = getSExtValue();
-      if (I < 0) {
+      if (I >= 0) {
+        N = I;
+      } else {
         Str.push_back('-');
-        I = -I;
+        N = -(uint64_t)I;
       }
-      N = I;
-    } else {
-      N = getZExtValue();
     }
 
     while (N) {