summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvan Cheng <evan.cheng@apple.com>2008-12-10 00:15:44 +0000
committerEvan Cheng <evan.cheng@apple.com>2008-12-10 00:15:44 +0000
commit94ea5be39fe379cda3ff144a99b6a1a69a9fe2e2 (patch)
treeed64507396551b399c479df97b737c56ad1cabb6
parentaedc637c966b6eaa3ca33e9220efe5ec34517de7 (diff)
downloadllvm-94ea5be39fe379cda3ff144a99b6a1a69a9fe2e2.tar.gz
llvm-94ea5be39fe379cda3ff144a99b6a1a69a9fe2e2.tar.bz2
llvm-94ea5be39fe379cda3ff144a99b6a1a69a9fe2e2.tar.xz
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60812 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/CodeGen/MachineModuleInfo.h9
-rw-r--r--lib/CodeGen/AsmPrinter/DwarfWriter.cpp21
-rw-r--r--lib/CodeGen/MachineModuleInfo.cpp9
-rw-r--r--test/DebugInfo/forwardDecl.ll49
4 files changed, 79 insertions, 9 deletions
diff --git a/include/llvm/CodeGen/MachineModuleInfo.h b/include/llvm/CodeGen/MachineModuleInfo.h
index 46bf7904c7..61befb5cfb 100644
--- a/include/llvm/CodeGen/MachineModuleInfo.h
+++ b/include/llvm/CodeGen/MachineModuleInfo.h
@@ -282,7 +282,8 @@ class TypeDesc : public DebugInfoDesc {
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 @@ private:
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 @@ public:
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 @@ public:
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.
///
diff --git a/lib/CodeGen/AsmPrinter/DwarfWriter.cpp b/lib/CodeGen/AsmPrinter/DwarfWriter.cpp
index 9ca9e28010..4476be3bb3 100644
--- a/lib/CodeGen/AsmPrinter/DwarfWriter.cpp
+++ b/lib/CodeGen/AsmPrinter/DwarfWriter.cpp
@@ -1774,14 +1774,25 @@ private:
}
}
- // 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.
diff --git a/lib/CodeGen/MachineModuleInfo.cpp b/lib/CodeGen/MachineModuleInfo.cpp
index 9e0e9025a4..f93f27c934 100644
--- a/lib/CodeGen/MachineModuleInfo.cpp
+++ b/lib/CodeGen/MachineModuleInfo.cpp
@@ -906,7 +906,8 @@ void BasicTypeDesc::dump() {
<< "Context(" << getContext() << "), "
<< "Name(\"" << getName() << "\"), "
<< "Size(" << getSize() << "), "
- << "Encoding(" << Encoding << ")\n";
+ << "Encoding(" << Encoding << "),"
+ << "Flags(" << Flags << ")\n";
}
#endif
@@ -965,7 +966,8 @@ void DerivedTypeDesc::dump() {
<< "Size(" << getSize() << "), "
<< "File(" << getFile() << "), "
<< "Line(" << getLine() << "), "
- << "FromType(" << FromType << ")\n";
+ << "FromType(" << FromType << "),"
+ << "Flags(" << Flags << ")\n";
}
#endif
@@ -1023,7 +1025,8 @@ void CompositeTypeDesc::dump() {
<< "File(" << getFile() << "), "
<< "Line(" << getLine() << "), "
<< "FromType(" << getFromType() << "), "
- << "Elements.size(" << Elements.size() << ")\n";
+ << "Elements.size(" << Elements.size() << "),"
+ << "Flags(" << Flags << ")\n";
}
#endif
diff --git a/test/DebugInfo/forwardDecl.ll b/test/DebugInfo/forwardDecl.ll
new file mode 100644
index 0000000000..a8bb9fffd0
--- /dev/null
+++ b/test/DebugInfo/forwardDecl.ll
@@ -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
+@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]
+@llvm.dbg.subprograms = linkonce constant %llvm.dbg.anchor.type { i32 393216, i32 46 }, section "llvm.metadata" ; <%llvm.dbg.anchor.type*> [#uses=1]
+@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]
+@llvm.dbg.compile_units = linkonce constant %llvm.dbg.anchor.type { i32 393216, i32 17 }, section "llvm.metadata" ; <%llvm.dbg.anchor.type*> [#uses=1]
+@.str = internal constant [4 x i8] c"t.c\00", section "llvm.metadata" ; <[20 x i8]*> [#uses=1]
+@.str1 = internal constant [36 x i8] c"/Users/echeng/LLVM/radars/r6395152/\00", section "llvm.metadata" ; <[36 x i8]*> [#uses=1]
+@.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]
+@.str3 = internal constant [4 x i8] c"foo\00", section "llvm.metadata" ; <[4 x i8]*> [#uses=1]
+@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]
+@.str4 = internal constant [2 x i8] c"x\00", section "llvm.metadata" ; <[2 x i8]*> [#uses=1]
+@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]
+@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]
+@.str5 = internal constant [3 x i8] c"ST\00", section "llvm.metadata" ; <[3 x i8]*> [#uses=1]
+@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