diff --git a/lldb/source/Utility/Scalar.cpp b/lldb/source/Utility/Scalar.cpp index e94fd45962366..c70c5e1079918 100644 --- a/lldb/source/Utility/Scalar.cpp +++ b/lldb/source/Utility/Scalar.cpp @@ -134,9 +134,9 @@ size_t Scalar::GetByteSize() const { case e_void: break; case e_int: - return (m_integer.getBitWidth() / 8); + return (m_integer.getBitWidth() + 7) / 8; case e_float: - return m_float.bitcastToAPInt().getBitWidth() / 8; + return (m_float.bitcastToAPInt().getBitWidth() + 7) / 8; } return 0; } diff --git a/lldb/test/API/python_api/type/TestTypeList.py b/lldb/test/API/python_api/type/TestTypeList.py index 81c44f7a39d61..17e27b624511c 100644 --- a/lldb/test/API/python_api/type/TestTypeList.py +++ b/lldb/test/API/python_api/type/TestTypeList.py @@ -52,6 +52,19 @@ def _find_static_field_in_Task_pointer(self, task_pointer): self.DebugSBValue(value) self.assertEqual(value.GetValueAsSigned(), 47) + static_constexpr_bool_field = task_type.GetStaticFieldWithName( + "static_constexpr_bool_field" + ) + self.assertTrue(static_constexpr_bool_field) + self.assertEqual( + static_constexpr_bool_field.GetName(), "static_constexpr_bool_field" + ) + self.assertEqual(static_constexpr_bool_field.GetType().GetName(), "const bool") + + value = static_constexpr_bool_field.GetConstantValue(self.target()) + self.DebugSBValue(value) + self.assertEqual(value.GetValueAsUnsigned(), 1) + static_mutable_field = task_type.GetStaticFieldWithName("static_mutable_field") self.assertTrue(static_mutable_field) self.assertEqual(static_mutable_field.GetName(), "static_mutable_field") diff --git a/lldb/test/API/python_api/type/main.cpp b/lldb/test/API/python_api/type/main.cpp index c86644d918279..7384a3d8da16f 100644 --- a/lldb/test/API/python_api/type/main.cpp +++ b/lldb/test/API/python_api/type/main.cpp @@ -28,6 +28,7 @@ class Task { union U { } u; static constexpr long static_constexpr_field = 47; + static constexpr bool static_constexpr_bool_field = true; static int static_mutable_field; Task(int i, Task *n): id(i), diff --git a/lldb/unittests/Utility/ScalarTest.cpp b/lldb/unittests/Utility/ScalarTest.cpp index 8d957d16593ee..500cb8bb2286e 100644 --- a/lldb/unittests/Utility/ScalarTest.cpp +++ b/lldb/unittests/Utility/ScalarTest.cpp @@ -13,8 +13,11 @@ #include "lldb/Utility/Scalar.h" #include "lldb/Utility/Status.h" #include "lldb/Utility/StreamString.h" +#include "lldb/lldb-enumerations.h" +#include "llvm/ADT/APSInt.h" #include "llvm/Testing/Support/Error.h" +#include #include using namespace lldb_private; @@ -163,6 +166,33 @@ TEST(ScalarTest, GetBytes) { ASSERT_EQ(0, memcmp(f, Storage, sizeof(f))); } +TEST(ScalarTest, GetData) { + auto get_data = [](llvm::APSInt v) { + DataExtractor data; + Scalar(v).GetData(data); + return data.GetData().vec(); + }; + + auto vec = [](std::initializer_list l) { + std::vector v(l.begin(), l.end()); + if (endian::InlHostByteOrder() == lldb::eByteOrderLittle) + std::reverse(v.begin(), v.end()); + return v; + }; + + EXPECT_THAT( + get_data(llvm::APSInt::getMaxValue(/*numBits=*/1, /*Unsigned=*/true)), + vec({0x01})); + + EXPECT_THAT( + get_data(llvm::APSInt::getMaxValue(/*numBits=*/8, /*Unsigned=*/true)), + vec({0xff})); + + EXPECT_THAT( + get_data(llvm::APSInt::getMaxValue(/*numBits=*/9, /*Unsigned=*/true)), + vec({0x01, 0xff})); +} + TEST(ScalarTest, SetValueFromData) { uint8_t a[] = {1, 2, 3, 4}; Scalar s;