llvm.org GIT mirror llvm / 6b2ae13
Debug Info: One more bitfield bugfix. While yesterday's r240853 fixed the DW_AT_bit_offset computation, the byte offset is in fact also endian-dependent as it needs to point to the storage unit containing the most-significant bit of the the bitfield. I'm so looking forward to emitting the endian-agnostic DWARF 3 version instead. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240890 91177308-0d34-0410-b5e6-96231b3b80d8 Adrian Prantl 5 years ago
2 changed file(s) with 22 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
13451345 addUInt(MemberDie, dwarf::DW_AT_byte_size, None, FieldSize/8);
13461346 addUInt(MemberDie, dwarf::DW_AT_bit_size, None, Size);
13471347 //
1348 // The DWARF 2 DW_AT_bit_offset is counting the bits between
1349 // the high end of the aligned storage unit containing the bit
1350 // field to the high end of the bit field.
1348 // The DWARF 2 DW_AT_bit_offset is counting the bits between the most
1349 // significant bit of the aligned storage unit containing the bit field to
1350 // the most significan bit of the bit field.
13511351 //
13521352 // FIXME: DWARF 4 states that DW_AT_data_bit_offset (which
13531353 // counts from the beginning, regardless of endianness) should
13601360 // | ... |b1|b2|b3|b4|
13611361 // +-----------+-----*-----+-----*-----+--
13621362 // | | |<-- Size ->| |
1363 // |<---- Offset --->| |<--->|
1364 // | | | \_ DW_AT_bit_offset (little endian)
1365 // | |<--->|
1366 // |<--------->| \_ StartBitOffset = DW_AT_bit_offset (big endian)
1367 // \ = DW_AT_data_bit_offset (biendian)
1368 // \_ OffsetInBytes
1363 // |<---- Offset --->| | |<--->|
1364 // | | | | \_ DW_AT_bit_offset (little endian)
1365 // | |<--->| |
1366 // |<--big-e.->| \_ StartBitOffset = DW_AT_bit_offset (big endian)
1367 // | ^ | = DW_AT_data_bit_offset (biendian)
1368 // | OffsetInBytes |
1369 // | v |
1370 // |<----little-endian---->|
13691371 uint64_t Offset = DT->getOffsetInBits();
13701372 uint64_t Align = DT->getAlignInBits() ? DT->getAlignInBits() : FieldSize;
13711373 uint64_t AlignMask = ~(Align - 1);
13721374 // The bits from the start of the storage unit to the start of the field.
13731375 uint64_t StartBitOffset = Offset - (Offset & AlignMask);
1374 // The endian-dependent DWARF 2 offset.
1375 uint64_t DwarfBitOffset = Asm->getDataLayout().isLittleEndian()
1376 ? OffsetToAlignment(Offset + Size, Align)
1377 : StartBitOffset;
1378
1379 // The byte offset of the field's aligned storage unit inside the struct.
1380 OffsetInBytes = (Offset - StartBitOffset) / 8;
1376 // OffsetInBytes is the byte offset of the field's aligned storage unit
1377 // inside the struct.
1378 uint64_t DwarfBitOffset;
1379 if (Asm->getDataLayout().isLittleEndian()) {
1380 DwarfBitOffset = OffsetToAlignment(Offset + Size, Align);
1381 OffsetInBytes = ((Offset + Size) & AlignMask) / 8;
1382 } else {
1383 DwarfBitOffset = StartBitOffset;
1384 OffsetInBytes = (Offset - StartBitOffset) / 8;
1385 }
13811386 addUInt(MemberDie, dwarf::DW_AT_bit_offset, None, DwarfBitOffset);
13821387 } else
13831388 // This is not a bitfield.
1313 ; CHECK: DW_AT_byte_size {{.*}} (0x04)
1414 ; CHECK: DW_AT_bit_size {{.*}} (0x1c)
1515 ; CHECK: DW_AT_bit_offset {{.*}} (0x18)
16 ; CHECK: DW_AT_data_member_location {{.*}}00
16 ; CHECK: DW_AT_data_member_location {{.*}}04
1717 target datalayout = "e-m:o-p:32:32-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32"
1818 target triple = "thumbv7-apple-ios"
1919