Author: davide Date: Thu Jan 24 12:55:12 2019 New Revision: 352103 URL: http://llvm.org/viewvc/llvm-project?rev=352103&view=rev Log: [Scalar] Clarify the constructor from APInt and document through a test.
I want to add 512-bits support but I first want to make sure I'm not breaking anything obvious. This is the first of a series of commit adding tests. The first oddity found is that Scalar from APInt(s) always constructed signed. Maybe at some point we want to revisit this, but at least now we have a test to document how the API behaves. <rdar://problem/46886288> Modified: lldb/trunk/include/lldb/Utility/Scalar.h lldb/trunk/unittests/Utility/ScalarTest.cpp Modified: lldb/trunk/include/lldb/Utility/Scalar.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/Scalar.h?rev=352103&r1=352102&r2=352103&view=diff ============================================================================== --- lldb/trunk/include/lldb/Utility/Scalar.h (original) +++ lldb/trunk/include/lldb/Utility/Scalar.h Thu Jan 24 12:55:12 2019 @@ -12,6 +12,7 @@ #include "lldb/Utility/Status.h" #include "lldb/lldb-enumerations.h" #include "lldb/lldb-private-types.h" +#include "lldb/Utility/LLDBAssert.h" #include "llvm/ADT/APFloat.h" #include "llvm/ADT/APInt.h" #include <cstddef> @@ -97,30 +98,19 @@ public: case 8: case 16: case 32: - if (m_integer.isSignedIntN(sizeof(sint_t) * 8)) - m_type = e_sint; - else - m_type = e_uint; - break; + m_type = e_sint; + return; case 64: - if (m_integer.isSignedIntN(sizeof(slonglong_t) * 8)) - m_type = e_slonglong; - else - m_type = e_ulonglong; - break; + m_type = e_slonglong; + return; case 128: - if (m_integer.isSignedIntN(BITWIDTH_INT128)) - m_type = e_sint128; - else - m_type = e_uint128; - break; + m_type = e_sint128; + return; case 256: - if (m_integer.isSignedIntN(BITWIDTH_INT256)) - m_type = e_sint256; - else - m_type = e_uint256; - break; + m_type = e_sint256; + return; } + lldbassert(false && "unsupported bitwidth"); } Scalar(const Scalar &rhs); // Scalar(const RegisterValue& reg_value); Modified: lldb/trunk/unittests/Utility/ScalarTest.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Utility/ScalarTest.cpp?rev=352103&r1=352102&r2=352103&view=diff ============================================================================== --- lldb/trunk/unittests/Utility/ScalarTest.cpp (original) +++ lldb/trunk/unittests/Utility/ScalarTest.cpp Thu Jan 24 12:55:12 2019 @@ -263,3 +263,18 @@ TEST(ScalarTest, SetValueFromCString) { a.SetValueFromCString("-123", lldb::eEncodingUint, 8).ToError(), Failed()); } + +TEST(ScalarTest, APIntConstructor) { + auto width_array = {8, 16, 32}; + for (auto &w : width_array) { + Scalar A(APInt(w, 24)); + EXPECT_EQ(A.GetType(), Scalar::e_sint); + } + + Scalar B(APInt(64, 42)); + EXPECT_EQ(B.GetType(), Scalar::e_slonglong); + Scalar C(APInt(128, 96)); + EXPECT_EQ(C.GetType(), Scalar::e_sint128); + Scalar D(APInt(256, 156)); + EXPECT_EQ(D.GetType(), Scalar::e_sint256); +} _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits