xref: /llvm-project/llvm/test/tools/llvm-dwarfdump/X86/LTO_CCU_zero_loc_cov.ll (revision a273c40820f78d8b08e411897eee84dbda983488)
1;; llc will generate additional 'empty' DW_TAG_subroutine in sum.c's CU.
2;; It will not be considered by the statistics.
3; RUN: llc %s -o - -filetype=obj \
4; RUN:   | llvm-dwarfdump -statistics - | FileCheck %s
5
6;; Instructions to regenerate IR:
7;; clang -g -flto -emit-llvm -S -o main.ll -c main.c
8;; clang -g -flto -emit-llvm -S -o sum.ll -c sum.c
9;; llvm-link -S -o linked.ll main.ll sum.ll
10;; opt -O1 linked.ll -S -o merged.ll
11;; Hard coded a call to llvm.dbg.value intrinsic, replacing %10 argument with undef, in order to have 0% location coverage for a CCU referencing DIE.
12
13;; Source files:
14;;main.c:
15;;extern int sum(int a, int b);
16;;
17;;int main()
18;;{
19;;	int a = 10, b = 5;
20;;	int c = sum(a,b);
21;; int d = c + sum(c,2);
22;;	return 0;
23;;}
24;;sum.c:
25;;__attribute__((always_inline)) int sum(int a, int b)
26;;{
27;;	int result = a + b;
28;;	return result;
29;;}
30
31; CHECK:      "#source variables with location": 10,
32; CHECK:      "#variables with 0% of parent scope covered by DW_AT_location": 1,
33; CHECK:      "#params with 0% of parent scope covered by DW_AT_location": 1,
34
35; ModuleID = 'linked.ll'
36source_filename = "llvm-link"
37target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
38target triple = "x86_64-unknown-linux-gnu"
39
40; Function Attrs: noinline nounwind optnone uwtable
41define dso_local i32 @main() local_unnamed_addr #0 !dbg !11 {
42  %1 = alloca i32, align 4
43  %2 = alloca i32, align 4
44  %3 = alloca i32, align 4
45  %4 = alloca i32, align 4
46  %5 = alloca i32, align 4
47  store i32 0, ptr %1, align 4
48  call void @llvm.dbg.declare(metadata ptr %2, metadata !15, metadata !DIExpression()), !dbg !16
49  store i32 10, ptr %2, align 4, !dbg !16
50  call void @llvm.dbg.declare(metadata ptr %3, metadata !17, metadata !DIExpression()), !dbg !16
51  store i32 5, ptr %3, align 4, !dbg !16
52  call void @llvm.dbg.declare(metadata ptr %4, metadata !19, metadata !DIExpression()), !dbg !16
53  %6 = load i32, ptr %2, align 4, !dbg !16
54  %7 = load i32, ptr %3, align 4, !dbg !16
55  call void @llvm.dbg.value(metadata i32 %6, metadata !23, metadata !DIExpression()), !dbg !27
56  call void @llvm.dbg.value(metadata i32 %7, metadata !29, metadata !DIExpression()), !dbg !27
57  %8 = add nsw i32 %7, %6, !dbg !27
58  call void @llvm.dbg.value(metadata i32 %8, metadata !31, metadata !DIExpression()), !dbg !27
59  store i32 %8, ptr %4, align 4, !dbg !16
60  call void @llvm.dbg.declare(metadata ptr %5, metadata !32, metadata !DIExpression()), !dbg !16
61  %9 = load i32, ptr %4, align 4, !dbg !16
62  %10 = load i32, ptr %4, align 4, !dbg !16
63  call void @llvm.dbg.value(metadata i32 undef, metadata !23, metadata !DIExpression()), !dbg !36 ;; Hard coded line: There was %10 instead of undef.
64  call void @llvm.dbg.value(metadata i32 2, metadata !29, metadata !DIExpression()), !dbg !36
65  %11 = add nsw i32 2, %10, !dbg !36
66  call void @llvm.dbg.value(metadata i32 %11, metadata !31, metadata !DIExpression()), !dbg !36
67  %12 = add nsw i32 %9, %11, !dbg !16
68  store i32 %12, ptr %5, align 4, !dbg !16
69  ret i32 0, !dbg !16
70}
71
72; Function Attrs: mustprogress nofree nosync nounwind readnone speculatable willreturn
73declare void @llvm.dbg.declare(metadata, metadata, metadata)
74
75; Function Attrs: alwaysinline mustprogress nofree norecurse nosync nounwind readnone uwtable willreturn
76define dso_local i32 @sum(i32 %0, i32 %1) local_unnamed_addr #2 !dbg !24 {
77  call void @llvm.dbg.value(metadata i32 %0, metadata !23, metadata !DIExpression()), !dbg !41
78  call void @llvm.dbg.value(metadata i32 %1, metadata !29, metadata !DIExpression()), !dbg !41
79  %3 = add nsw i32 %1, %0, !dbg !41
80  call void @llvm.dbg.value(metadata i32 %3, metadata !31, metadata !DIExpression()), !dbg !41
81  ret i32 %3, !dbg !41
82}
83
84; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
85declare void @llvm.dbg.value(metadata, metadata, metadata)
86
87attributes #0 = { noinline nounwind optnone uwtable }
88attributes #2 = { alwaysinline mustprogress nofree norecurse nosync nounwind readnone uwtable willreturn }
89
90!llvm.dbg.cu = !{!0, !3}
91!llvm.ident = !{!5, !5}
92!llvm.module.flags = !{!6, !7, !8, !9, !10}
93
94!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 14.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
95!1 = !DIFile(filename: "main.c", directory: "/dir")
96!2 = !{}
97!3 = distinct !DICompileUnit(language: DW_LANG_C99, file: !4, producer: "clang version 14.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
98!4 = !DIFile(filename: "sum.c", directory: "/dir")
99!5 = !{!"clang version 14.0.0"}
100!6 = !{i32 7, !"Dwarf Version", i32 4}
101!7 = !{i32 2, !"Debug Info Version", i32 3}
102!8 = !{i32 1, !"wchar_size", i32 4}
103!9 = !{i32 7, !"uwtable", i32 1}
104!10 = !{i32 7, !"frame-pointer", i32 2}
105!11 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 3, type: !12, scopeLine: 4, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
106!12 = !DISubroutineType(types: !13)
107!13 = !{!14}
108!14 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
109!15 = !DILocalVariable(name: "a", scope: !11, file: !1, line: 5, type: !14)
110!16 = !DILocation(line: 5, column: 6, scope: !11)
111!17 = !DILocalVariable(name: "b", scope: !11, file: !1, line: 5, type: !14)
112!19 = !DILocalVariable(name: "c", scope: !11, file: !1, line: 6, type: !14)
113!23 = !DILocalVariable(name: "a", arg: 1, scope: !24, file: !4, line: 1, type: !14)
114!24 = distinct !DISubprogram(name: "sum", scope: !4, file: !4, line: 1, type: !25, scopeLine: 2, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !3, retainedNodes: !2)
115!25 = !DISubroutineType(types: !26)
116!26 = !{!14, !14, !14}
117!27 = !DILocation(line: 0, scope: !24, inlinedAt: !28)
118!28 = distinct !DILocation(line: 6, column: 10, scope: !11)
119!29 = !DILocalVariable(name: "b", arg: 2, scope: !24, file: !4, line: 1, type: !14)
120!31 = !DILocalVariable(name: "result", scope: !24, file: !4, line: 3, type: !14)
121!32 = !DILocalVariable(name: "d", scope: !11, file: !1, line: 7, type: !14)
122!36 = !DILocation(line: 0, scope: !24, inlinedAt: !37)
123!37 = distinct !DILocation(line: 7, column: 14, scope: !11)
124!41 = !DILocation(line: 0, scope: !24)
125