Avoid undefined behavior by masking the shift amount.

Should hopefully fix the mips bots.

llvm-svn: 222146
This commit is contained in:
Rafael Espindola 2014-11-17 17:43:27 +00:00
parent b23eb5e3f7
commit f70c673db7
1 changed files with 2 additions and 2 deletions

View File

@ -345,7 +345,7 @@ public:
// If the field is fully contained by CurWord, return it quickly. // If the field is fully contained by CurWord, return it quickly.
if (BitsInCurWord >= NumBits) { 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. // Use a mask to avoid undefined behavior.
CurWord >>= (NumBits & Mask); CurWord >>= (NumBits & Mask);
@ -363,7 +363,7 @@ public:
if (BitsLeft > BitsInCurWord) if (BitsLeft > BitsInCurWord)
return 0; 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. // Use a mask to avoid undefined behavior.
CurWord >>= (BitsLeft & Mask); CurWord >>= (BitsLeft & Mask);