Index: lib/CodeGen/AsmPrinter/DwarfDebug.cpp =================================================================== --- lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -522,16 +522,18 @@ } void DwarfDebug::finishSubprogramDefinitions() { + SmallPtrSet FinalizedSPNodes; for (auto &F : MMI->getModule()->functions()) if (auto *SP = F.getSubprogram()) if (ProcessedSPNodes.count(SP) && SP->getUnit()->getEmissionKind() != DICompileUnit::NoDebug) forBothCUs(*CUMap.lookup(SP->getUnit()), [&](DwarfCompileUnit &CU) { CU.finishSubprogramDefinition(SP); + FinalizedSPNodes.insert(SP); }); for (auto *AbsScope : LScopes.getAbstractScopesList()) if (auto *SP = dyn_cast(AbsScope->getScopeNode())) - if (ProcessedSPNodes.count(SP) && + if (ProcessedSPNodes.count(SP) && !FinalizedSPNodes.count(SP) && SP->getUnit()->getEmissionKind() != DICompileUnit::NoDebug) forBothCUs(*CUMap.lookup(SP->getUnit()), [&](DwarfCompileUnit &CU) { CU.finishSubprogramDefinition(SP); Index: test/DebugInfo/X86/abstract_origin.ll =================================================================== --- /dev/null +++ test/DebugInfo/X86/abstract_origin.ll @@ -0,0 +1,71 @@ +; RUN: %llc_dwarf -filetype=obj %s -o - | llvm-dwarfdump -debug-dump=info - | FileCheck %s +; Generated at -O2 from: +; int bar(int x) { +; +; return x+1; +; } +; +; int foo(int y) { +; return bar(y); +; } +; +; CHECK: DW_TAG_subprogram +; CHECK: DW_AT_abstract_origin {{.*}}"bar" +; CHECK-NOT: DW_AT_abstract_origin {{.*}}"bar" +; CHECK: DW_TAG +source_filename = "test.c" +target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-apple-macosx10.11.0" + +; Function Attrs: nounwind readnone ssp uwtable +define i32 @bar(i32 %x) #0 !dbg !7 { +entry: + tail call void @llvm.dbg.value(metadata i32 %x, i64 0, metadata !12, metadata !13), !dbg !14 + %add = add nsw i32 %x, 1, !dbg !15 + ret i32 %add, !dbg !16 +} + +; Function Attrs: nounwind readnone ssp uwtable +define i32 @foo(i32 %y) #0 !dbg !17 { +entry: + tail call void @llvm.dbg.value(metadata i32 %y, i64 0, metadata !19, metadata !13), !dbg !20 + tail call void @llvm.dbg.value(metadata i32 %y, i64 0, metadata !12, metadata !13), !dbg !21 + %add.i = add nsw i32 %y, 1, !dbg !23 + ret i32 %add.i, !dbg !24 +} + +; Function Attrs: nounwind readnone +declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #1 + +attributes #0 = { nounwind readnone ssp uwtable } +attributes #1 = { nounwind readnone } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4, !5} +!llvm.ident = !{!6} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.9.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2) +!1 = !DIFile(filename: "test.c", directory: "/Volumes/Data/llvm") +!2 = !{} +!3 = !{i32 2, !"Dwarf Version", i32 2} +!4 = !{i32 2, !"Debug Info Version", i32 3} +!5 = !{i32 1, !"PIC Level", i32 2} +!6 = !{!"clang version 3.9.0 "} +!7 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 1, type: !8, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !11) +!8 = !DISubroutineType(types: !9) +!9 = !{!10, !10} +!10 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) +!11 = !{!12} +!12 = !DILocalVariable(name: "x", arg: 1, scope: !7, file: !1, line: 1, type: !10) +!13 = !DIExpression() +!14 = !DILocation(line: 1, column: 13, scope: !7) +!15 = !DILocation(line: 3, column: 11, scope: !7) +!16 = !DILocation(line: 3, column: 3, scope: !7) +!17 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 6, type: !8, isLocal: false, isDefinition: true, scopeLine: 6, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !18) +!18 = !{!19} +!19 = !DILocalVariable(name: "y", arg: 1, scope: !17, file: !1, line: 6, type: !10) +!20 = !DILocation(line: 6, column: 13, scope: !17) +!21 = !DILocation(line: 1, column: 13, scope: !7, inlinedAt: !22) +!22 = distinct !DILocation(line: 7, column: 10, scope: !17) +!23 = !DILocation(line: 3, column: 11, scope: !7, inlinedAt: !22) +!24 = !DILocation(line: 7, column: 3, scope: !17)