xref: /llvm-project/llvm/test/DebugInfo/Generic/dbg-value-lower-linenos.ll (revision 094572701dce4aaf36f4521d6cf750420d39f206)
1; RUN: opt < %s -S -passes=mem2reg,instcombine | FileCheck %s
2; RUN: opt --try-experimental-debuginfo-iterators < %s -S -passes=mem2reg,instcombine | FileCheck %s
3
4; The '%bar' alloca will be promoted to an SSA register by mem2reg: test that
5; zero line number are assigned to the dbg.value intrinsics that are inserted
6; to represent changes in variable value. No machine instructions are
7; generated from these dbg.values so their lines are irrelevant, only the
8; scope and inlining information must be correct.
9
10; In the second function here, LowerDbgDeclare will promote various variable
11; accesses of a dbg.declare'd alloca into dbg.values. Check that their line
12; numbers are sane too. (IR copied from DebugInfo/X86/formal_parameter.ll).
13
14; CHECK-LABEL: define i32 @foo
15
16; CHECK-LABEL: bb1:
17; CHECK-NEXT:  %bar.0 = phi i32
18; CHECK-NEXT:  #dbg_value(i32 %bar.0,{{.*}},  ![[UNKNOWN:[0-9]+]]
19; CHECK-NEXT:  %totest = load
20; CHECK-NEXT:  %add = add i32 %bar.0
21; CHECK-NEXT:  #dbg_value(i32 %add, {{.*}},  ![[UNKNOWN]]
22; CHECK-NEXT:  %cond = icmp ult
23; CHECK-NEXT:  br i1 %cond, label %bb1, label %bb2
24;
25; CHECK-LABEL: bb2:
26; CHECK-NEXT:  %toret = add i32 %bar.0, 3
27; CHECK-NEXT:  #dbg_value(i32 %toret, {{.*}},  ![[UNKNOWN]]
28; CHECK-NEXT:  ret i32 %toret
29
30define i32 @foo(ptr %bees, ptr %output) {
31entry:
32  %bar = alloca i32
33  call void @llvm.dbg.declare(metadata ptr %bar, metadata !7, metadata !DIExpression()), !dbg !6
34  store i32 0, ptr %bar
35  br label %bb1, !dbg !6
36
37bb1:
38  %totest = load i32, ptr %bees, !dbg !8
39  %load1 = load i32, ptr %bar, !dbg !9
40  %add = add i32 %load1, 1, !dbg !10
41  store i32 %add, ptr %bar, !dbg !11
42  %toret = add i32 %add, 2, !dbg !12
43  %cond = icmp ult i32 %totest, %load1, !dbg !13
44  br i1 %cond, label %bb1, label %bb2, !dbg !14
45
46bb2:
47  store i32 %toret, ptr %bar, !dbg !16
48  ret i32 %toret
49}
50
51; In the following, the dbg.value created for the store should get the stores
52; line number, the other dbg.values should be unknown.
53; CHECK-LABEL: define void @bar
54;
55; CHECK:      #dbg_value(i32 %map, ![[MAPVAR:[0-9]+]],{{.*}}),
56; CHECK-SAME:           ![[UNKNOWN2:[0-9]+]]
57; CHECK-NEXT: store
58; CHECK-NEXT: #dbg_value(ptr %map.addr, ![[MAPVAR]],
59; CHECK-SAME:           !DIExpression(DW_OP_deref),
60; CHECK-SAME:           ![[UNKNOWN2]]
61; CHECK-NEXT: call
62; CHECK-NEXT: load
63; CHECK-NEXT: #dbg_value(i32 %{{[0-9]+}}, ![[MAPVAR]],
64; CHECK-SAME:           ![[UNKNOWN2]]
65
66define void @bar(i32 %map) !dbg !20 {
67entry:
68  %map.addr = alloca i32, align 4
69  store i32 %map, ptr %map.addr, align 4, !dbg !27
70  call void @llvm.dbg.declare(metadata ptr %map.addr, metadata !21, metadata !DIExpression()), !dbg !22
71  %call = call i32 (ptr, ...) @lookup(ptr %map.addr), !dbg !23
72%0 = load i32, ptr %map.addr, align 4, !dbg !24
73  %call1 = call i32 (i32, ...) @verify(i32 %0), !dbg !25
74  ret void, !dbg !26
75}
76
77declare void @llvm.dbg.value(metadata, metadata, metadata)
78declare void @llvm.dbg.declare(metadata, metadata, metadata)
79declare i32 @verify(...)
80declare i32 @lookup(...)
81
82; CHECK: ![[SUBPROG:[0-9]+]] = distinct !DISubprogram(name: "nope",
83; CHECK: ![[UNKNOWN]] = !DILocation(line: 0, scope: ![[SUBPROG]])
84
85; CHECK: ![[SUBPROG2:[0-9]+]] = distinct !DISubprogram(name: "thin",
86; CHECK: ![[MAPVAR]] = !DILocalVariable(name: "floogie",
87; CHECK: ![[UNKNOWN2]] = !DILocation(line: 0
88
89!llvm.module.flags = !{!4}
90!llvm.dbg.cu = !{!2}
91!1 = !DILocalVariable(name: "bees", scope: !5, type: null)
92!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "beards", isOptimized: true, runtimeVersion: 4, emissionKind: FullDebug)
93!3 = !DIFile(filename: "bees.cpp", directory: "")
94!4 = !{i32 2, !"Debug Info Version", i32 3}
95!5 = distinct !DISubprogram(name: "nope", scope: !3, file: !3, line: 1, unit: !2)
96!6 = !DILocation(line: 1, scope: !5)
97!7 = !DILocalVariable(name: "flannel", scope: !5, type: null)
98!8 = !DILocation(line: 2, scope: !5)
99!9 = !DILocation(line: 3, scope: !5)
100!10 = !DILocation(line: 4, scope: !5)
101!11 = !DILocation(line: 5, scope: !5)
102!12 = !DILocation(line: 6, scope: !5)
103!13 = !DILocation(line: 7, scope: !5)
104!14 = !DILocation(line: 8, scope: !5)
105!15 = distinct !DISubprogram(name: "wat", scope: !2, file: !3, line: 10, unit: !2)
106!16 = !DILocation(line: 9, scope: !15, inlinedAt: !14)
107!20 = distinct !DISubprogram(name: "thin", scope: !3, file: !3, line: 20, unit: !2)
108!21 = !DILocalVariable(name: "floogie", scope: !20, type: null)
109!22 = !DILocation(line: 21, scope: !20)
110!23 = !DILocation(line: 22, scope: !20)
111!24 = !DILocation(line: 23, scope: !20)
112!25 = !DILocation(line: 24, scope: !20)
113!26 = !DILocation(line: 25, scope: !20)
114!27 = !DILocation(line: 20, scope: !20)
115