Fix DW_AT_data_member_location for bit-fields. It points to the location of annonymou...
authorDevang Patel <dpatel@apple.com>
Wed, 4 Nov 2009 22:06:12 +0000 (22:06 +0000)
committerDevang Patel <dpatel@apple.com>
Wed, 4 Nov 2009 22:06:12 +0000 (22:06 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86054 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/AsmPrinter/DwarfDebug.cpp

index 674304e7b36112f82cbc8b06bb40dea93a8cb54e..dc4c9096ab00963e87f87cd16d6273ace03fa72d 100644 (file)
@@ -1137,6 +1137,9 @@ DIE *DwarfDebug::CreateMemberDIE(CompileUnit *DW_Unit, const DIDerivedType &DT){
 
   AddSourceLine(MemberDie, &DT);
 
+  DIEBlock *MemLocationDie = new DIEBlock();
+  AddUInt(MemLocationDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst);
+
   uint64_t Size = DT.getSizeInBits();
   uint64_t FieldSize = Size;
   if (DT.getTypeDerivedFrom().getTag() != dwarf::DW_TAG_array_type)
@@ -1157,12 +1160,16 @@ DIE *DwarfDebug::CreateMemberDIE(CompileUnit *DW_Unit, const DIDerivedType &DT){
     // Maybe we need to work from the other end.
     if (TD->isLittleEndian()) Offset = FieldSize - (Offset + Size);
     AddUInt(MemberDie, dwarf::DW_AT_bit_offset, 0, Offset);
-  }
 
-  DIEBlock *Block = new DIEBlock();
-  AddUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst);
-  AddUInt(Block, 0, dwarf::DW_FORM_udata, DT.getOffsetInBits() >> 3);
-  AddBlock(MemberDie, dwarf::DW_AT_data_member_location, 0, Block);
+    // Here WD_AT_data_member_location points to the anonymous
+    // field that includes this bit field.
+    AddUInt(MemLocationDie, 0, dwarf::DW_FORM_udata, FieldOffset >> 3);
+
+  } else
+    // This is not a bitfield.
+    AddUInt(MemLocationDie, 0, dwarf::DW_FORM_udata, DT.getOffsetInBits() >> 3);
+
+  AddBlock(MemberDie, dwarf::DW_AT_data_member_location, 0, MemLocationDie);
 
   if (DT.isProtected())
     AddUInt(MemberDie, dwarf::DW_AT_accessibility, 0,