[Lldb-commits] [lldb] bae9aed - [LLDB] Fix handling of bit-fields in a union

via lldb-commits lldb-commits at lists.llvm.org
Thu Nov 12 14:09:37 PST 2020


Author: shafik
Date: 2020-11-12T14:09:27-08:00
New Revision: bae9aedb341c5f4eceafba2ee1fec7c05d842c97

URL: https://github.com/llvm/llvm-project/commit/bae9aedb341c5f4eceafba2ee1fec7c05d842c97
DIFF: https://github.com/llvm/llvm-project/commit/bae9aedb341c5f4eceafba2ee1fec7c05d842c97.diff

LOG: [LLDB] Fix handling of bit-fields in a union

When parsing DWARF and laying out bit-fields we don't properly take into account when they are in a union, they will all have a zero offset.

Differential Revision: https://reviews.llvm.org/D91118

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 2003a24c04fa..6633acd70a50 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -2581,7 +2581,11 @@ void DWARFASTParserClang::ParseSingleMember(
           // The ObjC runtime knows the byte offset but we still need to provide
           // the bit-offset in the layout. It just means something 
diff erent then
           // what it does in C and C++. So we skip this check for ObjC types.
+          //
+          // We also skip this for fields of a union since they will all have a
+          // zero offset.
           if (!TypeSystemClang::IsObjCObjectOrInterfaceType(class_clang_type) &&
+              !(parent_die.Tag() == DW_TAG_union_type && this_field_info.bit_offset == 0) &&
               ((this_field_info.bit_offset >= parent_bit_size) ||
                (last_field_info.IsBitfield() &&
                 !last_field_info.NextBitfieldOffsetIsValid(

diff  --git a/lldb/test/API/lang/cpp/bitfields/TestCppBitfields.py b/lldb/test/API/lang/cpp/bitfields/TestCppBitfields.py
index 7320ce2b816e..0585cf60951b 100644
--- a/lldb/test/API/lang/cpp/bitfields/TestCppBitfields.py
+++ b/lldb/test/API/lang/cpp/bitfields/TestCppBitfields.py
@@ -46,6 +46,16 @@ def test_and_run_command(self):
         self.expect("expr (clang_example.f.a)", VARIABLES_DISPLAYED_CORRECTLY,
                     substrs=['uint64_t', '1'])
 
+        self.expect("expr uwbf",
+            substrs=['a = 255',
+                    'b = 65535',
+                    'c = 4294967295',
+                    'x = 4294967295'] )
+
+        self.expect("expr uwubf",
+            substrs=['a = 16777215',
+                    'x = 4294967295'] )
+
         self.expect(
             "frame variable --show-types lba",
             VARIABLES_DISPLAYED_CORRECTLY,

diff  --git a/lldb/test/API/lang/cpp/bitfields/main.cpp b/lldb/test/API/lang/cpp/bitfields/main.cpp
index 986b7cb947ed..f9015b758c72 100644
--- a/lldb/test/API/lang/cpp/bitfields/main.cpp
+++ b/lldb/test/API/lang/cpp/bitfields/main.cpp
@@ -57,7 +57,7 @@ int main(int argc, char const *argv[]) {
   f.i = 1;
   f.j = 0;
   f.k = 1;
-    } 
+    }
   } clang_example;
 
   class B {
@@ -70,6 +70,18 @@ int main(int argc, char const *argv[]) {
     uint32_t d_a : 1;
   } derived;
 
+  union union_with_bitfields {
+      unsigned int a : 8;
+      unsigned int b : 16;
+      unsigned int c : 32;
+      unsigned int x;
+  } uwbf;
+
+  union union_with_unnamed_bitfield {
+   unsigned int : 16, a : 24;
+   unsigned int x;
+  } uwubf;
+
   lba.a = 2;
 
   lbb.a = 1;
@@ -89,5 +101,8 @@ int main(int argc, char const *argv[]) {
   derived.b_a = 2;
   derived.d_a = 1;
 
+  uwbf.x = 0xFFFFFFFF;
+  uwubf.x = 0xFFFFFFFF;
+
   return 0; // Set break point at this line.
 }


        


More information about the lldb-commits mailing list