Index: lib/CodeGen/AsmPrinter/DwarfUnit.cpp =================================================================== --- lib/CodeGen/AsmPrinter/DwarfUnit.cpp +++ lib/CodeGen/AsmPrinter/DwarfUnit.cpp @@ -1152,7 +1152,8 @@ assert(DeclDie && "This DIE should've already been constructed when the " "definition DIE was created in " "getOrCreateSubprogramDIE"); - DeclLinkageName = SPDecl->getLinkageName(); + if (DD->useAllLinkageNames()) + DeclLinkageName = SPDecl->getLinkageName(); unsigned DeclID = getOrCreateSourceID(SPDecl->getFilename(), SPDecl->getDirectory()); unsigned DefID = getOrCreateSourceID(SP->getFilename(), SP->getDirectory()); Index: test/DebugInfo/Generic/linkage-name-abstract.ll =================================================================== --- test/DebugInfo/Generic/linkage-name-abstract.ll +++ test/DebugInfo/Generic/linkage-name-abstract.ll @@ -18,56 +18,143 @@ ; void f3() { ; f2(); ; } +; +; struct F4 { +; __attribute__((always_inline)) void f5(); +; }; +; void F4::f5() { +; f1(); +; } +; void f6() { +; F4 f; +; f.f5(); +; } -; Show that there's only one linkage_name. -; ONENAME: {{DW_AT(_MIPS)?_linkage_name}} +; Show that the only linkage names are for the inlined functions, +; because those are the ones with an abstract origin. +; ONENAME-NOT: {{DW_AT(_MIPS)?_linkage_name}} +; ONENAME: {{DW_AT(_MIPS)?_linkage_name}} {{.*}} "_Z2f2v" ; ONENAME-NOT: {{DW_AT(_MIPS)?_linkage_name}} +; ONENAME: {{DW_AT(_MIPS)?_linkage_name}} {{.*}} "_ZN2F42f5Ev" +; ONENAME-NOT: {{DW_AT(_MIPS)?_linkage_name}} + +; For f2() we see the definition pointing to an abstract origin DIE, +; which in turn is where the linkage_name is; and then there's +; an inlined_subroutine pointing back to the abstract origin. +; The order of these DIEs is not important of course, just the links. +; REF: DW_TAG_subprogram +; REF-NOT: {{DW_TAG|NULL}} +; REF: DW_AT_abstract_origin {{.*}} {[[F2:0x.*]]} "_Z2f2v" +; REF: [[F2]]: DW_TAG_subprogram +; REF-NEXT: linkage_name {{.*}} "_Z2f2v" +; REF: DW_TAG_inlined_subroutine +; REF-NOT: {{DW_TAG|NULL}} +; REF: DW_AT_abstract_origin {{.*}} {[[F2]]} + +; For F4::f5(), first we see the in-class declaration, +; then the definition, abstract origin, and the inlined_subroutine. +; REF: DW_TAG_structure_type +; REF-NEXT: DW_AT_name {{.*}} "F4" +; REF-NOT: {{DW_TAG|NULL}} +; REF: [[F5_DECL:0x.*]]: DW_TAG_subprogram +; REF-NEXT: DW_AT_name {{.*}} "f5" +; REF: DW_TAG_subprogram +; REF-NOT: {{DW_TAG|NULL}} +; REF: DW_AT_abstract_origin {{.*}} {[[F5_ABS:0x.*]]} "_ZN2F42f5Ev" +; REF: [[F5_ABS]]: DW_TAG_subprogram +; REF-NOT: {{DW_TAG|NULL}} +; REF: linkage_name {{.*}} "_ZN2F42f5Ev" +; REF-NEXT: DW_AT_specification {{.*}} {[[F5_DECL]]} +; REF: DW_TAG_inlined_subroutine +; REF-NOT: {{DW_TAG|NULL}} +; REF: DW_AT_abstract_origin {{.*}} {[[F5_ABS]]} -; 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]]} + +%struct.F4 = type { i8 } ; Function Attrs: alwaysinline uwtable -define void @_Z2f2v() #0 !dbg !4 { +define void @_Z2f2v() #0 !dbg !6 { entry: - call void @_Z2f1v(), !dbg !11 - ret void, !dbg !12 + call void @_Z2f1v(), !dbg !9 + ret void, !dbg !10 } declare void @_Z2f1v() ; Function Attrs: uwtable -define void @_Z2f3v() #2 !dbg !7 { +define void @_Z2f3v() !dbg !11 { +entry: + call void @_Z2f1v(), !dbg !12 + ret void, !dbg !14 +} + +; Function Attrs: alwaysinline uwtable +define void @_ZN2F42f5Ev(%struct.F4* %this) #0 align 2 !dbg !15 { +entry: + %this.addr = alloca %struct.F4*, align 8 + store %struct.F4* %this, %struct.F4** %this.addr, align 8 + call void @llvm.dbg.declare(metadata %struct.F4** %this.addr, metadata !22, metadata !24), !dbg !25 + %this1 = load %struct.F4*, %struct.F4** %this.addr, align 8 + call void @_Z2f1v(), !dbg !26 + ret void, !dbg !27 +} + +; Function Attrs: nounwind readnone +declare void @llvm.dbg.declare(metadata, metadata, metadata) #3 + +; Function Attrs: uwtable +define void @_Z2f6v() !dbg !28 { entry: - call void @_Z2f1v(), !dbg !13 - ret void, !dbg !15 + %this.addr.i = alloca %struct.F4*, align 8 + call void @llvm.dbg.declare(metadata %struct.F4** %this.addr.i, metadata !22, metadata !24), !dbg !29 + %f = alloca %struct.F4, align 1 + call void @llvm.dbg.declare(metadata %struct.F4* %f, metadata !31, metadata !24), !dbg !32 + store %struct.F4* %f, %struct.F4** %this.addr.i, align 8, !dbg !33 + %this1.i = load %struct.F4*, %struct.F4** %this.addr.i, align 8, !dbg !33 + call void @_Z2f1v(), !dbg !34 + ret void, !dbg !35 } -attributes #0 = { alwaysinline uwtable } -attributes #2 = { uwtable } +attributes #0 = { alwaysinline } +attributes #3 = { nounwind readnone } !llvm.dbg.cu = !{!0} -!llvm.module.flags = !{!8, !9} -!llvm.ident = !{!10} +!llvm.module.flags = !{!3, !4} +!llvm.ident = !{!5} -!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) +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 4.0.0 (trunk 288231)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2) !1 = !DIFile(filename: "linkage-name-abstract.cpp", directory: "/home/probinson/projects/scratch") !2 = !{} -!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, unit: !0, 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, unit: !0, 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) +!3 = !{i32 2, !"Dwarf Version", i32 4} +!4 = !{i32 2, !"Debug Info Version", i32 3} +!5 = !{!"clang version 4.0.0 (trunk 288231)"} +!6 = distinct !DISubprogram(name: "f2", linkageName: "_Z2f2v", scope: !1, file: !1, line: 2, type: !7, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2) +!7 = !DISubroutineType(types: !8) +!8 = !{null} +!9 = !DILocation(line: 3, column: 3, scope: !6) +!10 = !DILocation(line: 4, column: 1, scope: !6) +!11 = distinct !DISubprogram(name: "f3", linkageName: "_Z2f3v", scope: !1, file: !1, line: 5, type: !7, isLocal: false, isDefinition: true, scopeLine: 5, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2) +!12 = !DILocation(line: 3, column: 3, scope: !6, inlinedAt: !13) +!13 = distinct !DILocation(line: 6, column: 3, scope: !11) +!14 = !DILocation(line: 7, column: 1, scope: !11) +!15 = distinct !DISubprogram(name: "f5", linkageName: "_ZN2F42f5Ev", scope: !16, file: !1, line: 12, type: !19, isLocal: false, isDefinition: true, scopeLine: 12, flags: DIFlagPrototyped, isOptimized: false, unit: !0, declaration: !18, variables: !2) +!16 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "F4", file: !1, line: 9, size: 8, elements: !17, identifier: "_ZTS2F4") +!17 = !{!18} +!18 = !DISubprogram(name: "f5", linkageName: "_ZN2F42f5Ev", scope: !16, file: !1, line: 10, type: !19, isLocal: false, isDefinition: false, scopeLine: 10, flags: DIFlagPrototyped, isOptimized: false) +!19 = !DISubroutineType(types: !20) +!20 = !{null, !21} +!21 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !16, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer) +!22 = !DILocalVariable(name: "this", arg: 1, scope: !15, type: !23, flags: DIFlagArtificial | DIFlagObjectPointer) +!23 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !16, size: 64) +!24 = !DIExpression() +!25 = !DILocation(line: 0, scope: !15) +!26 = !DILocation(line: 13, column: 3, scope: !15) +!27 = !DILocation(line: 14, column: 1, scope: !15) +!28 = distinct !DISubprogram(name: "f6", linkageName: "_Z2f6v", scope: !1, file: !1, line: 15, type: !7, isLocal: false, isDefinition: true, scopeLine: 15, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2) +!29 = !DILocation(line: 0, scope: !15, inlinedAt: !30) +!30 = distinct !DILocation(line: 17, column: 5, scope: !28) +!31 = !DILocalVariable(name: "f", scope: !28, file: !1, line: 16, type: !16) +!32 = !DILocation(line: 16, column: 6, scope: !28) +!33 = !DILocation(line: 17, column: 5, scope: !28) +!34 = !DILocation(line: 13, column: 3, scope: !15, inlinedAt: !30) +!35 = !DILocation(line: 18, column: 1, scope: !28)