diff --git a/lib/Support/APInt.cpp b/lib/Support/APInt.cpp index 262fa42ab2c..8a212a291f2 100644 --- a/lib/Support/APInt.cpp +++ b/lib/Support/APInt.cpp @@ -2123,15 +2123,16 @@ void APInt::toString(SmallVectorImpl &Str, unsigned Radix, char *BufPtr = Buffer+65; uint64_t N; - if (Signed) { - int64_t I = getSExtValue(); - if (I < 0) { - Str.push_back('-'); - I = -I; - } - N = I; - } else { + if (!Signed) { N = getZExtValue(); + } else { + int64_t I = getSExtValue(); + if (I >= 0) { + N = I; + } else { + Str.push_back('-'); + N = -(uint64_t)I; + } } while (N) {