summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2011-10-13 22:49:56 +0000
committerEli Friedman <eli.friedman@gmail.com>2011-10-13 22:49:56 +0000
commit90406e18b8590d9588a76b849937d643dd3dc8b5 (patch)
treeeccf6de90468c0ce86d1f70b713d38ceabf947a0
parent8e4d0429de3d44a4c5b02b3d27cb0b78520609ba (diff)
downloadllvm-90406e18b8590d9588a76b849937d643dd3dc8b5.tar.gz
llvm-90406e18b8590d9588a76b849937d643dd3dc8b5.tar.bz2
llvm-90406e18b8590d9588a76b849937d643dd3dc8b5.tar.xz
Avoid undefined behavior in signed integer negation. Patch by Ahmed Charles.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@141905 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Support/raw_ostream.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/Support/raw_ostream.cpp b/lib/Support/raw_ostream.cpp
index c9cf249500..4927e9a7b9 100644
--- a/lib/Support/raw_ostream.cpp
+++ b/lib/Support/raw_ostream.cpp
@@ -121,7 +121,8 @@ raw_ostream &raw_ostream::operator<<(unsigned long N) {
raw_ostream &raw_ostream::operator<<(long N) {
if (N < 0) {
*this << '-';
- N = -N;
+ // Avoid undefined behavior on LONG_MIN with a cast.
+ N = -(unsigned long)N;
}
return this->operator<<(static_cast<unsigned long>(N));