[Lldb-commits] [PATCH] D80995: [Scalar] Fix assignment operator for long long.

Andy Yankovsky via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Jun 2 05:31:21 PDT 2020


werat created this revision.
werat added a reviewer: labath.
werat added a project: LLDB.
werat added a reviewer: teemperor.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80995

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


Index: lldb/unittests/Utility/ScalarTest.cpp
===================================================================
--- lldb/unittests/Utility/ScalarTest.cpp
+++ lldb/unittests/Utility/ScalarTest.cpp
@@ -188,6 +188,16 @@
             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);
Index: lldb/source/Utility/Scalar.cpp
===================================================================
--- lldb/source/Utility/Scalar.cpp
+++ lldb/source/Utility/Scalar.cpp
@@ -331,7 +331,7 @@
 
 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;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80995.267852.patch
Type: text/x-patch
Size: 1125 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20200602/3fdc9f84/attachment.bin>


More information about the lldb-commits mailing list