Index: lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp =================================================================== --- lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp +++ lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp @@ -660,18 +660,11 @@ } void DwarfCompileUnit::finishSubprogramDefinition(const DISubprogram *SP) { - DIE *D = getDIE(SP); - if (DIE *AbsSPDIE = DU->getAbstractSPDies().lookup(SP)) { - if (D) + if (DIE *D = getDIE(SP)) { + if (DIE *AbsSPDIE = DU->getAbstractSPDies().lookup(SP)) // If this subprogram has an abstract definition, reference that addDIEEntry(*D, dwarf::DW_AT_abstract_origin, *AbsSPDIE); - } else { - if (!D && !includeMinimalInlineScopes()) - // Lazily construct the subprogram if we didn't see either concrete or - // inlined versions during codegen. (except in -gmlt ^ where we want - // to omit these entirely) - D = getOrCreateSubprogramDIE(SP); - if (D) + else // And attach the attributes applySubprogramAttributesToDefinition(SP, *D); } @@ -686,7 +679,7 @@ DIE *SPDIE = DU->getAbstractSPDies().lookup(SP); if (!SPDIE) - SPDIE = getDIE(SP); + return; assert(SPDIE); for (const DILocalVariable *DV : Variables) { DbgVariable NewVar(DV, /* IA */ nullptr, DD); Index: test/DebugInfo/X86/dbg-file-name.ll =================================================================== --- test/DebugInfo/X86/dbg-file-name.ll +++ test/DebugInfo/X86/dbg-file-name.ll @@ -6,7 +6,7 @@ declare i32 @printf(i8*, ...) nounwind define i32 @main() nounwind { - ret i32 0 + ret i32 0, !dbg !13 } !llvm.dbg.cu = !{!2} @@ -22,3 +22,4 @@ !10 = !DIFile(filename: "simple.c", directory: "/Users/manav/one/two") !11 = !{} !12 = !{i32 1, !"Debug Info Version", i32 3} +!13 = !DILocation(line: 10, scope: !6) Index: test/DebugInfo/X86/debug-dead-local-var.ll =================================================================== --- test/DebugInfo/X86/debug-dead-local-var.ll +++ test/DebugInfo/X86/debug-dead-local-var.ll @@ -27,7 +27,7 @@ !llvm.module.flags = !{!18, !19} !llvm.ident = !{!20} -!0 = !DICompileUnit(language: DW_LANG_C99, producer: "clang version 3.5.0 (trunk 209255) (llvm/trunk 209253)", isOptimized: true, emissionKind: 1, file: !1, enums: !2, retainedTypes: !2, subprograms: !3, globals: !2, imports: !2) +!0 = !DICompileUnit(language: DW_LANG_C99, producer: "clang version 3.5.0 (trunk 209255) (llvm/trunk 209253)", isOptimized: true, emissionKind: 1, file: !1, enums: !2, retainedTypes: !22, subprograms: !3, globals: !2, imports: !2) !1 = !DIFile(filename: "debug-dead-local-var.c", directory: "/usr/local/google/home/echristo") !2 = !{} !3 = !{!4, !9} @@ -49,3 +49,4 @@ !19 = !{i32 2, !"Debug Info Version", i32 3} !20 = !{!"clang version 3.5.0 (trunk 209255) (llvm/trunk 209253)"} !21 = !DILocation(line: 13, scope: !4) +!22 = !{!14} \ No newline at end of file Index: test/DebugInfo/cross-cu-linkonce-distinct.ll =================================================================== --- test/DebugInfo/cross-cu-linkonce-distinct.ll +++ test/DebugInfo/cross-cu-linkonce-distinct.ll @@ -27,12 +27,8 @@ ; int (*y)(int) = &func; ; CHECK: DW_TAG_compile_unit -; CHECK: DW_TAG_subprogram -; CHECK-NOT: DW_TAG -; CHECK: DW_AT_name {{.*}} "func" -; CHECK: DW_TAG_compile_unit -; FIXME: Maybe we should drop the subprogram here - since the function was +; Check that the subprogram is dropped in this CU - since the function was ; emitted in one CU, due to linkonce_odr uniquing. We certainly don't emit the ; subprogram here if the source location for this definition is the same (see ; test/DebugInfo/cross-cu-linkonce.ll), though it's very easy to tickle that @@ -43,7 +39,12 @@ ; directory of the source file even though the file name is absolute, not ; relative) -; CHECK: DW_TAG_subprogram +; CHECK-NOT: DW_TAG_subprogram + +; CHECK: DW_TAG_compile_unit +; CHECK: DW_TAG_subprogram +; CHECK-NOT: DW_TAG +; CHECK: DW_AT_name {{.*}} "func" @x = global i32 (i32)* @_Z4funci, align 8 @y = global i32 (i32)* @_Z4funci, align 8 Index: test/DebugInfo/nodebug.ll =================================================================== --- test/DebugInfo/nodebug.ll +++ test/DebugInfo/nodebug.ll @@ -16,10 +16,8 @@ ; f1(); ; } -; Check that there's only one DW_TAG_subprogram, nothing for the 'f2' function. -; CHECK: DW_TAG_subprogram -; CHECK-NOT: DW_TAG -; CHECK: DW_AT_name {{.*}} "f1" +; Check that there is no DW_TAG_subprogram, nothing for the 'f2' function. +; Note: No debug info was emitted for 'f1' function because it has no code. ; CHECK-NOT: DW_TAG_subprogram @i = external global i32