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

Tim Shen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 15 17:46:52 PST 2018


This revision was not accepted when it landed; it landed in state "Needs Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL325311: [APInt] Fix extractBits to correctly handle Result.isSingleWord() case. (authored by timshen, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D43363?vs=134532&id=134539#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D43363

Files:
  llvm/trunk/lib/Support/APInt.cpp
  llvm/trunk/unittests/ADT/APIntTest.cpp


Index: llvm/trunk/lib/Support/APInt.cpp
===================================================================
--- llvm/trunk/lib/Support/APInt.cpp
+++ llvm/trunk/lib/Support/APInt.cpp
@@ -428,11 +428,12 @@
   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();
Index: llvm/trunk/unittests/ADT/APIntTest.cpp
===================================================================
--- llvm/trunk/unittests/ADT/APIntTest.cpp
+++ llvm/trunk/unittests/ADT/APIntTest.cpp
@@ -1768,6 +1768,13 @@
             i257.extractBits(128, 1).getSExtValue());
   EXPECT_EQ(static_cast<int64_t>(0xFFFFFFFFFF80007Full),
             i257.extractBits(129, 1).getSExtValue());
+
+  EXPECT_EQ(APInt(48, 0),
+            APInt(144, "281474976710655", 10).extractBits(48, 48));
+  EXPECT_EQ(APInt(48, 0x0000ffffffffffffull),
+            APInt(144, "281474976710655", 10).extractBits(48, 0));
+  EXPECT_EQ(APInt(48, 0x00007fffffffffffull),
+            APInt(144, "281474976710655", 10).extractBits(48, 1));
 }
 
 TEST(APIntTest, getLowBitsSet) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43363.134539.patch
Type: text/x-patch
Size: 1526 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180216/db6182a9/attachment.bin>


More information about the llvm-commits mailing list