[llvm] r360458 - DebugInfo: Only move types out of type units if they're named or type united
David Blaikie via llvm-commits
llvm-commits at lists.llvm.org
Fri May 10 12:15:29 PDT 2019
Author: dblaikie
Date: Fri May 10 12:15:29 2019
New Revision: 360458
URL: http://llvm.org/viewvc/llvm-project?rev=360458&view=rev
Log:
DebugInfo: Only move types out of type units if they're named or type united
Follow up to r359122, after a bug was reported in it - the original
change too aggressively tried to move related types out of type units,
which included unnamed types (like array types) which can't reasonably
be declared-but-not-defined.
A step beyond that is that some types in type units can be anonymous, if
they are types with a name for linkage purposes (eg: "typedef struct { }
x;"). So ensure those don't get turned into plain declarations (without
signatures) because, lacking names, they can't be resolved to the
definition.
[Also include a fix for llvm-dwarfdump/libDebugInfoDWARF to pretty print
types in type units]
Added:
llvm/trunk/test/DebugInfo/X86/tu-to-non-named-type.ll
Modified:
llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFFormValue.h
llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp
llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp
Modified: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFFormValue.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFFormValue.h?rev=360458&r1=360457&r2=360458&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFFormValue.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFFormValue.h Fri May 10 12:15:29 2019
@@ -104,6 +104,11 @@ public:
/// getAsFoo functions below return the extracted value as Foo if only
/// DWARFFormValue has form class is suitable for representing Foo.
Optional<uint64_t> getAsReference() const;
+ struct UnitOffset {
+ DWARFUnit *Unit;
+ uint64_t Offset;
+ };
+ Optional<UnitOffset> getAsRelativeReference() const;
Optional<uint64_t> getAsUnsignedConstant() const;
Optional<int64_t> getAsSignedConstant() const;
Optional<const char *> getAsCString() const;
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp?rev=360458&r1=360457&r2=360458&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp Fri May 10 12:15:29 2019
@@ -639,7 +639,8 @@ DIE *DwarfUnit::createTypeDIE(const DISc
else if (auto *STy = dyn_cast<DISubroutineType>(Ty))
constructTypeDIE(TyDIE, STy);
else if (auto *CTy = dyn_cast<DICompositeType>(Ty)) {
- if (DD->generateTypeUnits() && !Ty->isForwardDecl()) {
+ if (DD->generateTypeUnits() && !Ty->isForwardDecl() &&
+ (Ty->getRawName() || CTy->getRawIdentifier())) {
// Skip updating the accelerator tables since this is not the full type.
if (MDString *TypeId = CTy->getRawIdentifier())
DD->addDwarfTypeUnitType(getCU(), TypeId->getString(), TyDIE, CTy);
Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp?rev=360458&r1=360457&r2=360458&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp Fri May 10 12:15:29 2019
@@ -429,9 +429,11 @@ DWARFDie::getAttributeValueAsReferencedD
DWARFDie
DWARFDie::getAttributeValueAsReferencedDie(const DWARFFormValue &V) const {
- if (auto SpecRef = toReference(V)) {
- if (auto SpecUnit = U->getUnitVector().getUnitForOffset(*SpecRef))
- return SpecUnit->getDIEForOffset(*SpecRef);
+ if (auto SpecRef = V.getAsRelativeReference()) {
+ if (SpecRef->Unit)
+ return SpecRef->Unit->getDIEForOffset(SpecRef->Unit->getOffset() + SpecRef->Offset);
+ if (auto SpecUnit = U->getUnitVector().getUnitForOffset(SpecRef->Offset))
+ return SpecUnit->getDIEForOffset(SpecRef->Offset);
}
return DWARFDie();
}
Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp?rev=360458&r1=360457&r2=360458&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp Fri May 10 12:15:29 2019
@@ -639,6 +639,12 @@ DWARFFormValue::getAsSectionedAddress()
}
Optional<uint64_t> DWARFFormValue::getAsReference() const {
+ if (auto R = getAsRelativeReference())
+ return R->Unit ? R->Unit->getOffset() + R->Offset : R->Offset;
+ return None;
+}
+
+Optional<DWARFFormValue::UnitOffset> DWARFFormValue::getAsRelativeReference() const {
if (!isFormClass(FC_Reference))
return None;
switch (Form) {
@@ -649,11 +655,11 @@ Optional<uint64_t> DWARFFormValue::getAs
case DW_FORM_ref_udata:
if (!U)
return None;
- return Value.uval + U->getOffset();
+ return UnitOffset{const_cast<DWARFUnit*>(U), Value.uval};
case DW_FORM_ref_addr:
case DW_FORM_ref_sig8:
case DW_FORM_GNU_ref_alt:
- return Value.uval;
+ return UnitOffset{nullptr, Value.uval};
default:
return None;
}
Added: llvm/trunk/test/DebugInfo/X86/tu-to-non-named-type.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/tu-to-non-named-type.ll?rev=360458&view=auto
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/tu-to-non-named-type.ll (added)
+++ llvm/trunk/test/DebugInfo/X86/tu-to-non-named-type.ll Fri May 10 12:15:29 2019
@@ -0,0 +1,79 @@
+; REQUIRES: object-emission
+
+; RUN: llc -filetype=obj -O0 -generate-type-units -mtriple=x86_64-unknown-linux-gnu < %s \
+; RUN: | llvm-dwarfdump -debug-info -debug-types - | FileCheck %s
+
+; CHECK: Compile Unit:
+
+; CHECK: Type Unit:
+; CHECK: DW_TAG_structure
+; CHECK-NOT: {{DW_TAG|NULL}}
+; CHECK: DW_AT_name ("foo")
+; CHECK-NOT: {{DW_TAG|NULL}}
+; CHECK: DW_TAG_member
+; CHECK-NEXT: DW_AT_name ("x")
+; CHECK-NEXT: DW_AT_type ({{.*}} "int[1]"
+
+; But make sure we still use a type unit for an anonymous type that still has a
+; name for linkage purposes (due to being defined in a typedef).
+
+; CHECK: Type Unit:
+; CHECK: DW_TAG_structure
+; CHECK-NEXT: DW_AT_calling_convention
+; CHECK-NEXT: DW_AT_byte_size
+; CHECK-NEXT: DW_AT_decl_file
+; CHECK-NEXT: DW_AT_decl_line
+; CHECK-NOT: DW
+; CHECK: NULL
+
+%struct.foo = type { [1 x i32] }
+%struct.bar = type { i8 }
+
+; Function Attrs: noinline nounwind optnone uwtable
+define dso_local void @_Z1f3foo3bar(i32 %.coerce) #0 !dbg !7 {
+entry:
+ %0 = alloca %struct.foo, align 4
+ %1 = alloca %struct.bar, align 1
+ %coerce.dive = getelementptr inbounds %struct.foo, %struct.foo* %0, i32 0, i32 0
+ %2 = bitcast [1 x i32]* %coerce.dive to i32*
+ store i32 %.coerce, i32* %2, align 4
+ call void @llvm.dbg.declare(metadata %struct.foo* %0, metadata !19, metadata !DIExpression()), !dbg !20
+ call void @llvm.dbg.declare(metadata %struct.bar* %1, metadata !21, metadata !DIExpression()), !dbg !22
+ ret void, !dbg !23
+}
+
+; Function Attrs: nounwind readnone speculatable
+declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
+
+attributes #0 = { noinline nounwind optnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #1 = { nounwind readnone speculatable }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4, !5}
+!llvm.ident = !{!6}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 9.0.0 (trunk 360374) (llvm/trunk 360380)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
+!1 = !DIFile(filename: "named_types.cpp", directory: "/usr/local/google/home/blaikie/dev/scratch")
+!2 = !{}
+!3 = !{i32 2, !"Dwarf Version", i32 4}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{i32 1, !"wchar_size", i32 4}
+!6 = !{!"clang version 9.0.0 (trunk 360374) (llvm/trunk 360380)"}
+!7 = distinct !DISubprogram(name: "f", linkageName: "_Z1f3foo3bar", scope: !1, file: !1, line: 6, type: !8, scopeLine: 6, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
+!8 = !DISubroutineType(types: !9)
+!9 = !{null, !10, !17}
+!10 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "foo", file: !1, line: 1, size: 32, flags: DIFlagTypePassByValue, elements: !11, identifier: "_ZTS3foo")
+!11 = !{!12}
+!12 = !DIDerivedType(tag: DW_TAG_member, name: "x", scope: !10, file: !1, line: 2, baseType: !13, size: 32)
+!13 = !DICompositeType(tag: DW_TAG_array_type, baseType: !14, size: 32, elements: !15)
+!14 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!15 = !{!16}
+!16 = !DISubrange(count: 1)
+!17 = !DIDerivedType(tag: DW_TAG_typedef, name: "bar", file: !1, line: 5, baseType: !18)
+!18 = distinct !DICompositeType(tag: DW_TAG_structure_type, file: !1, line: 4, size: 8, flags: DIFlagTypePassByValue, elements: !2, identifier: "_ZTS3bar")
+!19 = !DILocalVariable(arg: 1, scope: !7, file: !1, line: 6, type: !10)
+!20 = !DILocation(line: 6, column: 11, scope: !7)
+!21 = !DILocalVariable(arg: 2, scope: !7, file: !1, line: 6, type: !17)
+!22 = !DILocation(line: 6, column: 16, scope: !7)
+!23 = !DILocation(line: 7, column: 1, scope: !7)
+
More information about the llvm-commits
mailing list