diff --git a/llvm/include/llvm/ADT/APInt.h b/llvm/include/llvm/ADT/APInt.h --- a/llvm/include/llvm/ADT/APInt.h +++ b/llvm/include/llvm/ADT/APInt.h @@ -1458,10 +1458,8 @@ /// uint64_t. The bitwidth must be <= 64 or the value must fit within a /// uint64_t. Otherwise an assertion will result. uint64_t getZExtValue() const { - if (isSingleWord()) { - assert(BitWidth && "zero width values not allowed"); + if (isSingleWord()) return U.VAL; - } assert(getActiveBits() <= 64 && "Too many bits for uint64_t"); return U.pVal[0]; } diff --git a/llvm/unittests/ADT/APIntTest.cpp b/llvm/unittests/ADT/APIntTest.cpp --- a/llvm/unittests/ADT/APIntTest.cpp +++ b/llvm/unittests/ADT/APIntTest.cpp @@ -3054,6 +3054,9 @@ EXPECT_EQ(0U, APInt(4, 3).trunc(0).getBitWidth()); EXPECT_TRUE(ZW.isAllOnes()); + // Zero extension. + EXPECT_EQ(0U, ZW.getZExtValue()); + SmallString<42> STR; ZW.toStringUnsigned(STR); EXPECT_EQ("0", STR);