[PATCH] D82881: [DEBUGINFO]Fix debug info for packed bitfields.
Alexey Bataev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 30 08:39:46 PDT 2020
ABataev created this revision.
ABataev added reviewers: aprantl, probinson.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.
For the packed bitfields, the compiler emits not quite correct debug
info. Packed bitfield may use more bytes than the base type of the
bitfield. In this case, DW_AT_byte_size and DW_AT_bit_offset attributes
may have incorrect values.
Repository:
rG LLVM Github Monorepo
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
@@ -13,9 +13,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 {{.*}} (DW_OP_plus_uconst 0x0)
; 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 = ((Offset + Size + 7) / 8 - Offset / 8) * 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.274487.patch
Type: text/x-patch
Size: 1670 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200630/06404b5b/attachment.bin>
More information about the llvm-commits
mailing list