1; RUN: llc < %s -filetype=obj | llvm-dwarfdump -v - --debug-info | FileCheck %s 2; 3; IR module created as follows: 4; clang -emit-llvm -S -O2 foo.cpp -o foo.ll -g 5; clang -emit-llvm -S -O2 bar.cpp -o bar.ll -gmlt 6; llvm-link foo.ll bar.ll -S -o linked.ll 7; opt -std-link-opts linked.ll -S -o opt.ll 8; --- foo.cpp --- 9; void f(); 10; void foo(int param) { 11; if (param) f(); 12; } 13; --- bar.cpp --- 14; void foo(int); 15; void bar() { 16; foo(0); 17; } 18; --- 19; The point is that bar() is compiled -gmlt and calls foo() with a constant 0. 20; foo() is compiled -g and gets inlined into bar(); foo's body is then 21; optimized away, leaving only a dbg.value call describing the inlined copy 22; of 'param', which should be benign. 23; That is, the compile-unit for bar.cpp should have nothing in it. 24; PR31437. 25 26; foo.cpp's unit comes first; skip past it, second unit should be empty. 27; CHECK: DW_TAG_compile_unit 28; CHECK-NOT: {{DW_TAG|NULL}} 29; CHECK: DW_AT_name {{.*}} "foo.cpp" 30; CHECK: DW_TAG_compile_unit 31; CHECK-NOT: DW_TAG 32 33; ModuleID = 'linked.ll' 34source_filename = "llvm-link" 35target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" 36target triple = "x86_64-unknown-linux-gnu" 37 38; Function Attrs: uwtable 39define void @_Z3fooi(i32 %param) local_unnamed_addr #0 !dbg !8 { 40entry: 41 tail call void @llvm.dbg.value(metadata i32 %param, metadata !13, metadata !14), !dbg !15 42 %tobool = icmp eq i32 %param, 0, !dbg !16 43 br i1 %tobool, label %if.end, label %if.then, !dbg !18 44 45if.then: ; preds = %entry 46 tail call void @_Z1fv(), !dbg !19 47 br label %if.end, !dbg !19 48 49if.end: ; preds = %if.then, %entry 50 ret void, !dbg !21 51} 52 53; Function Attrs: nounwind readnone 54declare void @llvm.dbg.value(metadata, metadata, metadata) #1 55 56declare void @_Z1fv() local_unnamed_addr #2 57 58; Function Attrs: nounwind readnone uwtable 59define void @_Z3barv() local_unnamed_addr #3 !dbg !22 { 60entry: 61 tail call void @llvm.dbg.value(metadata i32 0, metadata !13, metadata !14), !dbg !24 62 ret void, !dbg !26 63} 64 65attributes #0 = { uwtable } 66attributes #1 = { nounwind readnone } 67attributes #2 = { nounwind } 68attributes #3 = { nounwind readnone uwtable } 69 70!llvm.dbg.cu = !{!0, !3} 71!llvm.ident = !{!5, !5} 72!llvm.module.flags = !{!6, !7} 73 74!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 5.0.0 (trunk 293745)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2) 75!1 = !DIFile(filename: "foo.cpp", directory: "/home/probinson/projects/scratch/pr31437") 76!2 = !{} 77!3 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !4, producer: "clang version 5.0.0 (trunk 293745)", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !2) 78!4 = !DIFile(filename: "bar.cpp", directory: "/home/probinson/projects/scratch/pr31437") 79!5 = !{!"clang version 5.0.0 (trunk 293745)"} 80!6 = !{i32 2, !"Dwarf Version", i32 4} 81!7 = !{i32 2, !"Debug Info Version", i32 3} 82!8 = distinct !DISubprogram(name: "foo", linkageName: "_Z3fooi", scope: !1, file: !1, line: 2, type: !9, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !12) 83!9 = !DISubroutineType(types: !10) 84!10 = !{null, !11} 85!11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 86!12 = !{!13} 87!13 = !DILocalVariable(name: "param", arg: 1, scope: !8, file: !1, line: 2, type: !11) 88!14 = !DIExpression() 89!15 = !DILocation(line: 2, column: 14, scope: !8) 90!16 = !DILocation(line: 3, column: 7, scope: !17) 91!17 = distinct !DILexicalBlock(scope: !8, file: !1, line: 3, column: 7) 92!18 = !DILocation(line: 3, column: 7, scope: !8) 93!19 = !DILocation(line: 3, column: 14, scope: !20) 94!20 = !DILexicalBlockFile(scope: !17, file: !1, discriminator: 1) 95!21 = !DILocation(line: 4, column: 1, scope: !8) 96!22 = distinct !DISubprogram(name: "bar", scope: !4, file: !4, line: 2, type: !23, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: true, unit: !3, retainedNodes: !2) 97!23 = !DISubroutineType(types: !2) 98!24 = !DILocation(line: 2, column: 14, scope: !8, inlinedAt: !25) 99!25 = distinct !DILocation(line: 3, column: 3, scope: !22) 100!26 = !DILocation(line: 4, column: 1, scope: !22) 101