[llvm-commits] [llvm] r64818 - in /llvm/branches/Apple/Dib: include/llvm/Analysis/DebugInfo.h lib/Analysis/DebugInfo.cpp lib/CodeGen/AsmPrinter/DwarfWriter.cpp test/FrontendC/2009-02-17-BitField-dbg.c

Bill Wendling isanbard at gmail.com
Tue Feb 17 13:34:45 PST 2009


Author: void
Date: Tue Feb 17 15:34:44 2009
New Revision: 64818

URL: http://llvm.org/viewvc/llvm-project?rev=64818&view=rev
Log:
--- Merging (from foreign repository) r64815 into '.':
A    test/FrontendC/2009-02-17-BitField-dbg.c
U    include/llvm/Analysis/DebugInfo.h
U    lib/Analysis/DebugInfo.cpp
U    lib/CodeGen/AsmPrinter/DwarfWriter.cpp

Emit debug info for bitfields.

Added:
    llvm/branches/Apple/Dib/test/FrontendC/2009-02-17-BitField-dbg.c
Modified:
    llvm/branches/Apple/Dib/include/llvm/Analysis/DebugInfo.h
    llvm/branches/Apple/Dib/lib/Analysis/DebugInfo.cpp
    llvm/branches/Apple/Dib/lib/CodeGen/AsmPrinter/DwarfWriter.cpp

Modified: llvm/branches/Apple/Dib/include/llvm/Analysis/DebugInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/include/llvm/Analysis/DebugInfo.h?rev=64818&r1=64817&r2=64818&view=diff

==============================================================================
--- llvm/branches/Apple/Dib/include/llvm/Analysis/DebugInfo.h (original)
+++ llvm/branches/Apple/Dib/include/llvm/Analysis/DebugInfo.h Tue Feb 17 15:34:44 2009
@@ -118,9 +118,9 @@
     /// code generator accepts maximum one main compile unit per module. If a
     /// module does not contain any main compile unit then the code generator 
     /// will emit multiple compile units in the output object file.
-    bool isMain() const             { return getUnsignedField(6); }
-    bool isOptimized() const         { return getUnsignedField(7); }
-    std::string getFlags() const     { return getStringField(8); }
+    bool isMain() const                { return getUnsignedField(6); }
+    bool isOptimized() const           { return getUnsignedField(7); }
+    std::string getFlags() const       { return getStringField(8); }
 
     /// Verify - Verify that a compile unit is well formed.
     bool Verify() const;
@@ -217,6 +217,9 @@
     explicit DIDerivedType(GlobalVariable *GV);
     DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
 
+    /// getOriginalTypeSize - If this type is derived from a base type then
+    /// return base type size.
+    uint64_t getOriginalTypeSize() const;
     /// dump - print derived type.
     void dump() const;
   };

Modified: llvm/branches/Apple/Dib/lib/Analysis/DebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/Analysis/DebugInfo.cpp?rev=64818&r1=64817&r2=64818&view=diff

==============================================================================
--- llvm/branches/Apple/Dib/lib/Analysis/DebugInfo.cpp (original)
+++ llvm/branches/Apple/Dib/lib/Analysis/DebugInfo.cpp Tue Feb 17 15:34:44 2009
@@ -169,8 +169,8 @@
   }
 }
 
-DIVariable::DIVariable(GlobalVariable *GV) : DIDescriptor(GV) {
-  if (GV && !isVariable(getTag()))
+DIVariable::DIVariable(GlobalVariable *gv) : DIDescriptor(gv) {
+  if (gv && !isVariable(getTag()))
     GV = 0;
 }
 
@@ -273,7 +273,16 @@
   return true;
 }
 
-
+/// getOriginalTypeSize - If this type is derived from a base type then
+/// return base type size.
+uint64_t DIDerivedType::getOriginalTypeSize() const {
+  if (getTag() != dwarf::DW_TAG_member)
+    return getSizeInBits();
+  DIType BT = getTypeDerivedFrom();
+  if (BT.getTag() != dwarf::DW_TAG_base_type)
+    return getSizeInBits();
+  return BT.getSizeInBits();
+}
 
 //===----------------------------------------------------------------------===//
 // DIFactory: Basic Helpers

Modified: llvm/branches/Apple/Dib/lib/CodeGen/AsmPrinter/DwarfWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/CodeGen/AsmPrinter/DwarfWriter.cpp?rev=64818&r1=64817&r2=64818&view=diff

==============================================================================
--- llvm/branches/Apple/Dib/lib/CodeGen/AsmPrinter/DwarfWriter.cpp (original)
+++ llvm/branches/Apple/Dib/lib/CodeGen/AsmPrinter/DwarfWriter.cpp Tue Feb 17 15:34:44 2009
@@ -1870,7 +1870,24 @@
 
     AddSourceLine(MemberDie, &DT);
 
-    // FIXME _ Handle bitfields
+    uint64_t Size = DT.getSizeInBits();
+    uint64_t FieldSize = DT.getOriginalTypeSize();
+
+    if (Size != FieldSize) {
+      // Handle bitfield.
+      AddUInt(MemberDie, DW_AT_byte_size, 0, DT.getOriginalTypeSize() >> 3);
+      AddUInt(MemberDie, DW_AT_bit_size, 0, DT.getSizeInBits());
+
+      uint64_t Offset = DT.getOffsetInBits();
+      uint64_t FieldOffset = Offset;
+      uint64_t AlignMask = ~(DT.getAlignInBits() - 1);
+      uint64_t HiMark = (Offset + FieldSize) & AlignMask;
+      FieldOffset = (HiMark - FieldSize);
+      Offset -= FieldOffset;
+      // Maybe we need to work from the other end.
+      if (TD->isLittleEndian()) Offset = FieldSize - (Offset + Size);
+      AddUInt(MemberDie, DW_AT_bit_offset, 0, Offset);
+    }
     DIEBlock *Block = new DIEBlock();
     AddUInt(Block, 0, DW_FORM_data1, DW_OP_plus_uconst);
     AddUInt(Block, 0, DW_FORM_udata, DT.getOffsetInBits() >> 3);

Added: llvm/branches/Apple/Dib/test/FrontendC/2009-02-17-BitField-dbg.c
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/test/FrontendC/2009-02-17-BitField-dbg.c?rev=64818&view=auto

==============================================================================
--- llvm/branches/Apple/Dib/test/FrontendC/2009-02-17-BitField-dbg.c (added)
+++ llvm/branches/Apple/Dib/test/FrontendC/2009-02-17-BitField-dbg.c Tue Feb 17 15:34:44 2009
@@ -0,0 +1,13 @@
+// Check bitfields.
+// RUN: %llvmgcc -S -O0 -g %s -o - | llvm-as | \
+// RUN: llc --disable-fp-elim -o 2009-02-17-BitField-dbg.s -f
+// RUN: %compile_c 2009-02-17-BitField-dbg.s -o 2009-02-17-BitField-dbg.o
+// RUN: echo {ptype mystruct} > %t2
+// RUN: gdb -q -batch -n -x %t2 2009-02-17-BitField-dbg.o | \
+// RUN:   tee 2009-02-17-BitField-dbg.out | grep "int a : 4"
+
+struct {
+  int  a:4;
+  int  b:2;
+} mystruct;
+





More information about the llvm-commits mailing list