From 5083912dd79249a8954fd3e1e381a0cd7c624fbd Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 18 Aug 2010 00:33:47 +0000 Subject: [PATCH] stomp some more undefined behavior, PR7775. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@111337 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/APInt.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) 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) {