[llvm] r222146 - Avoid undefined behavior by masking the shift amount.
Rafael Espindola
rafael.espindola at gmail.com
Mon Nov 17 09:43:27 PST 2014
Author: rafael
Date: Mon Nov 17 11:43:27 2014
New Revision: 222146
URL: http://llvm.org/viewvc/llvm-project?rev=222146&view=rev
Log:
Avoid undefined behavior by masking the shift amount.
Should hopefully fix the mips bots.
Modified:
llvm/trunk/include/llvm/Bitcode/BitstreamReader.h
Modified: llvm/trunk/include/llvm/Bitcode/BitstreamReader.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Bitcode/BitstreamReader.h?rev=222146&r1=222145&r2=222146&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Bitcode/BitstreamReader.h (original)
+++ llvm/trunk/include/llvm/Bitcode/BitstreamReader.h Mon Nov 17 11:43:27 2014
@@ -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);
More information about the llvm-commits
mailing list