[APInt] Fix extractBits to correctly handle Result.isSingleWord() case.

Summary: extractBits assumes that `!this->isSingleWord() implies !Result.isSingleWord()`, which may not necessarily be true. Handle both cases.

Reviewers: RKSimon

Subscribers: sanjoy, llvm-commits, hiraditya

Differential Revision: https://reviews.llvm.org/D43363

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@325311 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Tim Shen
2018-02-16 01:44:36 +00:00
parent 4f9b553009
commit 6e5a3d77a3
2 changed files with 9 additions and 1 deletions
+2 -1
View File
@@ -428,11 +428,12 @@ APInt APInt::extractBits(unsigned numBits, unsigned bitPosition) const {
unsigned NumSrcWords = getNumWords();
unsigned NumDstWords = Result.getNumWords();
uint64_t *DestPtr = Result.isSingleWord() ? &Result.U.VAL : Result.U.pVal;
for (unsigned word = 0; word < NumDstWords; ++word) {
uint64_t w0 = U.pVal[loWord + word];
uint64_t w1 =
(loWord + word + 1) < NumSrcWords ? U.pVal[loWord + word + 1] : 0;
Result.U.pVal[word] = (w0 >> loBit) | (w1 << (APINT_BITS_PER_WORD - loBit));
DestPtr[word] = (w0 >> loBit) | (w1 << (APINT_BITS_PER_WORD - loBit));
}
return Result.clearUnusedBits();