1; RUN: llc -O0 %s -o - -filetype=obj \
2; RUN:   | llvm-dwarfdump -statistics - | FileCheck %s
3
4; int GlobalConst = 42;
5; int Global;
6;
7; struct S {
8;   static const int constant = 24;
9; } s;
10;
11; int __attribute__((always_inline)) square(int i) { return i * i; }
12; int cube(int i) {
13;   int squared = square(i);
14;   return squared*i;
15; }
16
17; GlobalConst,Global,s,s.constant,square::i,cube::i,cube::squared
18; CHECK: "unique source variables":7
19; +1 extra inline i.
20; CHECK: "source variables":8
21; -1 square::i
22; CHECK: "variables with location":7
23; CHECK: "scope bytes total":[[BYTES:[0-9]+]]
24; Because of the dbg.value in the middle of the function, the pc range coverage
25; must be below 100%.
26; CHECK-NOT: "scope bytes covered":0
27; CHECK-NOT "scope bytes covered":[[BYTES]]
28; CHECK: "scope bytes covered":
29
30; ModuleID = '/tmp/quality.cpp'
31source_filename = "/tmp/quality.cpp"
32target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
33target triple = "x86_64-apple-macosx10.12.0"
34
35%struct.S = type { i8 }
36
37@GlobalConst = global i32 42, align 4, !dbg !0
38@Global = global i32 0, align 4, !dbg !6
39@s = global %struct.S zeroinitializer, align 1, !dbg !9
40
41; Function Attrs: alwaysinline nounwind ssp uwtable
42define i32 @_Z6squarei(i32 %i) #0 !dbg !20 {
43entry:
44  %i.addr = alloca i32, align 4
45  store i32 %i, i32* %i.addr, align 4
46  ; Modified to loose debug info for i here.
47  call void @llvm.dbg.declare(metadata i32* undef, metadata !23, metadata !24), !dbg !25
48  %0 = load i32, i32* %i.addr, align 4, !dbg !26
49  %1 = load i32, i32* %i.addr, align 4, !dbg !27
50  %mul = mul nsw i32 %0, %1, !dbg !28
51  ret i32 %mul, !dbg !29
52}
53
54; Function Attrs: nounwind readnone speculatable
55declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
56declare void @llvm.dbg.value(metadata, metadata, metadata) #1
57
58; Function Attrs: noinline nounwind optnone ssp uwtable
59define i32 @_Z4cubei(i32 %i) #2 !dbg !30 {
60entry:
61  %i.addr.i = alloca i32, align 4
62  call void @llvm.dbg.declare(metadata i32* %i.addr.i, metadata !23, metadata !24), !dbg !31
63  %i.addr = alloca i32, align 4
64  %squared = alloca i32, align 4
65  store i32 %i, i32* %i.addr, align 4
66  call void @llvm.dbg.declare(metadata i32* %i.addr, metadata !33, metadata !24), !dbg !34
67  %0 = load i32, i32* %i.addr, align 4, !dbg !37
68  store i32 %0, i32* %i.addr.i, align 4
69  %1 = load i32, i32* %i.addr.i, align 4, !dbg !38
70  %2 = load i32, i32* %i.addr.i, align 4, !dbg !39
71  %mul.i = mul nsw i32 %1, %2, !dbg !40
72  ; Modified to cover only about 50% of the lexical scope.
73  call void @llvm.dbg.value(metadata i32 %mul.i, metadata !35, metadata !24), !dbg !36
74  store i32 %mul.i, i32* %squared, align 4, !dbg !36
75  %3 = load i32, i32* %squared, align 4, !dbg !41
76  call void @llvm.dbg.value(metadata i32 %3, metadata !35, metadata !24), !dbg !36
77  %4 = load i32, i32* %i.addr, align 4, !dbg !42
78  %mul = mul nsw i32 %3, %4, !dbg !43
79  ret i32 %mul, !dbg !44
80}
81
82attributes #0 = { alwaysinline nounwind ssp uwtable }
83attributes #1 = { nounwind readnone speculatable }
84attributes #2 = { noinline nounwind optnone ssp uwtable }
85
86!llvm.dbg.cu = !{!2}
87!llvm.module.flags = !{!15, !16, !17, !18}
88!llvm.ident = !{!19}
89
90!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
91!1 = distinct !DIGlobalVariable(name: "GlobalConst", scope: !2, file: !3, line: 1, type: !8, isLocal: false, isDefinition: true)
92!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, globals: !5)
93!3 = !DIFile(filename: "/tmp/quality.cpp", directory: "/Volumes/Data/llvm")
94!4 = !{}
95!5 = !{!0, !6, !9}
96!6 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression())
97!7 = distinct !DIGlobalVariable(name: "Global", scope: !2, file: !3, line: 2, type: !8, isLocal: false, isDefinition: true)
98!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
99!9 = !DIGlobalVariableExpression(var: !10, expr: !DIExpression())
100!10 = distinct !DIGlobalVariable(name: "s", scope: !2, file: !3, line: 6, type: !11, isLocal: false, isDefinition: true)
101!11 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "S", file: !3, line: 4, size: 8, elements: !12, identifier: "_ZTS1S")
102!12 = !{!13}
103!13 = !DIDerivedType(tag: DW_TAG_member, name: "constant", scope: !11, file: !3, line: 5, baseType: !14, flags: DIFlagStaticMember, extraData: i32 24)
104!14 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !8)
105!15 = !{i32 2, !"Dwarf Version", i32 4}
106!16 = !{i32 2, !"Debug Info Version", i32 3}
107!17 = !{i32 1, !"wchar_size", i32 4}
108!18 = !{i32 7, !"PIC Level", i32 2}
109!19 = !{!"clang version 6.0.0 (trunk 310529) (llvm/trunk 310534)"}
110!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)
111!21 = !DISubroutineType(types: !22)
112!22 = !{!8, !8}
113!23 = !DILocalVariable(name: "i", arg: 1, scope: !20, file: !3, line: 8, type: !8)
114!24 = !DIExpression()
115!25 = !DILocation(line: 8, column: 47, scope: !20)
116!26 = !DILocation(line: 8, column: 59, scope: !20)
117!27 = !DILocation(line: 8, column: 63, scope: !20)
118!28 = !DILocation(line: 8, column: 61, scope: !20)
119!29 = !DILocation(line: 8, column: 52, scope: !20)
120!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)
121!31 = !DILocation(line: 8, column: 47, scope: !20, inlinedAt: !32)
122!32 = distinct !DILocation(line: 10, column: 17, scope: !30)
123!33 = !DILocalVariable(name: "i", arg: 1, scope: !30, file: !3, line: 9, type: !8)
124!34 = !DILocation(line: 9, column: 14, scope: !30)
125!35 = !DILocalVariable(name: "squared", scope: !30, file: !3, line: 10, type: !8)
126!36 = !DILocation(line: 10, column: 7, scope: !30)
127!37 = !DILocation(line: 10, column: 24, scope: !30)
128!38 = !DILocation(line: 8, column: 59, scope: !20, inlinedAt: !32)
129!39 = !DILocation(line: 8, column: 63, scope: !20, inlinedAt: !32)
130!40 = !DILocation(line: 8, column: 61, scope: !20, inlinedAt: !32)
131!41 = !DILocation(line: 11, column: 10, scope: !30)
132!42 = !DILocation(line: 11, column: 18, scope: !30)
133!43 = !DILocation(line: 11, column: 17, scope: !30)
134!44 = !DILocation(line: 11, column: 3, scope: !30)
135