llvm.org GIT mirror llvm / 35b1423
ADT: Correct APInt::getActiveWords for zero values PR15138 was opened because of a segfault in the Bitcode writer. The actual issue ended up being a bug in APInt where calls to APInt::getActiveWords returns a bogus value when the APInt value is 0. This patch fixes the problem by ensuring that getActiveWords returns 1 for 0 valued APInts. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@174641 91177308-0d34-0410-b5e6-96231b3b80d8 Meador Inge 6 years ago
2 changed file(s) with 10 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
11901190 /// APInt. This is used in conjunction with getActiveData to extract the raw
11911191 /// value of the APInt.
11921192 unsigned getActiveWords() const {
1193 return whichWord(getActiveBits()-1) + 1;
1193 unsigned numActiveBits = getActiveBits();
1194 return numActiveBits ? whichWord(numActiveBits - 1) + 1 : 1;
11941195 }
11951196
11961197 /// Computes the minimum bit width for this APInt while considering it to be
5555 #endif
5656
5757 TEST(APIntTest, i65_Count) {
58 APInt i65(65, 0, true);
59 EXPECT_EQ(65u, i65.countLeadingZeros());
60 EXPECT_EQ(0u, i65.countLeadingOnes());
61 EXPECT_EQ(0u, i65.getActiveBits());
62 EXPECT_EQ(1u, i65.getActiveWords());
63 EXPECT_EQ(65u, i65.countTrailingZeros());
64 EXPECT_EQ(0u, i65.countPopulation());
65
5866 APInt i65minus(65, 0, true);
5967 i65minus.setBit(64);
6068 EXPECT_EQ(0u, i65minus.countLeadingZeros());