1; RUN: opt < %s -S -inline | FileCheck %s
2; RUN: opt < %s -S -passes='cgscc(inline)' | FileCheck %s
3;
4; The purpose of this test is to check that inline pass preserves debug info
5; for variable using the dbg.declare intrinsic.
6;
7;; This test was generated by running this command:
8;; clang.exe -S -O0 -emit-llvm -g foo.c
9;;
10;; foo.c
11;; ==========================
12;; float foo(float x)
13;; {
14;;    return x;
15;; }
16;;
17;; void bar(float *dst)
18;; {
19;;    dst[0] = foo(dst[0]);
20;; }
21;; ==========================
22
23target datalayout = "e-m:w-p:32:32-i64:64-f80:32-n8:16:32-S32"
24target triple = "i686-pc-windows-msvc"
25
26; Function Attrs: nounwind
27define float @foo(float %x) #0 !dbg !4 {
28entry:
29  %x.addr = alloca float, align 4
30  store float %x, float* %x.addr, align 4
31  call void @llvm.dbg.declare(metadata float* %x.addr, metadata !16, metadata !17), !dbg !18
32  %0 = load float, float* %x.addr, align 4, !dbg !19
33  ret float %0, !dbg !19
34}
35
36; Function Attrs: nounwind readnone
37declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
38
39; CHECK: define void @bar
40
41; Function Attrs: nounwind
42define void @bar(float* %dst) #0 !dbg !9 {
43entry:
44
45; CHECK: [[x_addr_i:%.+]] = alloca float, align 4
46; CHECK: store float {{.*}}, float* [[x_addr_i]]
47; CHECK-NEXT: void @llvm.dbg.declare(metadata float* [[x_addr_i]], metadata [[m23:![0-9]+]], metadata !DIExpression()), !dbg [[m24:![0-9]+]]
48
49  %dst.addr = alloca float*, align 4
50  store float* %dst, float** %dst.addr, align 4
51  call void @llvm.dbg.declare(metadata float** %dst.addr, metadata !20, metadata !17), !dbg !21
52  %0 = load float*, float** %dst.addr, align 4, !dbg !22
53  %arrayidx = getelementptr inbounds float, float* %0, i32 0, !dbg !22
54  %1 = load float, float* %arrayidx, align 4, !dbg !22
55  %call = call float @foo(float %1), !dbg !22
56
57; CHECK-NOT: call float @foo
58
59  %2 = load float*, float** %dst.addr, align 4, !dbg !22
60  %arrayidx1 = getelementptr inbounds float, float* %2, i32 0, !dbg !22
61  store float %call, float* %arrayidx1, align 4, !dbg !22
62  ret void, !dbg !23
63}
64
65attributes #0 = { nounwind }
66attributes #1 = { nounwind readnone }
67
68!llvm.dbg.cu = !{!0}
69!llvm.module.flags = !{!13, !14}
70!llvm.ident = !{!15}
71
72!0 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang version 3.6.0 (trunk)", isOptimized: false, emissionKind: FullDebug, file: !1, enums: !2, retainedTypes: !2, globals: !2, imports: !2)
73!1 = !DIFile(filename: "foo.c", directory: "")
74!2 = !{}
75!4 = distinct !DISubprogram(name: "foo", line: 1, isLocal: false, isDefinition: true, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 2, file: !1, scope: !5, type: !6, retainedNodes: !2)
76!5 = !DIFile(filename: "foo.c", directory: "")
77!6 = !DISubroutineType(types: !7)
78!7 = !{!8, !8}
79!8 = !DIBasicType(tag: DW_TAG_base_type, name: "float", size: 32, align: 32, encoding: DW_ATE_float)
80!9 = distinct !DISubprogram(name: "bar", line: 6, isLocal: false, isDefinition: true, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 7, file: !1, scope: !5, type: !10, retainedNodes: !2)
81!10 = !DISubroutineType(types: !11)
82!11 = !{null, !12}
83!12 = !DIDerivedType(tag: DW_TAG_pointer_type, size: 32, align: 32, baseType: !8)
84!13 = !{i32 2, !"Dwarf Version", i32 4}
85!14 = !{i32 2, !"Debug Info Version", i32 3}
86!15 = !{!"clang version 3.6.0 (trunk)"}
87!16 = !DILocalVariable(name: "x", line: 1, arg: 1, scope: !4, file: !5, type: !8)
88!17 = !DIExpression()
89!18 = !DILocation(line: 1, column: 17, scope: !4)
90!19 = !DILocation(line: 3, column: 5, scope: !4)
91!20 = !DILocalVariable(name: "dst", line: 6, arg: 1, scope: !9, file: !5, type: !12)
92!21 = !DILocation(line: 6, column: 17, scope: !9)
93!22 = !DILocation(line: 8, column: 14, scope: !9)
94!23 = !DILocation(line: 9, column: 1, scope: !9)
95
96; CHECK: [[FOO:![0-9]+]] = distinct !DISubprogram(name: "foo",
97; CHECK: [[m23]] = !DILocalVariable(name: "x", arg: 1, scope: [[FOO]]
98; CHECK: [[BAR:![0-9]+]] = distinct !DISubprogram(name: "bar",
99; CHECK: [[m24]] = !DILocation(line: 1, column: 17, scope: [[FOO]], inlinedAt: [[CALL_SITE:![0-9]+]])
100; CHECK: [[CALL_SITE]] = distinct !DILocation(line: 8, column: 14, scope: [[BAR]])
101