diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp @@ -5097,7 +5097,9 @@ case clang::Type::Record: break; case clang::Type::Enum: - return lldb::eEncodingSint; + return qual_type->isUnsignedIntegerOrEnumerationType() + ? lldb::eEncodingUint + : lldb::eEncodingSint; case clang::Type::DependentSizedArray: case clang::Type::DependentSizedExtVector: case clang::Type::UnresolvedUsing: diff --git a/lldb/test/API/python_api/sbvalue_unsigned_enum_bitfield_value/TestSBValueUnsignedEnumBitField.py b/lldb/test/API/python_api/sbvalue_unsigned_enum_bitfield_value/TestSBValueUnsignedEnumBitField.py new file mode 100644 --- /dev/null +++ b/lldb/test/API/python_api/sbvalue_unsigned_enum_bitfield_value/TestSBValueUnsignedEnumBitField.py @@ -0,0 +1,18 @@ +""" +Test that SBValue doesn't incorrectly sign-extend +the Scalar value of a bitfield that has an unsigned +enum type. + +We test this by assigning to a bit-field a value +that is out-of-range of it's signed counterpart. +I.e., with a bit-field of width 4, assigning +8 to it would be out-of-range if we treated it +as a signed. If LLDB were to sign-extend the Scalar +(which shouldn't happen for unsigned bit-fields) +it would left-fill the result with 1s; we test +for this not to happen. +""" + +import lldbsuite.test.lldbinline as lldbinline + +lldbinline.MakeInlineTest(__file__, globals()) diff --git a/lldb/test/API/python_api/sbvalue_unsigned_enum_bitfield_value/main.cpp b/lldb/test/API/python_api/sbvalue_unsigned_enum_bitfield_value/main.cpp new file mode 100644 --- /dev/null +++ b/lldb/test/API/python_api/sbvalue_unsigned_enum_bitfield_value/main.cpp @@ -0,0 +1,14 @@ +#include + +enum class EnumVals : uint16_t { VAL0 = 0 }; + +struct Foo { + EnumVals b : 4; +}; + +int main(int argc, char const *argv[], char const *envp[]) { + Foo f{.b = static_cast(8)}; + return 0; //% b = self.frame().FindVariable("f").GetChildMemberWithName("b") + //% val = b.GetValueAsUnsigned() + //% self.assertEqual(val, 8, "Bit-field not correctly extracted") +}