[Lldb-commits] [lldb] 00c8120 - [LLDB] Fix handling of bit-fields when there is a base class when parsing DWARF
via lldb-commits
lldb-commits at lists.llvm.org
Fri Mar 27 11:28:22 PDT 2020
Author: shafik
Date: 2020-03-27T11:28:07-07:00
New Revision: 00c8120acbac3430c3594c5b6ca3527ef9c1afca
URL: https://github.com/llvm/llvm-project/commit/00c8120acbac3430c3594c5b6ca3527ef9c1afca
DIFF: https://github.com/llvm/llvm-project/commit/00c8120acbac3430c3594c5b6ca3527ef9c1afca.diff
LOG: [LLDB] Fix handling of bit-fields when there is a base class when parsing DWARF
When parsing DWARF and laying out bit-fields we currently don't take into account whether we have a base class or not.
Currently if the first field is a bit-field but the bit offset is due a field we inherit from a base class we currently
treat it as an unnamed bit-field and therefore add an extra field.
This fix will not check if we have a base class and assume that this offset is due to members we are inheriting from the base.
We are currently seeing asserts during codegen when debugging clang::DiagnosticOptions.
This assumption will fail in the case where the first field in the derived class in an unnamed bit-field. Fixing the first field
being an unnamed bit-field looks like it will require a larger change since we will need a way to track or discover the last field offset of the bases(s).
Differential Revision: https://reviews.llvm.org/D76808
Added:
Modified:
lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
lldb/test/API/lang/cpp/bitfields/TestCppBitfields.py
lldb/test/API/lang/cpp/bitfields/main.cpp
Removed:
################################################################################
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 8838888b2e23..760933bf898e 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -2668,9 +2668,19 @@ void DWARFASTParserClang::ParseSingleMember(
}
// If we have a gap between the last_field_end and the current
- // field we have an unnamed bit-field
+ // field we have an unnamed bit-field.
+ // If we have a base class, we assume there is no unnamed
+ // bit-field if this is the first field since the gap can be
+ // attributed to the members from the base class. This assumption
+ // is not correct if the first field of the derived class is
+ // indeed an unnamed bit-field. We currently do not have the
+ // machinary to track the offset of the last field of classes we
+ // have seen before, so we are not handling this case.
if (this_field_info.bit_offset != last_field_end &&
- !(this_field_info.bit_offset < last_field_end)) {
+ this_field_info.bit_offset > last_field_end &&
+ !(last_field_info.bit_offset == 0 &&
+ last_field_info.bit_size == 0 &&
+ layout_info.base_offsets.size() != 0)) {
unnamed_field_info = FieldInfo{};
unnamed_field_info->bit_size =
this_field_info.bit_offset - last_field_end;
diff --git a/lldb/test/API/lang/cpp/bitfields/TestCppBitfields.py b/lldb/test/API/lang/cpp/bitfields/TestCppBitfields.py
index 1b362e6b04f9..7320ce2b816e 100644
--- a/lldb/test/API/lang/cpp/bitfields/TestCppBitfields.py
+++ b/lldb/test/API/lang/cpp/bitfields/TestCppBitfields.py
@@ -103,3 +103,10 @@ def test_and_run_command(self):
'(uint64_t:1) k = 1',
])
+ self.expect(
+ "frame variable --show-types derived",
+ VARIABLES_DISPLAYED_CORRECTLY,
+ substrs=[
+ '(uint32_t) b_a = 2',
+ '(uint32_t:1) d_a = 1',
+ ])
diff --git a/lldb/test/API/lang/cpp/bitfields/main.cpp b/lldb/test/API/lang/cpp/bitfields/main.cpp
index e43bf8c138e9..986b7cb947ed 100644
--- a/lldb/test/API/lang/cpp/bitfields/main.cpp
+++ b/lldb/test/API/lang/cpp/bitfields/main.cpp
@@ -60,6 +60,16 @@ int main(int argc, char const *argv[]) {
}
} clang_example;
+ class B {
+ public:
+ uint32_t b_a;
+ };
+
+ class D : public B {
+ public:
+ uint32_t d_a : 1;
+ } derived;
+
lba.a = 2;
lbb.a = 1;
@@ -76,6 +86,8 @@ int main(int argc, char const *argv[]) {
lbd.arr[2] = '\0';
lbd.a = 5;
+ derived.b_a = 2;
+ derived.d_a = 1;
return 0; // Set break point at this line.
}
More information about the lldb-commits
mailing list