1; RUN: llc -O0 %s -o - -filetype=obj \ 2; RUN: | llvm-dwarfdump -statistics - | FileCheck %s 3; CHECK: "version": 6, 4 5; namespace test { 6; extern int a; 7; } 8; using test::a; 9; 10; int GlobalConst = 42; 11; int Global; 12; 13; struct S { 14; static const int constant = 24; 15; int (*fn)(int); 16; } s; 17; 18; int __attribute__((always_inline)) square(int i) { return i * i; } 19; int cube(int i) { 20; int squared = square(i); 21; return squared*i; 22; } 23; 24; int boo(int, int) {} 25 26; struct T { 27; void empty(); 28; }; 29; void T::empty() {} 30 31; Following variables/arguments/members should be counted: 32; - GlobalConst, 33; - Global, 34; - s, s.constant, 35; - square::i, 36; - cube::i, cube::squared 37; - boo::1, boo::2 38; - this in T::empty() 39; Skipped entities: 40; - declaration of test::a, 41; - non-constant member S:fn, 42; - arguments of S:fn. 43 44; CHECK: "#unique source variables": 10, 45; +1 extra inline i. 46; CHECK: "#source variables": 11, 47; -1 square::i 48; CHECK: "#source variables with location": 10, 49; CHECK: "sum_all_local_vars(#bytes in parent scope)": [[BYTES:[0-9]+]] 50; Because of the dbg.value in the middle of the function, the pc range coverage 51; must be below 100%. 52; CHECK-NOT: "sum_all_local_vars(#bytes in parent scope covered by DW_AT_location)": 0, 53; CHECK-NOT: "sum_all_local_vars(#bytes in parent scope covered by DW_AT_location)": [[BYTES]] 54; CHECK: "sum_all_local_vars(#bytes in parent scope covered by DW_AT_location)": 55; CHECK: "#bytes within functions": [[FUNCSIZE:[0-9]+]] 56; CHECK: "#bytes within inlined functions": [[INLINESIZE:[0-9]+]] 57; CHECK: "#bytes in __debug_info": 459, 58; CHECK-NEXT: "#bytes in __debug_loc": 35, 59; CHECK-NEXT: "#bytes in __apple_names": 348, 60; CHECK-NEXT: "#bytes in __apple_types": 133, 61; CHECK-NEXT: "#bytes in __debug_abbrev": 384, 62; CHECK-NEXT: "#bytes in __apple_namespac": 60, 63; CHECK-NEXT: "#bytes in __debug_line": 126, 64; CHECK-NEXT: "#bytes in __debug_str": 231, 65; CHECK-NEXT: "#bytes in __apple_objc": 36, 66 67; ModuleID = '/tmp/quality.cpp' 68source_filename = "/tmp/quality.cpp" 69target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" 70target triple = "x86_64-apple-macosx10.12.0" 71 72%struct.S = type { i8 (i32)* } 73 74@GlobalConst = global i32 42, align 4, !dbg !0 75@Global = global i32 0, align 4, !dbg !6 76@s = global %struct.S zeroinitializer, align 1, !dbg !9 77 78; Function Attrs: alwaysinline nounwind ssp uwtable 79define i32 @_Z6squarei(i32 %i) #0 !dbg !20 { 80entry: 81 %i.addr = alloca i32, align 4 82 store i32 %i, i32* %i.addr, align 4 83 ; Modified to loose debug info for i here. 84 call void @llvm.dbg.declare(metadata i32* undef, metadata !23, metadata !24), !dbg !25 85 %0 = load i32, i32* %i.addr, align 4, !dbg !26 86 %1 = load i32, i32* %i.addr, align 4, !dbg !27 87 %mul = mul nsw i32 %0, %1, !dbg !28 88 ret i32 %mul, !dbg !29 89} 90 91; Function Attrs: nounwind readnone speculatable 92declare void @llvm.dbg.declare(metadata, metadata, metadata) #1 93declare void @llvm.dbg.value(metadata, metadata, metadata) #1 94 95; Function Attrs: noinline nounwind optnone ssp uwtable 96define i32 @_Z4cubei(i32 %i) #2 !dbg !30 { 97entry: 98 %i.addr.i = alloca i32, align 4 99 call void @llvm.dbg.declare(metadata i32* %i.addr.i, metadata !23, metadata !24), !dbg !31 100 %i.addr = alloca i32, align 4 101 %squared = alloca i32, align 4 102 store i32 %i, i32* %i.addr, align 4 103 call void @llvm.dbg.declare(metadata i32* %i.addr, metadata !33, metadata !24), !dbg !34 104 %0 = load i32, i32* %i.addr, align 4, !dbg !37 105 store i32 %0, i32* %i.addr.i, align 4 106 %1 = load i32, i32* %i.addr.i, align 4, !dbg !38 107 %2 = load i32, i32* %i.addr.i, align 4, !dbg !39 108 %mul.i = mul nsw i32 %1, %2, !dbg !40 109 ; Modified to cover only about 50% of the lexical scope. 110 call void @llvm.dbg.value(metadata i32 %mul.i, metadata !35, metadata !24), !dbg !36 111 store i32 %mul.i, i32* %squared, align 4, !dbg !36 112 %3 = load i32, i32* %squared, align 4, !dbg !41 113 call void @llvm.dbg.value(metadata i32 %3, metadata !35, metadata !24), !dbg !36 114 %4 = load i32, i32* %i.addr, align 4, !dbg !42 115 %mul = mul nsw i32 %3, %4, !dbg !43 116 ret i32 %mul, !dbg !44 117} 118 119; Function Attrs: noinline optnone uwtable 120define dso_local i32 @_Z3booii(i32 %0, i32 %1) !dbg !52 { 121entry: 122 %.addr = alloca i32, align 4 123 %.addr1 = alloca i32, align 4 124 store i32 %0, i32* %.addr, align 4 125 call void @llvm.dbg.declare(metadata i32* %.addr, metadata !55, metadata !DIExpression()), !dbg !56 126 store i32 %1, i32* %.addr1, align 4 127 call void @llvm.dbg.declare(metadata i32* %.addr1, metadata !57, metadata !DIExpression()), !dbg !58 128 ret i32 0, !dbg !58 129} 130 131%struct.T = type { i8 } 132 133define void @_ZN1T5emptyEv(%struct.T* %this) #2 !dbg !59 { 134entry: 135 %this.addr = alloca %struct.T*, align 8 136 store %struct.T* %this, %struct.T** %this.addr, align 8 137 call void @llvm.dbg.declare(metadata %struct.T** %this.addr, metadata !67, metadata !DIExpression()), !dbg !69 138 %this1 = load %struct.T*, %struct.T** %this.addr, align 8 139 ret void, !dbg !70 140} 141 142attributes #0 = { alwaysinline nounwind ssp uwtable } 143attributes #1 = { nounwind readnone speculatable } 144attributes #2 = { noinline nounwind optnone ssp uwtable } 145 146!llvm.dbg.cu = !{!2} 147!llvm.module.flags = !{!15, !16, !17, !18} 148!llvm.ident = !{!19} 149 150!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) 151!1 = distinct !DIGlobalVariable(name: "GlobalConst", scope: !2, file: !3, line: 1, type: !8, isLocal: false, isDefinition: true) 152!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 6.0.0 (trunk 310529) (llvm/trunk 310534)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, imports: !48, globals: !5) 153!3 = !DIFile(filename: "/tmp/quality.cpp", directory: "/Volumes/Data/llvm") 154!4 = !{} 155!5 = !{!0, !6, !9} 156!6 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression()) 157!7 = distinct !DIGlobalVariable(name: "Global", scope: !2, file: !3, line: 2, type: !8, isLocal: false, isDefinition: true) 158!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 159!9 = !DIGlobalVariableExpression(var: !10, expr: !DIExpression()) 160!10 = distinct !DIGlobalVariable(name: "s", scope: !2, file: !3, line: 6, type: !11, isLocal: false, isDefinition: true) 161!11 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "S", file: !3, line: 4, size: 8, elements: !12, identifier: "_ZTS1S") 162!12 = !{!13, !45} 163!13 = !DIDerivedType(tag: DW_TAG_member, name: "constant", scope: !11, file: !3, line: 5, baseType: !14, flags: DIFlagStaticMember, extraData: i32 24) 164!14 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !8) 165!15 = !{i32 2, !"Dwarf Version", i32 4} 166!16 = !{i32 2, !"Debug Info Version", i32 3} 167!17 = !{i32 1, !"wchar_size", i32 4} 168!18 = !{i32 7, !"PIC Level", i32 2} 169!19 = !{!"clang version 6.0.0 (trunk 310529) (llvm/trunk 310534)"} 170!20 = distinct !DISubprogram(name: "square", linkageName: "_Z6squarei", scope: !3, file: !3, line: 8, type: !21, isLocal: false, isDefinition: true, scopeLine: 8, flags: DIFlagPrototyped, isOptimized: false, unit: !2, retainedNodes: !4) 171!21 = !DISubroutineType(types: !22) 172!22 = !{!8, !8} 173!23 = !DILocalVariable(name: "i", arg: 1, scope: !20, file: !3, line: 8, type: !8) 174!24 = !DIExpression() 175!25 = !DILocation(line: 8, column: 47, scope: !20) 176!26 = !DILocation(line: 8, column: 59, scope: !20) 177!27 = !DILocation(line: 8, column: 63, scope: !20) 178!28 = !DILocation(line: 8, column: 61, scope: !20) 179!29 = !DILocation(line: 8, column: 52, scope: !20) 180!30 = distinct !DISubprogram(name: "cube", linkageName: "_Z4cubei", scope: !3, file: !3, line: 9, type: !21, isLocal: false, isDefinition: true, scopeLine: 9, flags: DIFlagPrototyped, isOptimized: false, unit: !2, retainedNodes: !4) 181!31 = !DILocation(line: 8, column: 47, scope: !20, inlinedAt: !32) 182!32 = distinct !DILocation(line: 10, column: 17, scope: !30) 183!33 = !DILocalVariable(name: "i", arg: 1, scope: !30, file: !3, line: 9, type: !8) 184!34 = !DILocation(line: 9, column: 14, scope: !30) 185!35 = !DILocalVariable(name: "squared", scope: !30, file: !3, line: 10, type: !8) 186!36 = !DILocation(line: 10, column: 7, scope: !30) 187!37 = !DILocation(line: 10, column: 24, scope: !30) 188!38 = !DILocation(line: 8, column: 59, scope: !20, inlinedAt: !32) 189!39 = !DILocation(line: 8, column: 63, scope: !20, inlinedAt: !32) 190!40 = !DILocation(line: 8, column: 61, scope: !20, inlinedAt: !32) 191!41 = !DILocation(line: 11, column: 10, scope: !30) 192!42 = !DILocation(line: 11, column: 18, scope: !30) 193!43 = !DILocation(line: 11, column: 17, scope: !30) 194!44 = !DILocation(line: 11, column: 3, scope: !30) 195!45 = !DIDerivedType(tag: DW_TAG_member, name: "fn", scope: !11, file: !3, line: 5, baseType: !46, size: 64) 196!46 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !47, size: 64) 197!47 = !DISubroutineType(types: !22) 198!48 = !{!49} 199!49 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !2, entity: !50, file: !3, line: 2) 200!50 = !DIGlobalVariable(name: "a", linkageName: "_ZN4test1aE", scope: !51, file: !3, line: 2, type: !8, isLocal: false, isDefinition: false) 201!51 = !DINamespace(name: "test", scope: !2) 202!52 = distinct !DISubprogram(name: "boo", linkageName: "_Z3booii", scope: !3, file: !3, line: 10, type: !53, scopeLine: 3, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !4) 203!53 = !DISubroutineType(types: !54) 204!54 = !{!8, !8, !8} 205!55 = !DILocalVariable(arg: 1, scope: !52, file: !3, line: 10, type: !8) 206!56 = !DILocation(line: 10, column: 12, scope: !52) 207!57 = !DILocalVariable(arg: 2, scope: !52, file: !3, line: 10, type: !8) 208!58 = !DILocation(line: 10, column: 17, scope: !52) 209 210!59 = distinct !DISubprogram(name: "empty", linkageName: "_ZN1T5emptyEv", scope: !60, file: !3, line: 25, type: !63, scopeLine: 25, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2, declaration: !62, retainedNodes: !4) 211!60 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "T", file: !3, line: 22, size: 8, flags: DIFlagTypePassByValue, elements: !61, identifier: "_ZTS1T") 212!61 = !{!62} 213!62 = !DISubprogram(name: "empty", linkageName: "_ZN1T5emptyEv", scope: !60, file: !3, line: 23, type: !63, scopeLine: 23, flags: DIFlagPrototyped, spFlags: 0) 214!63 = !DISubroutineType(types: !64) 215!64 = !{!65, !66} 216!65 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64) 217!66 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !60, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer) 218!67 = !DILocalVariable(name: "this", arg: 1, scope: !59, type: !68, flags: DIFlagArtificial | DIFlagObjectPointer) 219!68 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !60, size: 64) 220!69 = !DILocation(line: 0, scope: !59) 221!70 = !DILocation(line: 25, column: 19, scope: !59) 222