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

Commit 3a21b80

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 (cherry picked from commit ee1e043)
1 parent 4584843 commit 3a21b80

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
@@ -1415,30 +1415,16 @@ void DwarfUnit::constructMemberDIE(DIE &Buffer, const DIDerivedType *DT) {
14151415
if (DD->getDwarfVersion() >= 4)
14161416
addUInt(MemberDie, dwarf::DW_AT_data_bit_offset, None, Offset);
14171417
else {
1418-
//
1419-
// The DWARF 2 DW_AT_bit_offset is counting the bits between the most
1420-
// significant bit of the aligned storage unit containing the bit field
1421-
// to
1422-
// the most significan bit of the bit field.
1423-
//
1424-
// Struct Align Align Align
1425-
// v v v v
1426-
// +-----------+-----*-----+-----*-----+--
1427-
// | ... |b1|b2|b3|b4|
1428-
// +-----------+-----*-----+-----*-----+--
1429-
// | | |<-- Size ->| |
1430-
// |<---- Offset --->| |<--->|
1431-
// | | | \_ DW_AT_bit_offset (little endian)
1432-
// | |<--->|
1433-
// |<--------->| \_ StartBitOffset = DW_AT_bit_offset (big endian)
1434-
// \ = DW_AT_data_bit_offset (biendian)
1435-
// \_ OffsetInBytes
1436-
// The endian-dependent DWARF 2 offset.
1437-
uint64_t DwarfBitOffset = Asm->getDataLayout().isLittleEndian()
1438-
? OffsetToAlignment(Offset + Size, Align)
1439-
: StartBitOffset;
1440-
1441-
addUInt(MemberDie, dwarf::DW_AT_bit_offset, None, DwarfBitOffset);
1418+
uint64_t HiMark = (Offset + FieldSize) & AlignMask;
1419+
uint64_t FieldOffset = (HiMark - FieldSize);
1420+
Offset -= FieldOffset;
1421+
1422+
// Maybe we need to work from the other end.
1423+
if (Asm->getDataLayout().isLittleEndian())
1424+
Offset = FieldSize - (Offset + Size);
1425+
1426+
addUInt(MemberDie, dwarf::DW_AT_bit_offset, None, Offset);
1427+
OffsetInBytes = FieldOffset >> 3;
14421428
}
14431429
} else
14441430
// 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)