[llvm-commits] [llvm] r60812 - in /llvm/trunk: include/llvm/CodeGen/MachineModuleInfo.h lib/CodeGen/AsmPrinter/DwarfWriter.cpp lib/CodeGen/MachineModuleInfo.cpp test/DebugInfo/forwardDecl.ll

Evan Cheng evan.cheng at apple.com
Tue Dec 9 16:15:45 PST 2008


Author: evancheng
Date: Tue Dec  9 18:15:44 2008
New Revision: 60812

URL: http://llvm.org/viewvc/llvm-project?rev=60812&view=rev
Log:
Fix a couple of Dwarf bugs.
- Emit DW_AT_byte_size for struct and union of size zero.
- Emit DW_AT_declaration for forward type declaration.

Added:
    llvm/trunk/test/DebugInfo/forwardDecl.ll
Modified:
    llvm/trunk/include/llvm/CodeGen/MachineModuleInfo.h
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfWriter.cpp
    llvm/trunk/lib/CodeGen/MachineModuleInfo.cpp

Modified: llvm/trunk/include/llvm/CodeGen/MachineModuleInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineModuleInfo.h?rev=60812&r1=60811&r2=60812&view=diff

==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineModuleInfo.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineModuleInfo.h Tue Dec  9 18:15:44 2008
@@ -282,7 +282,8 @@
 private:
   enum {
     FlagPrivate    = 1 << 0,
-    FlagProtected  = 1 << 1
+    FlagProtected  = 1 << 1,
+    FlagFwdDecl    = 1 << 2
   };
   DebugInfoDesc *Context;               // Context debug descriptor.
   std::string Name;                     // Type name (may be empty.)
@@ -291,6 +292,8 @@
   uint64_t Size;                        // Type bit size (may be zero.)
   uint64_t Align;                       // Type bit alignment (may be zero.)
   uint64_t Offset;                      // Type bit offset (may be zero.)
+
+protected:
   unsigned Flags;                       // Miscellaneous flags.
 
 public:
@@ -312,6 +315,9 @@
   bool isProtected() const {
     return (Flags & FlagProtected) != 0;
   }
+  bool isForwardDecl() const {
+    return (Flags & FlagFwdDecl) != 0;
+  }
   void setContext(DebugInfoDesc *C)                { Context = C; }
   void setName(const std::string &N)               { Name = N; }
   void setFile(CompileUnitDesc *U) {
@@ -323,6 +329,7 @@
   void setOffset(uint64_t O)                       { Offset = O; }
   void setIsPrivate()                              { Flags |= FlagPrivate; }
   void setIsProtected()                            { Flags |= FlagProtected; }
+  void setIsForwardDecl()                          { Flags |= FlagFwdDecl; }
   
   /// ApplyToFields - Target the visitor to the fields of the TypeDesc.
   ///

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfWriter.cpp?rev=60812&r1=60811&r2=60812&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfWriter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfWriter.cpp Tue Dec  9 18:15:44 2008
@@ -1774,14 +1774,25 @@
       }
     }
 
-    // Add size if non-zero (derived types don't have a size.)
-    if (Size) AddUInt(&Buffer, DW_AT_byte_size, 0, Size);
-
     // Add name if not anonymous or intermediate type.
     if (!Name.empty()) AddString(&Buffer, DW_AT_name, DW_FORM_string, Name);
 
-    // Add source line info if available.
-    AddSourceLine(&Buffer, TyDesc->getFile(), TyDesc->getLine());
+    // Add size if non-zero (derived types might be zero-sized.)
+    if (Size)
+      AddUInt(&Buffer, DW_AT_byte_size, 0, Size);
+    else if (isa<CompositeTypeDesc>(TyDesc)) {
+      // If TyDesc is a composite type, then add size even if it's zero unless
+      // it's a forward declaration.
+      if (TyDesc->isForwardDecl())
+        AddUInt(&Buffer, DW_AT_declaration, DW_FORM_flag, 1);
+      else
+        AddUInt(&Buffer, DW_AT_byte_size, 0, 0);
+    }
+
+    // Add source line info if available and TyDesc is not a forward
+    // declaration.
+    if (!TyDesc->isForwardDecl())
+      AddSourceLine(&Buffer, TyDesc->getFile(), TyDesc->getLine());
   }
 
   /// NewCompileUnit - Create new compile unit and it's debug information entry.

Modified: llvm/trunk/lib/CodeGen/MachineModuleInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineModuleInfo.cpp?rev=60812&r1=60811&r2=60812&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/MachineModuleInfo.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineModuleInfo.cpp Tue Dec  9 18:15:44 2008
@@ -906,7 +906,8 @@
        << "Context(" << getContext() << "), "
        << "Name(\"" << getName() << "\"), "
        << "Size(" << getSize() << "), "
-       << "Encoding(" << Encoding << ")\n";
+       << "Encoding(" << Encoding << "),"
+       << "Flags(" << Flags << ")\n";
 }
 #endif
 
@@ -965,7 +966,8 @@
        << "Size(" << getSize() << "), "
        << "File(" << getFile() << "), "
        << "Line(" << getLine() << "), "
-       << "FromType(" << FromType << ")\n";
+       << "FromType(" << FromType << "),"
+       << "Flags(" << Flags << ")\n";
 }
 #endif
 
@@ -1023,7 +1025,8 @@
        << "File(" << getFile() << "), "
        << "Line(" << getLine() << "), "
        << "FromType(" << getFromType() << "), "
-       << "Elements.size(" << Elements.size() << ")\n";
+       << "Elements.size(" << Elements.size() << "),"
+       << "Flags(" << Flags << ")\n";
 }
 #endif
 

Added: llvm/trunk/test/DebugInfo/forwardDecl.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/forwardDecl.ll?rev=60812&view=auto

==============================================================================
--- llvm/trunk/test/DebugInfo/forwardDecl.ll (added)
+++ llvm/trunk/test/DebugInfo/forwardDecl.ll Tue Dec  9 18:15:44 2008
@@ -0,0 +1,49 @@
+; RUN: llvm-as < %s | llc | %prcontext ST 1 | grep 0x1 | count 1
+
+target triple = "i386-apple-darwin9.6"
+	%llvm.dbg.anchor.type = type { i32, i32 }
+	%llvm.dbg.compile_unit.type = type { i32, { }*, i32, i8*, i8*, i8* }
+	%llvm.dbg.compositetype.type = type { i32, { }*, i8*, { }*, i32, i64, i64, i64, i32, { }*, { }* }
+	%llvm.dbg.derivedtype.type = type { i32, { }*, i8*, { }*, i32, i64, i64, i64, i32, { }* }
+	%llvm.dbg.subprogram.type = type { i32, { }*, { }*, i8*, i8*, i8*, { }*, i32, { }*, i1, i1 }
+	%llvm.dbg.variable.type = type { i32, { }*, i8*, { }*, i32, { }* }
+	%struct.ST = type opaque
+ at llvm.dbg.subprogram = internal constant %llvm.dbg.subprogram.type { i32 393262, { }* bitcast (%llvm.dbg.anchor.type* @llvm.dbg.subprograms to { }*), { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i8* getelementptr ([4 x i8]* @.str3, i32 0, i32 0), i8* getelementptr ([4 x i8]* @.str3, i32 0, i32 0), i8* null, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i32 3, { }* null, i1 false, i1 true }, section "llvm.metadata"		; <%llvm.dbg.subprogram.type*> [#uses=1]
+ at llvm.dbg.subprograms = linkonce constant %llvm.dbg.anchor.type { i32 393216, i32 46 }, section "llvm.metadata"		; <%llvm.dbg.anchor.type*> [#uses=1]
+ at llvm.dbg.compile_unit = internal constant %llvm.dbg.compile_unit.type { i32 393233, { }* bitcast (%llvm.dbg.anchor.type* @llvm.dbg.compile_units to { }*), i32 1, i8* getelementptr ([4 x i8]* @.str, i32 0, i32 0), i8* getelementptr ([36 x i8]* @.str1, i32 0, i32 0), i8* getelementptr ([52 x i8]* @.str2, i32 0, i32 0) }, section "llvm.metadata"		; <%llvm.dbg.compile_unit.type*> [#uses=1]
+ at llvm.dbg.compile_units = linkonce constant %llvm.dbg.anchor.type { i32 393216, i32 17 }, section "llvm.metadata"		; <%llvm.dbg.anchor.type*> [#uses=1]
+ at .str = internal constant [4 x i8] c"t.c\00", section "llvm.metadata"		; <[20 x i8]*> [#uses=1]
+ at .str1 = internal constant [36 x i8] c"/Users/echeng/LLVM/radars/r6395152/\00", section "llvm.metadata"		; <[36 x i8]*> [#uses=1]
+ at .str2 = internal constant [52 x i8] c"4.2.1 (Based on Apple Inc. build 5628) (LLVM build)\00", section "llvm.metadata"		; <[52 x i8]*> [#uses=1]
+ at .str3 = internal constant [4 x i8] c"foo\00", section "llvm.metadata"		; <[4 x i8]*> [#uses=1]
+ at llvm.dbg.variable = internal constant %llvm.dbg.variable.type { i32 393473, { }* bitcast (%llvm.dbg.subprogram.type* @llvm.dbg.subprogram to { }*), i8* getelementptr ([2 x i8]* @.str4, i32 0, i32 0), { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i32 3, { }* bitcast (%llvm.dbg.derivedtype.type* @llvm.dbg.derivedtype to { }*) }, section "llvm.metadata"		; <%llvm.dbg.variable.type*> [#uses=1]
+ at .str4 = internal constant [2 x i8] c"x\00", section "llvm.metadata"		; <[2 x i8]*> [#uses=1]
+ at llvm.dbg.derivedtype = internal constant %llvm.dbg.derivedtype.type { i32 393231, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i8* null, { }* null, i32 0, i64 32, i64 32, i64 0, i32 0, { }* bitcast (%llvm.dbg.compositetype.type* @llvm.dbg.compositetype to { }*) }, section "llvm.metadata"		; <%llvm.dbg.derivedtype.type*> [#uses=1]
+ at llvm.dbg.compositetype = internal constant %llvm.dbg.compositetype.type { i32 393235, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i8* getelementptr ([3 x i8]* @.str5, i32 0, i32 0), { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*), i32 1, i64 0, i64 8, i64 0, i32 4, { }* null, { }* bitcast ([0 x { }*]* @llvm.dbg.array to { }*) }, section "llvm.metadata"		; <%llvm.dbg.compositetype.type*> [#uses=1]
+ at .str5 = internal constant [3 x i8] c"ST\00", section "llvm.metadata"		; <[3 x i8]*> [#uses=1]
+ at llvm.dbg.array = internal constant [0 x { }*] zeroinitializer, section "llvm.metadata"		; <[0 x { }*]*> [#uses=1]
+
+define void @foo(%struct.ST* %x1) nounwind {
+entry:
+	%x_addr = alloca %struct.ST*		; <%struct.ST**> [#uses=2]
+	%"alloca point" = bitcast i32 0 to i32		; <i32> [#uses=0]
+	call void @llvm.dbg.func.start({ }* bitcast (%llvm.dbg.subprogram.type* @llvm.dbg.subprogram to { }*))
+	%x = bitcast %struct.ST** %x_addr to { }*		; <{ }*> [#uses=1]
+	call void @llvm.dbg.declare({ }* %x, { }* bitcast (%llvm.dbg.variable.type* @llvm.dbg.variable to { }*))
+	store %struct.ST* %x1, %struct.ST** %x_addr
+	call void @llvm.dbg.stoppoint(i32 4, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+	br label %return
+
+return:		; preds = %entry
+	call void @llvm.dbg.stoppoint(i32 4, i32 0, { }* bitcast (%llvm.dbg.compile_unit.type* @llvm.dbg.compile_unit to { }*))
+	call void @llvm.dbg.region.end({ }* bitcast (%llvm.dbg.subprogram.type* @llvm.dbg.subprogram to { }*))
+	ret void
+}
+
+declare void @llvm.dbg.func.start({ }*) nounwind
+
+declare void @llvm.dbg.declare({ }*, { }*) nounwind
+
+declare void @llvm.dbg.stoppoint(i32, i32, { }*) nounwind
+
+declare void @llvm.dbg.region.end({ }*) nounwind





More information about the llvm-commits mailing list