diff options
author | Tim Shen <timshen91@gmail.com> | 2018-02-16 01:44:36 +0000 |
---|---|---|
committer | Tim Shen <timshen91@gmail.com> | 2018-02-16 01:44:36 +0000 |
commit | 89337750a0286ac970738ac22a8462d82008b09f (patch) | |
tree | 53c022d3515c555a21e64beea4c972802096470c /llvm/lib/Support/APInt.cpp | |
parent | 3dc6de619a7a5778c1338187d3181ac5613b3959 (diff) | |
download | bcm5719-llvm-89337750a0286ac970738ac22a8462d82008b09f.tar.gz bcm5719-llvm-89337750a0286ac970738ac22a8462d82008b09f.zip |
[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
llvm-svn: 325311
Diffstat (limited to 'llvm/lib/Support/APInt.cpp')
-rw-r--r-- | llvm/lib/Support/APInt.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp index 1ea6319acfa..48b9613b3ec 100644 --- a/llvm/lib/Support/APInt.cpp +++ b/llvm/lib/Support/APInt.cpp @@ -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(); |