diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -567,6 +567,11 @@ auto *SP = cast(Scope->getScopeNode()); + // Handling a case with LTO where function is inlined from CU which doesn't + // have SplitDebugInlining enabled into one that does. + if (SrcCU.getCUNode()->getSplitDebugInlining()) + SP->getUnit()->setSplitDebugInlining(true); + // Find the subprogram's DwarfCompileUnit in the SPMap in case the subprogram // was inlined from another compile unit. if (useSplitDwarf() && !shareAcrossDWOCUs() && !SP->getUnit()->getSplitDebugInlining()) diff --git a/llvm/test/DebugInfo/Inputs/mixDebugInliingHelper.ll b/llvm/test/DebugInfo/Inputs/mixDebugInliingHelper.ll new file mode 100644 --- /dev/null +++ b/llvm/test/DebugInfo/Inputs/mixDebugInliingHelper.ll @@ -0,0 +1,47 @@ +; -g2 -gsplit-dwarf=split -fdebug-info-for-profiling -flto=thin -c +; int __attribute__((always_inline)) func(int x) { +; return x * 2; +; } + +; ModuleID = 'helper.cpp' +source_filename = "helper.cpp" +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +; Function Attrs: alwaysinline nounwind uwtable mustprogress +define dso_local i32 @_Z4funci(i32 %x) #0 !dbg !7 { +entry: + %x.addr = alloca i32, align 4 + store i32 %x, i32* %x.addr, align 4 + call void @llvm.dbg.declare(metadata i32* %x.addr, metadata !11, metadata !DIExpression()), !dbg !12 + %0 = load i32, i32* %x.addr, align 4, !dbg !13 + %mul = mul nsw i32 %0, 2, !dbg !14 + ret i32 %mul, !dbg !15 +} + +; Function Attrs: nofree nosync nounwind readnone speculatable willreturn +declare void @llvm.dbg.declare(metadata, metadata, metadata) #1 + +attributes #0 = { alwaysinline nounwind uwtable mustprogress "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { nofree nosync nounwind readnone speculatable willreturn } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4, !5} +!llvm.ident = !{!6} + +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 12.0.1", isOptimized: true, runtimeVersion: 0, splitDebugFilename: "helper.dwo", emissionKind: FullDebug, enums: !2, splitDebugInlining: false, debugInfoForProfiling: true, nameTableKind: GNU) +!1 = !DIFile(filename: "helper.cpp", directory: "bug2") +!2 = !{} +!3 = !{i32 7, !"Dwarf Version", i32 4} +!4 = !{i32 2, !"Debug Info Version", i32 3} +!5 = !{i32 1, !"wchar_size", i32 4} +!6 = !{!"clang version 12.0.1"} +!7 = distinct !DISubprogram(name: "func", linkageName: "_Z4funci", scope: !1, file: !1, line: 1, type: !8, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2) +!8 = !DISubroutineType(types: !9) +!9 = !{!10, !10} +!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!11 = !DILocalVariable(name: "x", arg: 1, scope: !7, file: !1, line: 1, type: !10) +!12 = !DILocation(line: 1, column: 45, scope: !7) +!13 = !DILocation(line: 2, column: 11, scope: !7) +!14 = !DILocation(line: 2, column: 13, scope: !7) +!15 = !DILocation(line: 2, column: 4, scope: !7) diff --git a/llvm/test/DebugInfo/Inputs/mixDebugInliingMain.ll b/llvm/test/DebugInfo/Inputs/mixDebugInliingMain.ll new file mode 100644 --- /dev/null +++ b/llvm/test/DebugInfo/Inputs/mixDebugInliingMain.ll @@ -0,0 +1,61 @@ +; -g2 -gsplit-dwarf=split -fsplit-dwarf-inlining -fdebug-info-for-profiling -flto=thin +; int func(int); +; int main(int argc, char *argv[]) { +; return func(argc);; +; } + +; ModuleID = 'main.cpp' +source_filename = "main.cpp" +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +; Function Attrs: noinline norecurse optnone uwtable mustprogress +define dso_local i32 @main(i32 %argc, i8** %argv) #0 !dbg !7 { +entry: + %retval = alloca i32, align 4 + %argc.addr = alloca i32, align 4 + %argv.addr = alloca i8**, align 8 + store i32 0, i32* %retval, align 4 + store i32 %argc, i32* %argc.addr, align 4 + call void @llvm.dbg.declare(metadata i32* %argc.addr, metadata !14, metadata !DIExpression()), !dbg !15 + store i8** %argv, i8*** %argv.addr, align 8 + call void @llvm.dbg.declare(metadata i8*** %argv.addr, metadata !16, metadata !DIExpression()), !dbg !17 + %0 = load i32, i32* %argc.addr, align 4, !dbg !18 + %call = call i32 @_Z4funci(i32 %0), !dbg !19 + ret i32 %call, !dbg !20 +} + +; Function Attrs: nofree nosync nounwind readnone speculatable willreturn +declare void @llvm.dbg.declare(metadata, metadata, metadata) #1 + +declare dso_local i32 @_Z4funci(i32) #2 + +attributes #0 = { noinline norecurse optnone uwtable mustprogress "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { nofree nosync nounwind readnone speculatable willreturn } +attributes #2 = { "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" "unsafe-fp-math"="false" "use-soft-float"="false" } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4, !5} +!llvm.ident = !{!6} + +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 12.0.1", isOptimized: true, runtimeVersion: 0, splitDebugFilename: "main.dwo", emissionKind: FullDebug, enums: !2, debugInfoForProfiling: true, nameTableKind: GNU) +!1 = !DIFile(filename: "main.cpp", directory: "bug2") +!2 = !{} +!3 = !{i32 7, !"Dwarf Version", i32 4} +!4 = !{i32 2, !"Debug Info Version", i32 3} +!5 = !{i32 1, !"wchar_size", i32 4} +!6 = !{!"clang version 12.0.1"} +!7 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 2, type: !8, scopeLine: 2, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2) +!8 = !DISubroutineType(types: !9) +!9 = !{!10, !10, !11} +!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!11 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64) +!12 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 64) +!13 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char) +!14 = !DILocalVariable(name: "argc", arg: 1, scope: !7, file: !1, line: 2, type: !10) +!15 = !DILocation(line: 2, column: 14, scope: !7) +!16 = !DILocalVariable(name: "argv", arg: 2, scope: !7, file: !1, line: 2, type: !11) +!17 = !DILocation(line: 2, column: 26, scope: !7) +!18 = !DILocation(line: 3, column: 15, scope: !7) +!19 = !DILocation(line: 3, column: 10, scope: !7) +!20 = !DILocation(line: 3, column: 3, scope: !7) diff --git a/llvm/test/DebugInfo/X86/mixDebugInliing.test b/llvm/test/DebugInfo/X86/mixDebugInliing.test new file mode 100644 --- /dev/null +++ b/llvm/test/DebugInfo/X86/mixDebugInliing.test @@ -0,0 +1,29 @@ +; RUN: llvm-as %p/../Inputs/mixDebugInliingMain.ll -o %tMain.o +; RUN: llvm-as %p/../Inputs/mixDebugInliingHelper.ll -o %tHelper.o +; RUN: clang++ -fuse-ld=lld -flto=thin -Wl,--plugin-opt=dwo_dir="." %tMain.o %tHelper.o -o %t.exe +; RUN: llvm-dwarfdump --debug-info --show-form --verbose %t.exe | FileCheck -check-prefix=CHECK %s + +; CHECK: DW_TAG_compile_unit +; CHECK-NEXT: DW_AT_stmt_list +; CHECK-NEXT: DW_AT_comp_dir +; CHECK-NEXT: DW_AT_GNU_pubnames +; CHECK-NEXT: DW_AT_GNU_dwo_name +; CHECK-NEXT: DW_AT_GNU_dwo_id +; CHECK-NEXT: DW_AT_low_pc +; CHECK-NEXT: DW_AT_high_pc +; CHECK-NEXT: DW_AT_GNU_addr_base +; CHECK-EMPTY: +; CHECK-NEXT: DW_TAG_subprogram +; CHECK-NEXT: DW_AT_low_pc +; CHECK-NEXT: DW_AT_high_pc +; CHECK-NEXT: DW_AT_name +; CHECK-NEXT: DW_AT_decl_file +; CHECK-NEXT: DW_AT_decl_line +; CHECK-EMPTY: +; CHECK-NEXT: DW_TAG_inlined_subroutine +; CHECK-NEXT: DW_AT_abstract_origin +; CHECK-NEXT: DW_AT_low_pc +; CHECK-NEXT: DW_AT_high_pc +; CHECK-NEXT: DW_AT_call_file +; CHECK-NEXT: DW_AT_call_line +; CHECK-NEXT: DW_AT_call_column