diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp --- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp @@ -537,7 +537,7 @@ } DIE *DwarfUnit::getOrCreateContextDIE(const DIScope *Context) { - if (!Context || isa(Context)) + if (!Context || isa(Context) || isa(Context)) return &getUnitDie(); if (auto *T = dyn_cast(Context)) return getOrCreateTypeDIE(T); diff --git a/llvm/test/DebugInfo/X86/dwarfdump-ContextDICompileUnit.ll b/llvm/test/DebugInfo/X86/dwarfdump-ContextDICompileUnit.ll new file mode 100644 --- /dev/null +++ b/llvm/test/DebugInfo/X86/dwarfdump-ContextDICompileUnit.ll @@ -0,0 +1,57 @@ +; REQUIRES: x86_64-linux + +; RUN: llc %s -filetype=obj -o - | llvm-dwarfdump - | FileCheck %s + +; CHECK: DW_TAG_compile_unit +; CHECK: DW_AT_name ("mod1.f90") +; CHECK: DW_TAG_module +; CHECK: DW_AT_name ("mdl1") +; CHECK: DW_TAG_subprogram +; CHECK: DW_AT_name ("sub1") +; CHECK: DW_TAG_module +; CHECK: DW_AT_name ("mdl2") +; CHECK: DW_AT_declaration (true) + +; CHECK: DW_TAG_compile_unit +; CHECK: DW_AT_name ("mod2.f90") +; CHECK: DW_TAG_module +; CHECK: DW_AT_name ("mdl2") +; CHECK: DW_TAG_subprogram +; CHECK: DW_AT_name ("sub2") + +; ModuleID = 'dwarfdump_ContextDICompileUnit.f90' +source_filename = "dwarfdump_ContextDICompileUnit.f90" + +define void @mdl1_sub1_(i64* noalias %rx) local_unnamed_addr !dbg !9 { +L.entry: + tail call void @mdl2_sub2_(i64* %rx), !dbg !14 + ret void, !dbg !15 +} + +define void @mdl2_sub2_(i64* noalias nocapture readnone %rx) local_unnamed_addr !dbg !16 { +L.entry: + ret void, !dbg !19 +} + +!llvm.dbg.cu = !{!0, !3} +!llvm.module.flags = !{!5, !6, !7} + +!0 = distinct !DICompileUnit(language: DW_LANG_Fortran90, file: !1, producer: " F90 Flang - 1.5 2017-05-01", isOptimized: true, flags: "'+flang -c -O3 -flto -emit-llvm mod1.f90'", runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2, globals: !2, imports: !2, nameTableKind: None) +!1 = !DIFile(filename: "mod1.f90", directory: "/tmp") +!2 = !{} +!3 = distinct !DICompileUnit(language: DW_LANG_Fortran90, file: !4, producer: " F90 Flang - 1.5 2017-05-01", isOptimized: true, flags: "'+flang -c -O3 -flto -emit-llvm mod2.f90'", runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2, globals: !2, imports: !2, nameTableKind: None) +!4 = !DIFile(filename: "mod2.f90", directory: "/tmp") +!5 = !{i32 2, !"Dwarf Version", i32 4} +!6 = !{i32 2, !"Debug Info Version", i32 3} +!7 = !{i32 1, !"ThinLTO", i32 0} +!9 = distinct !DISubprogram(name: "sub1", scope: !10, file: !1, line: 4, type: !11, scopeLine: 4, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0) +!10 = !DIModule(scope: !0, name: "mdl1", isDecl: true) +!11 = !DISubroutineType(types: !12) +!12 = !{null, !13} +!13 = !DIBasicType(name: "real", size: 32, align: 32, encoding: DW_ATE_float) +!14 = !DILocation(line: 7, column: 1, scope: !9) +!15 = !DILocation(line: 8, column: 1, scope: !9) +!16 = distinct !DISubprogram(name: "sub2", scope: !17, file: !4, line: 4, type: !11, scopeLine: 4, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !3) +!17 = !DIModule(scope: !3, name: "mdl2", isDecl: true) +!18 = !DILocation(line: 6, column: 1, scope: !16) +!19 = !DILocation(line: 7, column: 1, scope: !16)