From f6bef488eeab75b6c7746f9faa9731d45bb84aef Mon Sep 17 00:00:00 2001 From: Reid Spencer Date: Sun, 25 Mar 2007 21:58:42 +0000 Subject: [PATCH] Compute getLowBitsSet correctly. Using the complement of a 64-bit value and shifting down without regard for the bitwidth of the APInt can lead to incorrect initialization values. Instead, check for the word size case (to avoid undef results from shift) and then do (1 << loBitsSet) - 1 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35344 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ADT/APInt.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/include/llvm/ADT/APInt.h b/include/llvm/ADT/APInt.h index b39cf78b985..25ea4a2bd5d 100644 --- a/include/llvm/ADT/APInt.h +++ b/include/llvm/ADT/APInt.h @@ -374,11 +374,12 @@ public: // Handle a degenerate case, to avoid shifting by word size if (loBitsSet == 0) return APInt(numBits, 0); - uint32_t shiftAmt = numBits - loBitsSet; + if (loBitsSet == APINT_BITS_PER_WORD) + return APInt(numBits, -1ULL); // For small values, return quickly - if (numBits <= APINT_BITS_PER_WORD) - return APInt(numBits, ~0ULL >> shiftAmt); - return (~APInt(numBits, 0)).lshr(shiftAmt); + if (numBits < APINT_BITS_PER_WORD) + return APInt(numBits, (1ULL << loBitsSet) - 1); + return (~APInt(numBits, 0)).lshr(numBits - loBitsSet); } /// The hash value is computed as the sum of the words and the bit width. -- 2.11.0