Index: lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp =================================================================== --- lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp +++ lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp @@ -420,6 +420,8 @@ assert(Scope->getScopeNode()); auto *DS = Scope->getScopeNode(); auto *InlinedSP = getDISubprogram(DS); + if (InlinedSP->getUnit()->getEmissionKind() == DICompileUnit::NoDebug) + return nullptr; // Find the subprogram's DwarfCompileUnit in the SPMap in case the subprogram // was inlined from another compile unit. DIE *OriginDIE = DU->getAbstractSPDies()[InlinedSP]; Index: lib/CodeGen/AsmPrinter/DwarfDebug.cpp =================================================================== --- lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -366,6 +366,9 @@ auto *SP = cast(Scope->getScopeNode()); + if (SP->getUnit()->getEmissionKind() == DICompileUnit::NoDebug) + return; + ProcessedSPNodes.insert(SP); // Find the subprogram's DwarfCompileUnit in the SPMap in case the subprogram Index: test/DebugInfo/Generic/debug_and_nodebug_CUs.ll =================================================================== --- /dev/null +++ test/DebugInfo/Generic/debug_and_nodebug_CUs.ll @@ -0,0 +1,46 @@ +; Test to ensure that a module containing both a NoDebug CU and one with +; debug is handled correctly. + +; RUN: llc %s -o - | FileCheck %s +; CHECK-DAG: # debug.c: +; CHECK-DAG: # nodebug.c: + +; ModuleID = 'debug_and_nodebug_CUs.bc' +source_filename = "debug_and_nodebug_CUs.ll" +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@.str = private unnamed_addr constant [6 x i8] c"hello\00", align 1 + +; Function Attrs: nounwind uwtable +define i32 @main() local_unnamed_addr #0 !dbg !8 { +entry: + %call.i = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0)) #2, !dbg !10 + ret i32 0, !dbg !13 +} + +; Function Attrs: nounwind +declare i32 @printf(i8* nocapture readonly, ...) local_unnamed_addr #1 + +attributes #0 = { nounwind uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #2 = { nounwind } + +!llvm.dbg.cu = !{!0, !3} +!llvm.ident = !{!5, !5} +!llvm.module.flags = !{!6, !7} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 5.0.0 (trunk 293911) (llvm/trunk 293920)", isOptimized: false, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !2) +!1 = !DIFile(filename: "debug.c", directory: ".") +!2 = !{} +!3 = distinct !DICompileUnit(language: DW_LANG_C99, file: !4, producer: "clang version 5.0.0 (trunk 293911) (llvm/trunk 293920)", isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug, enums: !2) +!4 = !DIFile(filename: "nodebug.c", directory: ".") +!5 = !{!"clang version 5.0.0 (trunk 293911) (llvm/trunk 293920)"} +!6 = !{i32 2, !"Dwarf Version", i32 4} +!7 = !{i32 2, !"Debug Info Version", i32 3} +!8 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 2, type: !9, isLocal: false, isDefinition: true, scopeLine: 2, isOptimized: false, unit: !0, variables: !2) +!9 = !DISubroutineType(types: !2) +!10 = !DILocation(line: 3, column: 1, scope: !11, inlinedAt: !12) +!11 = distinct !DISubprogram(name: "foo", scope: !4, file: !4, line: 2, type: !9, isLocal: false, isDefinition: true, scopeLine: 2, isOptimized: false, unit: !3, variables: !2) +!12 = distinct !DILocation(line: 2, column: 14, scope: !8) +!13 = !DILocation(line: 2, column: 21, scope: !8)