Index: include/llvm/Support/Dwarf.h =================================================================== --- include/llvm/Support/Dwarf.h +++ include/llvm/Support/Dwarf.h @@ -238,6 +238,7 @@ DW_AT_GNU_addr_base = 0x2133, DW_AT_GNU_pubnames = 0x2134, DW_AT_GNU_pubtypes = 0x2135, + DW_AT_GNU_discriminator = 0x2136, // LLVM project extensions. DW_AT_LLVM_include_path = 0x3e00, Index: lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp =================================================================== --- lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp +++ lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp @@ -439,6 +439,9 @@ addUInt(*ScopeDIE, dwarf::DW_AT_call_file, None, getOrCreateSourceID(IA->getFilename(), IA->getDirectory())); addUInt(*ScopeDIE, dwarf::DW_AT_call_line, None, IA->getLine()); + if (IA->getDiscriminator()) { + addUInt(*ScopeDIE, dwarf::DW_AT_GNU_discriminator, None, IA->getDiscriminator()); + } // Add name to the name table, we do this here because we're guaranteed // to have concrete versions of our DW_TAG_inlined_subprogram nodes. Index: lib/Support/Dwarf.cpp =================================================================== --- lib/Support/Dwarf.cpp +++ lib/Support/Dwarf.cpp @@ -201,6 +201,7 @@ case DW_AT_GNU_addr_base: return "DW_AT_GNU_addr_base"; case DW_AT_GNU_pubnames: return "DW_AT_GNU_pubnames"; case DW_AT_GNU_pubtypes: return "DW_AT_GNU_pubtypes"; + case DW_AT_GNU_discriminator: return "DW_AT_GNU_discriminator"; } return nullptr; } Index: test/DebugInfo/Generic/discriminator.ll =================================================================== --- /dev/null +++ test/DebugInfo/Generic/discriminator.ll @@ -0,0 +1,67 @@ +; REQUIRES: object-emission + +; RUN: %llc_dwarf < %s -filetype=obj | llvm-dwarfdump -debug-dump=info - | FileCheck %s + +; Given the following source, ensure that the discriminator is emitted for +; the inlined callsite. + +;void abc(); +;void xyz(); +; +;static void bar() { abc(); } +;static void baz() { xyz(); } +; +;void foo(int i) { +; bar(); baz(); +;} + +; CHECK: DW_AT_GNU_discriminator + +; Function Attrs: uwtable +define void @_Z3fooi(i32 %i) #0 !dbg !4 { + tail call void @llvm.dbg.value(metadata i32 %i, i64 0, metadata !9, metadata !17), !dbg !18 + tail call void @_Z3abcv(), !dbg !19 + tail call void @_Z3xyzv(), !dbg !21 + ret void, !dbg !24 +} + +declare void @_Z3abcv() #1 + +declare void @_Z3xyzv() #1 + +; Function Attrs: nounwind readnone +declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #2 + +attributes #0 = { uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #2 = { nounwind readnone } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!14, !15} +!llvm.ident = !{!16} + +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.8.0 (trunk 252497)", isOptimized: true, runtimeVersion: 0, emissionKind: 1, enums: !2, subprograms: !3) +!1 = !DIFile(filename: "a.cc", directory: "/tmp") +!2 = !{} +!3 = !{!4, !10, !13} +!4 = distinct !DISubprogram(name: "foo", linkageName: "_Z3fooi", scope: !1, file: !1, line: 7, type: !5, isLocal: false, isDefinition: true, scopeLine: 7, flags: DIFlagPrototyped, isOptimized: true, variables: !8) +!5 = !DISubroutineType(types: !6) +!6 = !{null, !7} +!7 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) +!8 = !{!9} +!9 = !DILocalVariable(name: "i", arg: 1, scope: !4, file: !1, line: 7, type: !7) +!10 = distinct !DISubprogram(name: "bar", linkageName: "_ZL3barv", scope: !1, file: !1, line: 4, type: !11, isLocal: true, isDefinition: true, scopeLine: 4, flags: DIFlagPrototyped, isOptimized: true, variables: !2) +!11 = !DISubroutineType(types: !12) +!12 = !{null} +!13 = distinct !DISubprogram(name: "baz", linkageName: "_ZL3bazv", scope: !1, file: !1, line: 5, type: !11, isLocal: true, isDefinition: true, scopeLine: 5, flags: DIFlagPrototyped, isOptimized: true, variables: !2) +!14 = !{i32 2, !"Dwarf Version", i32 4} +!15 = !{i32 2, !"Debug Info Version", i32 3} +!16 = !{!"clang version 3.8.0 (trunk 252497)"} +!17 = !DIExpression() +!18 = !DILocation(line: 7, column: 14, scope: !4) +!19 = !DILocation(line: 4, column: 21, scope: !10, inlinedAt: !20) +!20 = distinct !DILocation(line: 8, column: 3, scope: !4) +!21 = !DILocation(line: 5, column: 21, scope: !13, inlinedAt: !22) +!22 = distinct !DILocation(line: 8, column: 10, scope: !23) +!23 = !DILexicalBlockFile(scope: !4, file: !1, discriminator: 1) +!24 = !DILocation(line: 9, column: 1, scope: !4)