Index: llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp =================================================================== --- llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp +++ llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp @@ -188,8 +188,9 @@ /// Check whether the DIE for this MDNode can be shared across CUs. bool DwarfUnit::isShareableAcrossCUs(const DINode *D) const { - // When the MDNode can be part of the type system, the DIE can be shared - // across CUs. + // When the MDNode can be part of the type system (this includes subprogram + // declarations *and* subprogram definitions, even local definitions), the + // DIE must be shared across CUs. // Combining type units and cross-CU DIE sharing is lower value (since // cross-CU DIE sharing is used in LTO and removes type redundancy at that // level already) but may be implementable for some value in projects @@ -197,9 +198,7 @@ // together. if (isDwoUnit() && !DD->shareAcrossDWOCUs()) return false; - return (isa(D) || - (isa(D) && !cast(D)->isDefinition())) && - !DD->generateTypeUnits(); + return (isa(D) || isa(D)) && !DD->generateTypeUnits(); } DIE *DwarfUnit::getDIE(const DINode *D) const { Index: llvm/test/DebugInfo/X86/lto-cross-cu-call-origin-ref.ll =================================================================== --- /dev/null +++ llvm/test/DebugInfo/X86/lto-cross-cu-call-origin-ref.ll @@ -0,0 +1,145 @@ +; RUN: llc -mtriple=x86_64-apple-darwin -filetype=obj < %s | llvm-dwarfdump - \ +; RUN: | FileCheck %s -implicit-check-not=DW_TAG_subprogram + +; Source: +; // a.c +; __attribute__((optnone)) void bar() {} +; __attribute__((optnone)) static void baz() {} +; __attribute__((always_inline)) void foo() { +; bar(); +; baz(); +; } +; // b.c +; extern void foo(); +; __attribute__((optnone)) void baz() {} +; int main() { +; foo(); +; baz(); +; return 0; +; } + +; Command: +; clang -O2 -Xclang -femit-debug-entry-values -g -flto -o a.o -c a.c +; clang -O2 -Xclang -femit-debug-entry-values -g -flto -o b.o -c b.c +; clang -O2 -Xclang -femit-debug-entry-values -g -flto -o main a.o b.o -Wl,-object_path_lto,lto.o,-save-temps + +; === CU for b.c === + +; CHECK: DW_TAG_compile_unit +; CHECK: DW_AT_name ("b.c") + +; "foo" should still be present in "b.c" as a declaration. +; CHECK: DW_TAG_subprogram +; CHECK: DW_AT_name ("foo") +; CHECK: DW_AT_declaration (true) + +; Check for an external definition subprogram for "baz". +; CHECK: 0x{{0+}}[[BAZ_IN_B_DIE:.*]]: DW_TAG_subprogram +; CHECK: DW_AT_call_all_calls (true) +; CHECK: DW_AT_name ("baz") +; CHECK: DW_AT_external (true) + +; Check that "main" references, in order: +; +; 1) The definition of "bar" in "a.c". (Previously we would not share +; definition subprograms across CUs, so the call site info logic would create an +; empty 'definition' subprogram for "bar" which never got filled in. This breaks +; both entry value evaluation & artificial tail call frame synthesis in the LTO +; setting.) +; +; 2) The non-external definition of "baz" in "a.c". This is inlined via "foo". +; +; 3) The external definition of "baz" in "b.c". +; CHECK: DW_TAG_subprogram +; CHECK: DW_AT_name ("main") +; CHECK: DW_TAG_call_site +; CHECK-NEXT: DW_AT_call_origin (0x{{0+}}[[BAR_IN_A_DIE:.*]]) +; CHECK: DW_TAG_call_site +; CHECK-NEXT: DW_AT_call_origin (0x{{0+}}[[BAZ_IN_A_DIE:.*]]) +; CHECK: DW_TAG_call_site +; CHECK-NEXT: DW_AT_call_origin (0x{{0+}}[[BAZ_IN_B_DIE]]) + +; === CU for a.c === + +; CHECK: DW_TAG_compile_unit +; CHECK: DW_AT_name ("a.c") + +; Check for the definitions expected in a.c. +; CHECK: 0x{{.*}}[[BAR_IN_A_DIE]]: DW_TAG_subprogram +; CHECK: DW_AT_call_all_calls (true) +; CHECK: DW_AT_name ("bar") + +; CHECK: 0x{{.*}}[[BAZ_IN_A_DIE]]: DW_TAG_subprogram +; CHECK: DW_AT_call_all_calls (true) +; CHECK: DW_AT_name ("baz") + +; Match & ignore. +; CHECK: DW_TAG_subprogram +; CHECK: DW_AT_name ("foo") +; CHECK: DW_AT_inline (DW_INL_inlined) + +target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-apple-macosx10.14.0" + +define internal fastcc void @bar() unnamed_addr #0 !dbg !15 { +entry: + ret void, !dbg !18 +} + +define internal fastcc void @baz.2() unnamed_addr #0 !dbg !19 { +entry: + ret void, !dbg !20 +} + +define internal fastcc void @baz() unnamed_addr #0 !dbg !21 { +entry: + ret void, !dbg !22 +} + +define i32 @main() local_unnamed_addr !dbg !23 { +entry: + tail call fastcc void @bar(), !dbg !27 + tail call fastcc void @baz.2(), !dbg !30 + tail call fastcc void @baz(), !dbg !31 + ret i32 0, !dbg !32 +} + +attributes #0 = { noinline optnone } + +!llvm.dbg.cu = !{!0, !3} +!llvm.ident = !{!9, !9} +!llvm.module.flags = !{!10, !11, !12, !13, !14} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 10.0.0 (git@github.com:llvm/llvm-project.git 3ad8c5db6b232383f4b0553505f585ad7fd194a4)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None) +!1 = !DIFile(filename: "a.c", directory: "/Users/vsk/tmp/lto-entry-vals") +!2 = !{} +!3 = distinct !DICompileUnit(language: DW_LANG_C99, file: !4, producer: "clang version 10.0.0 (git@github.com:llvm/llvm-project.git 3ad8c5db6b232383f4b0553505f585ad7fd194a4)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !5, nameTableKind: None) +!4 = !DIFile(filename: "b.c", directory: "/Users/vsk/tmp/lto-entry-vals") +!5 = !{!6} +!6 = !DISubprogram(name: "foo", scope: !4, file: !4, line: 1, type: !7, spFlags: DISPFlagOptimized, retainedNodes: !2) +!7 = !DISubroutineType(types: !8) +!8 = !{null, null} +!9 = !{!"clang version 10.0.0 (git@github.com:llvm/llvm-project.git 3ad8c5db6b232383f4b0553505f585ad7fd194a4)"} +!10 = !{i32 2, !"Dwarf Version", i32 4} +!11 = !{i32 2, !"Debug Info Version", i32 3} +!12 = !{i32 1, !"wchar_size", i32 4} +!13 = !{i32 7, !"PIC Level", i32 2} +!14 = !{i32 1, !"LTOPostLink", i32 1} +!15 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 1, type: !16, scopeLine: 1, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2) +!16 = !DISubroutineType(types: !17) +!17 = !{null} +!18 = !DILocation(line: 1, column: 38, scope: !15) +!19 = distinct !DISubprogram(name: "baz", scope: !1, file: !1, line: 2, type: !16, scopeLine: 2, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2) +!20 = !DILocation(line: 2, column: 45, scope: !19) +!21 = distinct !DISubprogram(name: "baz", scope: !4, file: !4, line: 2, type: !16, scopeLine: 2, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !3, retainedNodes: !2) +!22 = !DILocation(line: 2, column: 38, scope: !21) +!23 = distinct !DISubprogram(name: "main", scope: !4, file: !4, line: 3, type: !24, scopeLine: 3, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !3, retainedNodes: !2) +!24 = !DISubroutineType(types: !25) +!25 = !{!26} +!26 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!27 = !DILocation(line: 4, column: 3, scope: !28, inlinedAt: !29) +!28 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 3, type: !16, scopeLine: 3, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2) +!29 = distinct !DILocation(line: 4, column: 3, scope: !23) +!30 = !DILocation(line: 5, column: 3, scope: !28, inlinedAt: !29) +!31 = !DILocation(line: 5, column: 3, scope: !23) +!32 = !DILocation(line: 6, column: 3, scope: !23)