[PATCH] D82881: [DEBUGINFO]Fix debug info for packed bitfields.

Alexey Bataev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 7 07:23:04 PDT 2020


ABataev updated this revision to Diff 276057.
ABataev added a comment.

Rebase + used `align...` functions.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82881/new/

https://reviews.llvm.org/D82881

Files:
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
  llvm/test/DebugInfo/X86/packed_bitfields.ll


Index: llvm/test/DebugInfo/X86/packed_bitfields.ll
===================================================================
--- llvm/test/DebugInfo/X86/packed_bitfields.ll
+++ llvm/test/DebugInfo/X86/packed_bitfields.ll
@@ -15,9 +15,9 @@
 ; CHECK: DW_TAG_member
 ; CHECK-NEXT: DW_AT_name{{.*}}"a"
 ; CHECK-NOT: DW_TAG_member
-; CHECK:      DW_AT_byte_size  {{.*}} (0x01)
+; CHECK:      DW_AT_byte_size  {{.*}} (0x02)
 ; CHECK-NEXT: DW_AT_bit_size   {{.*}} (0x06)
-; CHECK-NEXT: DW_AT_bit_offset {{.*}} (0xffffffffffffffff)
+; CHECK-NEXT: DW_AT_bit_offset {{.*}} (0x07)
 ; CHECK-NEXT: DW_AT_data_member_location {{.*}} ({{.*}}0x0{{0*}})
 
 ; ModuleID = 'repro.c'
Index: llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -1541,12 +1541,15 @@
 
     bool IsBitfield = FieldSize && Size != FieldSize;
     if (IsBitfield) {
+      uint64_t Offset = DT->getOffsetInBits();
       // Handle bitfield, assume bytes are 8 bits.
+      uint64_t StorageSize = alignTo(Offset + Size, 8) - alignDown(Offset, 8);
+      if (StorageSize > FieldSize)
+        FieldSize = StorageSize;
       if (DD->useDWARF2Bitfields())
         addUInt(MemberDie, dwarf::DW_AT_byte_size, None, FieldSize/8);
       addUInt(MemberDie, dwarf::DW_AT_bit_size, None, Size);
 
-      uint64_t Offset = DT->getOffsetInBits();
       // We can't use DT->getAlignInBits() here: AlignInBits for member type
       // is non-zero if and only if alignment was forced (e.g. _Alignas()),
       // which can't be done with bitfields. Thus we use FieldSize here.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82881.276057.patch
Type: text/x-patch
Size: 1670 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200707/f305dae7/attachment.bin>


More information about the llvm-commits mailing list