[Lldb-commits] [PATCH] D91118: Fix handling of bit-fields in a union

Shafik Yaghmour via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Nov 9 20:54:22 PST 2020


shafik created this revision.
shafik added reviewers: teemperor, aprantl.
shafik requested review of this revision.

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


https://reviews.llvm.org/D91118

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  lldb/test/API/lang/cpp/bitfields/TestCppBitfields.py
  lldb/test/API/lang/cpp/bitfields/main.cpp


Index: lldb/test/API/lang/cpp/bitfields/main.cpp
===================================================================
--- lldb/test/API/lang/cpp/bitfields/main.cpp
+++ lldb/test/API/lang/cpp/bitfields/main.cpp
@@ -57,7 +57,7 @@
   f.i = 1;
   f.j = 0;
   f.k = 1;
-    } 
+    }
   } clang_example;
 
   class B {
@@ -70,6 +70,18 @@
     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 @@
   derived.b_a = 2;
   derived.d_a = 1;
 
+  uwbf.x = 0xFFFFFFFF;
+  uwubf.x = 0xFFFFFFFF;
+
   return 0; // Set break point at this line.
 }
Index: lldb/test/API/lang/cpp/bitfields/TestCppBitfields.py
===================================================================
--- lldb/test/API/lang/cpp/bitfields/TestCppBitfields.py
+++ lldb/test/API/lang/cpp/bitfields/TestCppBitfields.py
@@ -46,6 +46,16 @@
         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,
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -2582,6 +2582,7 @@
           // the bit-offset in the layout. It just means something different then
           // what it does in C and C++. So we skip this check for ObjC types.
           if (!TypeSystemClang::IsObjCObjectOrInterfaceType(class_clang_type) &&
+              !(parent_die.Tag() == DW_TAG_union_type) &&
               ((this_field_info.bit_offset >= parent_bit_size) ||
                (last_field_info.IsBitfield() &&
                 !last_field_info.NextBitfieldOffsetIsValid(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91118.304026.patch
Type: text/x-patch
Size: 2389 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20201110/b06dc359/attachment-0001.bin>


More information about the lldb-commits mailing list