From: Rafael Espindola Date: Mon, 17 Nov 2014 17:43:27 +0000 (+0000) Subject: Avoid undefined behavior by masking the shift amount. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f70c673db75b71756251e5647e7714ecd345340c;p=platform%2Fupstream%2Fllvm.git Avoid undefined behavior by masking the shift amount. Should hopefully fix the mips bots. llvm-svn: 222146 --- diff --git a/llvm/include/llvm/Bitcode/BitstreamReader.h b/llvm/include/llvm/Bitcode/BitstreamReader.h index a4d2b1d..d6f085c 100644 --- a/llvm/include/llvm/Bitcode/BitstreamReader.h +++ b/llvm/include/llvm/Bitcode/BitstreamReader.h @@ -345,7 +345,7 @@ public: // If the field is fully contained by CurWord, return it quickly. if (BitsInCurWord >= NumBits) { - word_t R = CurWord & ((word_t(1) << NumBits) - 1); + word_t R = CurWord & ((word_t(1) << (NumBits & Mask)) - 1); // Use a mask to avoid undefined behavior. CurWord >>= (NumBits & Mask); @@ -363,7 +363,7 @@ public: if (BitsLeft > BitsInCurWord) return 0; - word_t R2 = CurWord & ((word_t(1) << BitsLeft) - 1); + word_t R2 = CurWord & ((word_t(1) << (BitsLeft & Mask)) - 1); // Use a mask to avoid undefined behavior. CurWord >>= (BitsLeft & Mask);