From 29e8a627ba757eb9140cd3b1d550c35580308405 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Mon, 17 Nov 2014 17:43:27 +0000 Subject: [PATCH] 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 --- include/llvm/Bitcode/BitstreamReader.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/llvm/Bitcode/BitstreamReader.h b/include/llvm/Bitcode/BitstreamReader.h index a4d2b1d8b4c..d6f085c6491 100644 --- a/include/llvm/Bitcode/BitstreamReader.h +++ b/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); -- 2.34.1