[llvm-commits] [llvm] r141905 - /llvm/trunk/lib/Support/raw_ostream.cpp

Eli Friedman eli.friedman at gmail.com
Thu Oct 13 15:49:56 PDT 2011


Author: efriedma
Date: Thu Oct 13 17:49:56 2011
New Revision: 141905

URL: http://llvm.org/viewvc/llvm-project?rev=141905&view=rev
Log:
Avoid undefined behavior in signed integer negation.  Patch by Ahmed Charles.


Modified:
    llvm/trunk/lib/Support/raw_ostream.cpp

Modified: llvm/trunk/lib/Support/raw_ostream.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/raw_ostream.cpp?rev=141905&r1=141904&r2=141905&view=diff
==============================================================================
--- llvm/trunk/lib/Support/raw_ostream.cpp (original)
+++ llvm/trunk/lib/Support/raw_ostream.cpp Thu Oct 13 17:49:56 2011
@@ -121,7 +121,8 @@
 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));





More information about the llvm-commits mailing list