summaryrefslogtreecommitdiff
path: root/lib/Support
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2010-08-03 16:41:24 +0000
committerChris Lattner <sabre@nondot.org>2010-08-03 16:41:24 +0000
commite211cd83f088ad462815676bc08b437c123cabed (patch)
tree8671b862bccb77efe1313f31de640ba480e0dd79 /lib/Support
parent3bababf880bfeaf1bcda7e4f808007621b6bfac8 (diff)
downloadllvm-e211cd83f088ad462815676bc08b437c123cabed.tar.gz
llvm-e211cd83f088ad462815676bc08b437c123cabed.tar.bz2
llvm-e211cd83f088ad462815676bc08b437c123cabed.tar.xz
avoid undef behavior on minint, fixing PR7783.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@110114 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support')
-rw-r--r--lib/Support/raw_ostream.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/Support/raw_ostream.cpp b/lib/Support/raw_ostream.cpp
index 8054ae6368..ac118a91a3 100644
--- a/lib/Support/raw_ostream.cpp
+++ b/lib/Support/raw_ostream.cpp
@@ -143,9 +143,10 @@ raw_ostream &raw_ostream::operator<<(unsigned long long N) {
}
raw_ostream &raw_ostream::operator<<(long long N) {
- if (N < 0) {
+ if (N < 0) {
*this << '-';
- N = -N;
+ // Avoid undefined behavior on INT64_MIN with a cast.
+ N = -(unsigned long long)N;
}
return this->operator<<(static_cast<unsigned long long>(N));