[llvm] r237345 - TableGen: Avoid undefined behaviour by doing this shift in int64

Justin Bogner mail at justinbogner.com
Wed May 13 23:47:03 PDT 2015


Author: bogner
Date: Thu May 14 01:47:02 2015
New Revision: 237345

URL: http://llvm.org/viewvc/llvm-project?rev=237345&view=rev
Log:
TableGen: Avoid undefined behaviour by doing this shift in int64

Found by ubsan. This was taking a bool and left shifting by 32 - the
result is 64 bit, so we should really do the math in a type it fits
in.

Modified:
    llvm/trunk/lib/TableGen/Record.cpp

Modified: llvm/trunk/lib/TableGen/Record.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/Record.cpp?rev=237345&r1=237344&r2=237345&view=diff
==============================================================================
--- llvm/trunk/lib/TableGen/Record.cpp (original)
+++ llvm/trunk/lib/TableGen/Record.cpp Thu May 14 01:47:02 2015
@@ -230,7 +230,7 @@ Init *IntRecTy::convertValue(BitsInit *B
   int64_t Result = 0;
   for (unsigned i = 0, e = BI->getNumBits(); i != e; ++i)
     if (BitInit *Bit = dyn_cast<BitInit>(BI->getBit(i)))
-      Result |= Bit->getValue() << i;
+      Result |= static_cast<int64_t>(Bit->getValue()) << i;
     else
       return nullptr;
   return IntInit::get(Result);





More information about the llvm-commits mailing list