Index: llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp =================================================================== --- llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp +++ llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp @@ -197,9 +197,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,84 @@ +; RUN: llc -mtriple=x86_64-apple-darwin -filetype=obj < %s | llvm-dwarfdump - \ +; RUN: | FileCheck %s + +; Source: + +;; // a.c +;; __attribute__((optnone)) void bar() {} +;; __attribute__((always_inline)) void foo() { bar(); } + +;; // b.c +;; extern void foo(); +;; int main() { +;; foo(); +;; 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 + +; CHECK: DW_TAG_compile_unit +; CHECK: DW_AT_name ("a.c") + +; Check for a definition subprogram for "bar". Note that AT_call_all_calls +; implies that this is not a declaration. +; CHECK: 0x[[BAR_DIE:.*]]: DW_TAG_subprogram +; CHECK: DW_AT_call_all_calls (true) +; CHECK: DW_AT_name ("bar") + +; CHECK: DW_TAG_compile_unit +; CHECK: DW_AT_name ("b.c") + +; Check that "main" can reference 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.) +; CHECK: DW_TAG_subprogram +; CHECK: DW_AT_name ("main") +; CHECK: DW_TAG_call_site +; CHECK-NEXT: DW_AT_call_origin (0x{{.*}}[[BAR_DIE]]) + +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 !11 { + ret void, !dbg !14 +} + +define i32 @main() local_unnamed_addr !dbg !15 { + tail call fastcc void @bar(), !dbg !19 + ret i32 0, !dbg !22 +} + +attributes #0 = { noinline optnone } + +!llvm.dbg.cu = !{!0, !3} +!llvm.ident = !{!5, !5} +!llvm.module.flags = !{!6, !7, !8, !9, !10} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: GNU) +!1 = !DIFile(filename: "a.c", directory: "/Users/vsk/tmp/lto-entry-vals") +!2 = !{} +!3 = distinct !DICompileUnit(language: DW_LANG_C99, file: !4, producer: "", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: GNU) +!4 = !DIFile(filename: "b.c", directory: "/Users/vsk/tmp/lto-entry-vals") +!5 = !{!"Apple clang version 11.0.3 (clang-1103.0.22.93)"} +!6 = !{i32 2, !"SDK Version", [2 x i32] [i32 10, i32 14]} +!7 = !{i32 2, !"Dwarf Version", i32 4} +!8 = !{i32 2, !"Debug Info Version", i32 3} +!9 = !{i32 1, !"wchar_size", i32 4} +!10 = !{i32 7, !"PIC Level", i32 2} +!11 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 1, type: !12, scopeLine: 1, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2) +!12 = !DISubroutineType(types: !13) +!13 = !{null} +!14 = !DILocation(line: 1, column: 38, scope: !11) +!15 = distinct !DISubprogram(name: "main", scope: !4, file: !4, line: 2, type: !16, scopeLine: 2, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !3, retainedNodes: !2) +!16 = !DISubroutineType(types: !17) +!17 = !{!18} +!18 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!19 = !DILocation(line: 2, column: 45, scope: !20, inlinedAt: !21) +!20 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 2, type: !12, scopeLine: 2, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2) +!21 = distinct !DILocation(line: 3, column: 3, scope: !15) +!22 = !DILocation(line: 4, column: 3, scope: !15)