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,108 @@ +; RUN: llc -mtriple=x86_64-apple-darwin -filetype=obj < %s | llvm-dwarfdump - \ +; RUN: | FileCheck %s + +; Source: + +;; // a.c +;; volatile int sink; +;; +;; __attribute__((noinline)) void bar() { ++sink; } +;; +;; 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" + +@sink = internal global i32 0, align 4, !dbg !0 + +define internal fastcc void @bar() unnamed_addr !dbg !20 { +entry: + %0 = load volatile i32, i32* @sink, align 4, !dbg !23, !tbaa !24 + %inc = add nsw i32 %0, 1, !dbg !23 + store volatile i32 %inc, i32* @sink, align 4, !dbg !23, !tbaa !24 + ret void, !dbg !28 +} + +define i32 @main() local_unnamed_addr !dbg !29 { +entry: + tail call fastcc void @bar(), !dbg !32 + ret i32 0, !dbg !35 +} + +!llvm.dbg.cu = !{!2, !8} +!llvm.ident = !{!14, !14} +!llvm.module.flags = !{!15, !16, !17, !18, !19} + +!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) +!1 = distinct !DIGlobalVariable(name: "sink", scope: !2, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true) +!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 10.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, nameTableKind: None) +!3 = !DIFile(filename: "a.c", directory: "/Users/vsk/tmp/lto-entry-vals") +!4 = !{} +!5 = !{!0} +!6 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !7) +!7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!8 = distinct !DICompileUnit(language: DW_LANG_C99, file: !9, producer: "clang version 10.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, retainedTypes: !10, nameTableKind: None) +!9 = !DIFile(filename: "b.c", directory: "/Users/vsk/tmp/lto-entry-vals") +!10 = !{!11} +!11 = !DISubprogram(name: "foo", scope: !9, file: !9, line: 1, type: !12, spFlags: DISPFlagOptimized, retainedNodes: !4) +!12 = !DISubroutineType(types: !13) +!13 = !{null, null} +!14 = !{!"clang version 10.0.0"} +!15 = !{i32 2, !"Dwarf Version", i32 4} +!16 = !{i32 2, !"Debug Info Version", i32 3} +!17 = !{i32 1, !"wchar_size", i32 4} +!18 = !{i32 7, !"PIC Level", i32 2} +!19 = !{i32 1, !"LTOPostLink", i32 1} +!20 = distinct !DISubprogram(name: "bar", scope: !3, file: !3, line: 3, type: !21, scopeLine: 3, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !4) +!21 = !DISubroutineType(types: !22) +!22 = !{null} +!23 = !DILocation(line: 3, column: 40, scope: !20) +!24 = !{!25, !25, i64 0} +!25 = !{!"int", !26, i64 0} +!26 = !{!"omnipotent char", !27, i64 0} +!27 = !{!"Simple C/C++ TBAA"} +!28 = !DILocation(line: 3, column: 48, scope: !20) +!29 = distinct !DISubprogram(name: "main", scope: !9, file: !9, line: 3, type: !30, scopeLine: 3, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !8, retainedNodes: !4) +!30 = !DISubroutineType(types: !31) +!31 = !{!7} +!32 = !DILocation(line: 6, column: 3, scope: !33, inlinedAt: !34) +!33 = distinct !DISubprogram(name: "foo", scope: !3, file: !3, line: 5, type: !21, scopeLine: 5, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !4) +!34 = distinct !DILocation(line: 4, column: 3, scope: !29) +!35 = !DILocation(line: 5, column: 3, scope: !29)