[llvm] r267896 - Debug Info: Restore the pre-r240853 behavior for DWARF2 bitfields.

Adrian Prantl via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 28 08:37:53 PDT 2016


Author: adrian
Date: Thu Apr 28 10:37:52 2016
New Revision: 267896

URL: http://llvm.org/viewvc/llvm-project?rev=267896&view=rev
Log:
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.

Modified:
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
    llvm/trunk/test/DebugInfo/ARM/bitfield.ll

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp?rev=267896&r1=267895&r2=267896&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp Thu Apr 28 10:37:52 2016
@@ -1407,30 +1407,16 @@ void DwarfUnit::constructMemberDIE(DIE &
       if (DD->getDwarfVersion() >= 4)
         addUInt(MemberDie, dwarf::DW_AT_data_bit_offset, None, Offset);
       else {
-        //
-        // The DWARF 2 DW_AT_bit_offset is counting the bits between the most
-        // significant bit of the aligned storage unit containing the bit field
-        // to
-        // the most significan bit of the bit field.
-        //
-        // Struct      Align       Align       Align
-        // v           v           v           v
-        // +-----------+-----*-----+-----*-----+--
-        // | ...             |b1|b2|b3|b4|
-        // +-----------+-----*-----+-----*-----+--
-        // |           |     |<-- Size ->|     |
-        // |<---- Offset --->|           |<--->|
-        // |           |     |              \_ DW_AT_bit_offset (little endian)
-        // |           |<--->|
-        // |<--------->|  \_ StartBitOffset = DW_AT_bit_offset (big endian)
-        //     \                            = DW_AT_data_bit_offset (biendian)
-        //      \_ OffsetInBytes
-        // The endian-dependent DWARF 2 offset.
-        uint64_t DwarfBitOffset = Asm->getDataLayout().isLittleEndian()
-                                      ? OffsetToAlignment(Offset + Size, Align)
-                                      : StartBitOffset;
+        uint64_t HiMark = (Offset + FieldSize) & AlignMask;
+        uint64_t FieldOffset = (HiMark - FieldSize);
+        Offset -= FieldOffset;
 
-        addUInt(MemberDie, dwarf::DW_AT_bit_offset, None, DwarfBitOffset);
+        // Maybe we need to work from the other end.
+        if (Asm->getDataLayout().isLittleEndian())
+          Offset = FieldSize - (Offset + Size);
+
+        addUInt(MemberDie, dwarf::DW_AT_bit_offset, None, Offset);
+        OffsetInBytes = FieldOffset >> 3;
       }
     } else
       // This is not a bitfield.

Modified: llvm/trunk/test/DebugInfo/ARM/bitfield.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/ARM/bitfield.ll?rev=267896&r1=267895&r2=267896&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/ARM/bitfield.ll (original)
+++ llvm/trunk/test/DebugInfo/ARM/bitfield.ll Thu Apr 28 10:37:52 2016
@@ -13,7 +13,7 @@
 ; CHECK:          DW_AT_name {{.*}} "reserved"
 ; CHECK:          DW_AT_byte_size  {{.*}} (0x04)
 ; CHECK:          DW_AT_bit_size   {{.*}} (0x1c)
-; CHECK:          DW_AT_bit_offset {{.*}} (0x18)
+; CHECK:          DW_AT_bit_offset {{.*}} (0xfffffffffffffff8)
 ; CHECK:          DW_AT_data_member_location {{.*}}00
 target datalayout = "e-m:o-p:32:32-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32"
 target triple = "thumbv7-apple-ios"




More information about the llvm-commits mailing list