[Scalar] Fix assignment operator for long long.
authorAndy Yankovsky <weratt@gmail.com>
Wed, 3 Jun 2020 11:08:00 +0000 (13:08 +0200)
committerPavel Labath <pavel@labath.sk>
Wed, 3 Jun 2020 11:26:25 +0000 (13:26 +0200)
Summary:
Assignment operator `operator=(long long)` currently allocates `sizeof(long)`.
On some platforms it works as they have `sizeof(long) == sizeof(long long)`,
but on others (e.g. Windows) it's not the case.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D80995

lldb/source/Utility/Scalar.cpp
lldb/unittests/Utility/ScalarTest.cpp

index b6db5cc..e55aa2d 100644 (file)
@@ -331,7 +331,7 @@ Scalar &Scalar::operator=(unsigned long v) {
 
 Scalar &Scalar::operator=(long long v) {
   m_type = e_slonglong;
-  m_integer = llvm::APInt(sizeof(long) * 8, v, true);
+  m_integer = llvm::APInt(sizeof(long long) * 8, v, true);
   return *this;
 }
 
index f62173f..baf1de9 100644 (file)
@@ -188,6 +188,16 @@ TEST(ScalarTest, GetValue) {
             ScalarGetValue(std::numeric_limits<unsigned long long>::max()));
 }
 
+TEST(ScalarTest, LongLongAssigmentOperator) {
+  Scalar ull;
+  ull = std::numeric_limits<unsigned long long>::max();
+  EXPECT_EQ(std::numeric_limits<unsigned long long>::max(), ull.ULongLong());
+
+  Scalar sll;
+  sll = std::numeric_limits<signed long long>::max();
+  EXPECT_EQ(std::numeric_limits<signed long long>::max(), sll.SLongLong());
+}
+
 TEST(ScalarTest, Division) {
   Scalar lhs(5.0);
   Scalar rhs(2.0);