[llvm] r246836 - Fix APInt value initialization to give a zero value as any sane integer type
Richard Smith via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 3 21:08:37 PDT 2015
Author: rsmith
Date: Thu Sep 3 23:08:36 2015
New Revision: 246836
URL: http://llvm.org/viewvc/llvm-project?rev=246836&view=rev
Log:
Fix APInt value initialization to give a zero value as any sane integer type
should, rather than giving a broken value that doesn't even zero/sign-extend
properly.
Modified:
llvm/trunk/include/llvm/ADT/APInt.h
llvm/trunk/unittests/ADT/APIntTest.cpp
Modified: llvm/trunk/include/llvm/ADT/APInt.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/APInt.h?rev=246836&r1=246835&r2=246836&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/APInt.h (original)
+++ llvm/trunk/include/llvm/ADT/APInt.h Thu Sep 3 23:08:36 2015
@@ -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(); }
Modified: llvm/trunk/unittests/ADT/APIntTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/APIntTest.cpp?rev=246836&r1=246835&r2=246836&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/APIntTest.cpp (original)
+++ llvm/trunk/unittests/ADT/APIntTest.cpp Thu Sep 3 23:08:36 2015
@@ -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;
More information about the llvm-commits
mailing list