diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp --- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp +++ b/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. diff --git a/llvm/test/DebugInfo/X86/packed_bitfields.ll b/llvm/test/DebugInfo/X86/packed_bitfields.ll --- a/llvm/test/DebugInfo/X86/packed_bitfields.ll +++ b/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'