llvm.org GIT mirror llvm / 29e8a62
Avoid undefined behavior by masking the shift amount. Should hopefully fix the mips bots. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222146 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 6 years ago
1 changed file(s) with 2 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
344344
345345 // If the field is fully contained by CurWord, return it quickly.
346346 if (BitsInCurWord >= NumBits) {
347 word_t R = CurWord & ((word_t(1) << NumBits) - 1);
347 word_t R = CurWord & ((word_t(1) << (NumBits & Mask)) - 1);
348348
349349 // Use a mask to avoid undefined behavior.
350350 CurWord >>= (NumBits & Mask);
362362 if (BitsLeft > BitsInCurWord)
363363 return 0;
364364
365 word_t R2 = CurWord & ((word_t(1) << BitsLeft) - 1);
365 word_t R2 = CurWord & ((word_t(1) << (BitsLeft & Mask)) - 1);
366366
367367 // Use a mask to avoid undefined behavior.
368368 CurWord >>= (BitsLeft & Mask);