Author: Andy Yankovsky Date: 2021-05-19T15:32:17+02:00 New Revision: 0bab7b26f4d9dc4cb8f6c2877ad4a2c388c41c65
URL: https://github.com/llvm/llvm-project/commit/0bab7b26f4d9dc4cb8f6c2877ad4a2c388c41c65 DIFF: https://github.com/llvm/llvm-project/commit/0bab7b26f4d9dc4cb8f6c2877ad4a2c388c41c65.diff LOG: [lldb] Encode `bool` as unsigned int `bool` is considered to be unsigned according to `std::is_unsigned<bool>::value` (and `Type::GetTypeInfo`). Encoding it as signed int works fine for normal variables and fields, but breaks when reading the values of boolean bitfields. If the field is declared as `bool b : 1` and has a value of `0b1`, the call to `SBValue::GetValueAsSigned()` will return `-1`. Reviewed By: teemperor Differential Revision: https://reviews.llvm.org/D102685 Added: Modified: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp lldb/test/API/lang/cpp/bitfields/TestCppBitfields.py lldb/test/API/lang/cpp/bitfields/main.cpp Removed: ################################################################################ diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp index 7e037a1589f16..51e53f0bab561 100644 --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp @@ -4698,7 +4698,6 @@ lldb::Encoding TypeSystemClang::GetEncoding(lldb::opaque_compiler_type_t type, case clang::BuiltinType::Void: break; - case clang::BuiltinType::Bool: case clang::BuiltinType::Char_S: case clang::BuiltinType::SChar: case clang::BuiltinType::WChar_S: @@ -4709,6 +4708,7 @@ lldb::Encoding TypeSystemClang::GetEncoding(lldb::opaque_compiler_type_t type, case clang::BuiltinType::Int128: return lldb::eEncodingSint; + case clang::BuiltinType::Bool: case clang::BuiltinType::Char_U: case clang::BuiltinType::UChar: case clang::BuiltinType::WChar_U: diff --git a/lldb/test/API/lang/cpp/bitfields/TestCppBitfields.py b/lldb/test/API/lang/cpp/bitfields/TestCppBitfields.py index 0585cf60951b6..bf457d33a0bd1 100644 --- a/lldb/test/API/lang/cpp/bitfields/TestCppBitfields.py +++ b/lldb/test/API/lang/cpp/bitfields/TestCppBitfields.py @@ -120,3 +120,36 @@ def test_and_run_command(self): '(uint32_t) b_a = 2', '(uint32_t:1) d_a = 1', ]) + + self.expect( + "frame variable --show-types bb", + VARIABLES_DISPLAYED_CORRECTLY, + substrs=[ + '(bool:1) a = true', + '(bool:1) b = false', + '(bool:2) c = true', + '(bool:2) d = true', + ]) + + bb = self.frame().FindVariable('bb') + self.assertTrue(bb.IsValid()) + + bb_a = bb.GetChildAtIndex(0) + self.assertTrue(bb_a.IsValid()) + self.assertEqual(bb_a.GetValueAsUnsigned(), 1) + self.assertEqual(bb_a.GetValueAsSigned(), 1) + + bb_b = bb.GetChildAtIndex(1) + self.assertTrue(bb_b.IsValid()) + self.assertEqual(bb_b.GetValueAsUnsigned(), 0) + self.assertEqual(bb_b.GetValueAsSigned(), 0) + + bb_c = bb.GetChildAtIndex(2) + self.assertTrue(bb_c.IsValid()) + self.assertEqual(bb_c.GetValueAsUnsigned(), 1) + self.assertEqual(bb_c.GetValueAsSigned(), 1) + + bb_d = bb.GetChildAtIndex(3) + self.assertTrue(bb_d.IsValid()) + self.assertEqual(bb_d.GetValueAsUnsigned(), 1) + self.assertEqual(bb_d.GetValueAsSigned(), 1) diff --git a/lldb/test/API/lang/cpp/bitfields/main.cpp b/lldb/test/API/lang/cpp/bitfields/main.cpp index f9015b758c724..a9887b5e826e9 100644 --- a/lldb/test/API/lang/cpp/bitfields/main.cpp +++ b/lldb/test/API/lang/cpp/bitfields/main.cpp @@ -104,5 +104,17 @@ int main(int argc, char const *argv[]) { uwbf.x = 0xFFFFFFFF; uwubf.x = 0xFFFFFFFF; + struct BoolBits { + bool a : 1; + bool b : 1; + bool c : 2; + bool d : 2; + } bb; + + bb.a = 0b1; + bb.b = 0b0; + bb.c = 0b11; + bb.d = 0b01; + return 0; // Set break point at this line. } _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits