[llvm] r216116 - Fix undefined behavior (left shift by 64 bits) in ScaledNumber::toString().

Alexey Samsonov vonosmas at gmail.com
Wed Aug 20 11:30:07 PDT 2014


Author: samsonov
Date: Wed Aug 20 13:30:07 2014
New Revision: 216116

URL: http://llvm.org/viewvc/llvm-project?rev=216116&view=rev
Log:
Fix undefined behavior (left shift by 64 bits) in ScaledNumber::toString().

This bug is reported by UBSan.

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

Modified: llvm/trunk/lib/Support/ScaledNumber.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/ScaledNumber.cpp?rev=216116&r1=216115&r2=216116&view=diff
==============================================================================
--- llvm/trunk/lib/Support/ScaledNumber.cpp (original)
+++ llvm/trunk/lib/Support/ScaledNumber.cpp Wed Aug 20 13:30:07 2014
@@ -220,6 +220,9 @@ std::string ScaledNumberBase::toString(u
   } else if (E > -64) {
     Above0 = D >> -E;
     Below0 = D << (64 + E);
+  } else if (E == -64) {
+    // Special case: shift by 64 bits is undefined behavior.
+    Below0 = D;
   } else if (E > -120) {
     Below0 = D >> (-E - 64);
     Extra = D << (128 + E);





More information about the llvm-commits mailing list