Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit ee1e043

Browse files
committed
Debug Info: Restore the pre-r240853 behavior for DWARF2 bitfields.
The DWARF2 specification of DW_AT_bit_offset is ambiguous for little-endian machines, but by restoring to the old behavior we match what debuggers expect and what other popular compilers generate. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@267896 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 9ed561f commit ee1e043

File tree

2 files changed

+11
-25
lines changed

2 files changed

+11
-25
lines changed

lib/CodeGen/AsmPrinter/DwarfUnit.cpp

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,30 +1407,16 @@ void DwarfUnit::constructMemberDIE(DIE &Buffer, const DIDerivedType *DT) {
14071407
if (DD->getDwarfVersion() >= 4)
14081408
addUInt(MemberDie, dwarf::DW_AT_data_bit_offset, None, Offset);
14091409
else {
1410-
//
1411-
// The DWARF 2 DW_AT_bit_offset is counting the bits between the most
1412-
// significant bit of the aligned storage unit containing the bit field
1413-
// to
1414-
// the most significan bit of the bit field.
1415-
//
1416-
// Struct Align Align Align
1417-
// v v v v
1418-
// +-----------+-----*-----+-----*-----+--
1419-
// | ... |b1|b2|b3|b4|
1420-
// +-----------+-----*-----+-----*-----+--
1421-
// | | |<-- Size ->| |
1422-
// |<---- Offset --->| |<--->|
1423-
// | | | \_ DW_AT_bit_offset (little endian)
1424-
// | |<--->|
1425-
// |<--------->| \_ StartBitOffset = DW_AT_bit_offset (big endian)
1426-
// \ = DW_AT_data_bit_offset (biendian)
1427-
// \_ OffsetInBytes
1428-
// The endian-dependent DWARF 2 offset.
1429-
uint64_t DwarfBitOffset = Asm->getDataLayout().isLittleEndian()
1430-
? OffsetToAlignment(Offset + Size, Align)
1431-
: StartBitOffset;
1432-
1433-
addUInt(MemberDie, dwarf::DW_AT_bit_offset, None, DwarfBitOffset);
1410+
uint64_t HiMark = (Offset + FieldSize) & AlignMask;
1411+
uint64_t FieldOffset = (HiMark - FieldSize);
1412+
Offset -= FieldOffset;
1413+
1414+
// Maybe we need to work from the other end.
1415+
if (Asm->getDataLayout().isLittleEndian())
1416+
Offset = FieldSize - (Offset + Size);
1417+
1418+
addUInt(MemberDie, dwarf::DW_AT_bit_offset, None, Offset);
1419+
OffsetInBytes = FieldOffset >> 3;
14341420
}
14351421
} else
14361422
// This is not a bitfield.

test/DebugInfo/ARM/bitfield.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
; CHECK: DW_AT_name {{.*}} "reserved"
1414
; CHECK: DW_AT_byte_size {{.*}} (0x04)
1515
; CHECK: DW_AT_bit_size {{.*}} (0x1c)
16-
; CHECK: DW_AT_bit_offset {{.*}} (0x18)
16+
; CHECK: DW_AT_bit_offset {{.*}} (0xfffffffffffffff8)
1717
; CHECK: DW_AT_data_member_location {{.*}}00
1818
target datalayout = "e-m:o-p:32:32-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32"
1919
target triple = "thumbv7-apple-ios"

0 commit comments

Comments
 (0)