1; RUN: %llc_dwarf %s -o - -filetype=obj | llvm-dwarfdump - | FileCheck %s -implicit-check-not=DW_TAG 2; 3; This tests that we do not create concrete variable DIEs for variables that 4; have no location -- for both ways that LLVM-IR can express a variable with 5; no location. It's possible to: 6; 1) Omit all dbg.values and place the variable in the subprograms retained 7; nodes list, 8; 2) Have a dbg.value with an undef operand, and none with "real" operands. 9; Both of these should produce the same DWARF. In the two functions below 10; (qux and croix) I've modified the IR to represent both scenarios. 11; 12; Original C, LLVM-IR modified afterwards: 13; 14; int foo(int bar) { 15; int baz = 12 + bar; 16; return baz; 17; } 18; 19; int qux(int quux) { 20; int xyzzy = foo(quux); 21; return xyzzy; 22; } 23; 24; int croix(int quux) { 25; int xyzzy = foo(quux); 26; return xyzzy; 27; } 28; 29;; Note the implicit DW_TAG check-not in the FileCheck command line. 30; CHECK: DW_TAG_compile_unit 31;; 32;; First subprogram is attached to the plain "foo" function in the output 33;; object. It should have locations for the two variables in the function, 34;; let's be non-specific as to how. 35; CHECK: DW_TAG_subprogram 36; CHECK: DW_AT_abstract_origin (0x{{[0-9a-f]*}} "foo") 37; CHECK: DW_TAG_formal_parameter 38; CHECK: DW_AT_location 39; CHECK: DW_TAG_variable 40; CHECK: DW_AT_location 41; 42;; Abstract subprogram; should have plain variable declarations 43; CHECK: DW_TAG_subprogram 44; CHECK: DW_AT_name ("foo") 45; CHECK: DW_TAG_formal_parameter 46; CHECK: DW_AT_name ("bar") 47; CHECK: DW_TAG_variable 48; CHECK: DW_AT_name ("baz") 49; 50; CHECK: DW_TAG_base_type 51; 52;; The copy of "foo" inlined into "qux" should have no children. 53; CHECK: DW_TAG_subprogram 54; CHECK: DW_AT_name ("qux") 55; CHECK: DW_TAG_formal_parameter 56; CHECK: DW_TAG_variable 57; CHECK: DW_TAG_inlined_subroutine 58; CHECK: NULL 59; 60;; Same for the copy of foo inlined into "croix" 61; CHECK: DW_TAG_subprogram 62; CHECK: DW_AT_name ("croix") 63; CHECK: DW_TAG_formal_parameter 64; CHECK: DW_TAG_variable 65; CHECK: DW_TAG_inlined_subroutine 66; CHECK: NULL 67 68; Function Attrs: norecurse nounwind readnone uwtable willreturn 69define dso_local i32 @foo(i32 %bar) local_unnamed_addr !dbg !7 { 70entry: 71 call void @llvm.dbg.value(metadata i32 %bar, metadata !12, metadata !DIExpression()), !dbg !14 72 %add = add nsw i32 %bar, 12, !dbg !15 73 call void @llvm.dbg.value(metadata i32 %add, metadata !13, metadata !DIExpression()), !dbg !14 74 ret i32 %add, !dbg !16 75} 76 77; Function Attrs: norecurse nounwind readnone uwtable willreturn 78define dso_local i32 @qux(i32 %quux) local_unnamed_addr !dbg !17 { 79entry: 80 %add.i = add nsw i32 %quux, 12, !dbg !24 81 ret i32 %add.i, !dbg !25 82} 83 84; Function Attrs: norecurse nounwind readnone uwtable willreturn 85define dso_local i32 @croix(i32 %quux) local_unnamed_addr !dbg !26 { 86entry: 87 call void @llvm.dbg.value(metadata i32 undef, metadata !28, metadata !DIExpression()), !dbg !30 88 call void @llvm.dbg.value(metadata i32 undef, metadata !12, metadata !DIExpression()), !dbg !31 89 %add.i = add nsw i32 %quux, 12, !dbg !33 90 call void @llvm.dbg.value(metadata i32 undef, metadata !13, metadata !DIExpression()), !dbg !31 91 call void @llvm.dbg.value(metadata i32 undef, metadata !29, metadata !DIExpression()), !dbg !30 92 ret i32 %add.i, !dbg !34 93} 94 95; Function Attrs: nofree nosync nounwind readnone speculatable willreturn 96declare void @llvm.dbg.value(metadata, metadata, metadata) 97 98!llvm.dbg.cu = !{!0} 99!llvm.module.flags = !{!3, !4, !5} 100!llvm.ident = !{!6} 101 102!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None) 103!1 = !DIFile(filename: "test.c", directory: ".") 104!2 = !{} 105!3 = !{i32 7, !"Dwarf Version", i32 4} 106!4 = !{i32 2, !"Debug Info Version", i32 3} 107!5 = !{i32 1, !"wchar_size", i32 4} 108!6 = !{!"clang"} 109!7 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !8, scopeLine: 1, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !11) 110!8 = !DISubroutineType(types: !9) 111!9 = !{!10, !10} 112!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 113!11 = !{!12, !13} 114!12 = !DILocalVariable(name: "bar", arg: 1, scope: !7, file: !1, line: 1, type: !10) 115!13 = !DILocalVariable(name: "baz", scope: !7, file: !1, line: 2, type: !10) 116!14 = !DILocation(line: 0, scope: !7) 117!15 = !DILocation(line: 2, column: 16, scope: !7) 118!16 = !DILocation(line: 3, column: 3, scope: !7) 119!17 = distinct !DISubprogram(name: "qux", scope: !1, file: !1, line: 6, type: !8, scopeLine: 6, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !18) 120!18 = !{!19, !20} 121!19 = !DILocalVariable(name: "quux", arg: 1, scope: !17, file: !1, line: 6, type: !10) 122!20 = !DILocalVariable(name: "xyzzy", scope: !17, file: !1, line: 7, type: !10) 123!21 = !DILocation(line: 0, scope: !17) 124!22 = !DILocation(line: 0, scope: !7, inlinedAt: !23) 125!23 = distinct !DILocation(line: 7, column: 15, scope: !17) 126!24 = !DILocation(line: 2, column: 16, scope: !7, inlinedAt: !23) 127!25 = !DILocation(line: 8, column: 3, scope: !17) 128!26 = distinct !DISubprogram(name: "croix", scope: !1, file: !1, line: 11, type: !8, scopeLine: 11, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !27) 129!27 = !{!28, !29} 130!28 = !DILocalVariable(name: "quux", arg: 1, scope: !26, file: !1, line: 11, type: !10) 131!29 = !DILocalVariable(name: "xyzzy", scope: !26, file: !1, line: 12, type: !10) 132!30 = !DILocation(line: 0, scope: !26) 133!31 = !DILocation(line: 0, scope: !7, inlinedAt: !32) 134!32 = distinct !DILocation(line: 12, column: 15, scope: !26) 135!33 = !DILocation(line: 2, column: 16, scope: !7, inlinedAt: !32) 136!34 = !DILocation(line: 13, column: 3, scope: !26) 137