Index: lib/CodeGen/AsmPrinter/DwarfUnit.h =================================================================== --- lib/CodeGen/AsmPrinter/DwarfUnit.h +++ lib/CodeGen/AsmPrinter/DwarfUnit.h @@ -244,7 +244,7 @@ void addConstantFPValue(DIE &Die, const ConstantFP *CFP); /// Add a linkage name, if it isn't empty. - void addLinkageName(DIE &Die, StringRef LinkageName); + void addLinkageName(DIE &Die, StringRef LinkageName, bool Force = false); /// Add template parameters in buffer. void addTemplateParams(DIE &Buffer, DINodeArray TParams); Index: lib/CodeGen/AsmPrinter/DwarfUnit.cpp =================================================================== --- lib/CodeGen/AsmPrinter/DwarfUnit.cpp +++ lib/CodeGen/AsmPrinter/DwarfUnit.cpp @@ -664,8 +664,8 @@ addBlock(Die, dwarf::DW_AT_const_value, Block); } -void DwarfUnit::addLinkageName(DIE &Die, StringRef LinkageName) { - if (!LinkageName.empty() && DD->useLinkageNames()) +void DwarfUnit::addLinkageName(DIE &Die, StringRef LinkageName, bool Force) { + if (!LinkageName.empty() && (DD->useLinkageNames() || Force)) addString(Die, DD->getDwarfVersion() >= 4 ? dwarf::DW_AT_linkage_name : dwarf::DW_AT_MIPS_linkage_name, @@ -1169,8 +1169,11 @@ assert(((LinkageName.empty() || DeclLinkageName.empty()) || LinkageName == DeclLinkageName) && "decl has a linkage name and it is different"); - if (DeclLinkageName.empty()) - addLinkageName(SPDie, LinkageName); + if (DeclLinkageName.empty()) { + // Abstract origins must have a linkage name. + bool Abstract = DU->getAbstractSPDies().lookup(SP); + addLinkageName(SPDie, LinkageName, Abstract); + } if (!DeclDie) return false; Index: test/DebugInfo/Generic/linkage-name-abstract.ll =================================================================== --- test/DebugInfo/Generic/linkage-name-abstract.ll +++ test/DebugInfo/Generic/linkage-name-abstract.ll @@ -0,0 +1,70 @@ +; RUN: %llc_dwarf -O0 -filetype=obj -dwarf-linkage-names=Disable < %s | llvm-dwarfdump -debug-dump=info - > %t +; RUN: FileCheck %s -check-prefix=ONENAME < %t +; RUN: FileCheck %s -check-prefix=REF < %t +; REQUIRES: object-emission + +; Even with linkage-names disabled, the abstract-origin of inlined subprograms +; needs a linkage name (there's no other way to find that name). + +; IR generated from clang -O0 with: +; void f1(); +; __attribute__((always_inline)) void f2() { +; f1(); +; } +; void f3() { +; f2(); +; } + +; Show that there's only one linkage_name. +; ONENAME: {{DW_AT(_MIPS)?_linkage_name}} +; ONENAME-NOT: {{DW_AT(_MIPS)?_linkage_name}} + +; Locate the subprogram DIE with the linkage name. +; Show that the inlined_subroutine refers to it. +; REF: DW_TAG_subprogram +; REF: [[FOO:0x.*]]: DW_TAG_subprogram +; REF-NOT: {{DW_TAG|NULL}} +; REF: {{DW_AT(_MIPS)?_linkage_name}} +; REF: DW_TAG_inlined_subroutine +; REF-NOT: {{DW_TAG|NULL}} +; REF: DW_AT_abstract_origin {{.*}} {[[FOO]]} + +; Function Attrs: alwaysinline uwtable +define void @_Z2f2v() #0 !dbg !4 { +entry: + call void @_Z2f1v(), !dbg !11 + ret void, !dbg !12 +} + +declare void @_Z2f1v() + +; Function Attrs: uwtable +define void @_Z2f3v() #2 !dbg !7 { +entry: + call void @_Z2f1v(), !dbg !13 + ret void, !dbg !15 +} + +attributes #0 = { alwaysinline uwtable } +attributes #2 = { uwtable } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!8, !9} +!llvm.ident = !{!10} + +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.9.0 (trunk 265282)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, subprograms: !3) +!1 = !DIFile(filename: "linkage-name-abstract.cpp", directory: "/home/probinson/projects/scratch") +!2 = !{} +!3 = !{!4, !7} +!4 = distinct !DISubprogram(name: "f2", linkageName: "_Z2f2v", scope: !1, file: !1, line: 2, type: !5, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: false, variables: !2) +!5 = !DISubroutineType(types: !6) +!6 = !{null} +!7 = distinct !DISubprogram(name: "f3", linkageName: "_Z2f3v", scope: !1, file: !1, line: 5, type: !5, isLocal: false, isDefinition: true, scopeLine: 5, flags: DIFlagPrototyped, isOptimized: false, variables: !2) +!8 = !{i32 2, !"Dwarf Version", i32 4} +!9 = !{i32 2, !"Debug Info Version", i32 3} +!10 = !{!"clang version 3.9.0 (trunk 265282)"} +!11 = !DILocation(line: 3, column: 3, scope: !4) +!12 = !DILocation(line: 4, column: 1, scope: !4) +!13 = !DILocation(line: 3, column: 3, scope: !4, inlinedAt: !14) +!14 = distinct !DILocation(line: 6, column: 3, scope: !7) +!15 = !DILocation(line: 7, column: 1, scope: !7)