diff options
-rw-r--r-- | llvm/include/llvm/ADT/APInt.h | 5 | ||||
-rw-r--r-- | llvm/unittests/ADT/APIntTest.cpp | 7 |
2 files changed, 10 insertions, 2 deletions
diff --git a/llvm/include/llvm/ADT/APInt.h b/llvm/include/llvm/ADT/APInt.h index ea67e7928a7..e2a0cb5e69d 100644 --- a/llvm/include/llvm/ADT/APInt.h +++ b/llvm/include/llvm/ADT/APInt.h @@ -294,11 +294,12 @@ public: delete[] pVal; } - /// \brief Default constructor that creates an uninitialized APInt. + /// \brief Default constructor that creates an uninteresting APInt + /// representing a 1-bit zero value. /// /// This is useful for object deserialization (pair this with the static /// method Read). - explicit APInt() : BitWidth(1) {} + explicit APInt() : BitWidth(1), VAL(0) {} /// \brief Returns whether this instance allocated memory. bool needsCleanup() const { return !isSingleWord(); } diff --git a/llvm/unittests/ADT/APIntTest.cpp b/llvm/unittests/ADT/APIntTest.cpp index ffba7b16336..0002dad8555 100644 --- a/llvm/unittests/ADT/APIntTest.cpp +++ b/llvm/unittests/ADT/APIntTest.cpp @@ -17,6 +17,13 @@ using namespace llvm; namespace { +TEST(APIntTest, ValueInit) { + APInt Zero = APInt(); + EXPECT_TRUE(!Zero); + EXPECT_TRUE(!Zero.zext(64)); + EXPECT_TRUE(!Zero.sext(64)); +} + // Test that APInt shift left works when bitwidth > 64 and shiftamt == 0 TEST(APIntTest, ShiftLeftByZero) { APInt One = APInt::getNullValue(65) + 1; |