xref: /llvm-project/llvm/test/DebugInfo/assignment-tracking/X86/sdag-dangling-dbgassign.ll (revision 30845e8ab46c416a2e333eb84239e9ec71e92617)
1; RUN: llc %s -stop-before finalize-isel -o - \
2; RUN:    -experimental-debug-variable-locations=false \
3; RUN: | FileCheck %s --check-prefixes=CHECK,DBGVALUE
4
5; RUN: llc --try-experimental-debuginfo-iterators %s -stop-before finalize-isel -o - \
6; RUN:    -experimental-debug-variable-locations=false \
7; RUN: | FileCheck %s --check-prefixes=CHECK,DBGVALUE
8; RUN: llc %s -stop-before finalize-isel -o - \
9; RUN:    -experimental-debug-variable-locations=true \
10; RUN: | FileCheck %s --check-prefixes=CHECK,INSTRREF
11
12
13; RUN: llc --try-experimental-debuginfo-iterators %s -stop-before finalize-isel -o - \
14; RUN:    -experimental-debug-variable-locations=true \
15; RUN: | FileCheck %s --check-prefixes=CHECK,INSTRREF
16
17;--------------------------------------------------------------------
18; Adapted from sdag-dangling-dbgvalue.ll to test dbg.assign intrinsics. This
19; ensures that dbg.assigns with no linked store are treated as dbg.values.  For
20; ease of writing, all the dbg.assign intrinsics refer to the same DIAssignID
21; !54. There is no linked store in any case.
22;
23; This test case is basically generated from the following C code.
24; Compiled with "--target=x86_64-apple-darwin -S -g -O3" to get debug
25; info for optimized code.
26;
27; struct SS {
28;   int a;
29;   int b;
30; } S = { .a = 23, .b = -17 };
31;
32; int test1() {
33;   struct SS* foo1 = &S;
34;   return (int)foo1;
35; }
36;
37; int test2() {
38;   struct SS* foo2 = &S;
39;   struct SS* bar2 = &S;
40;   return (int)foo2 + (int)bar2;
41; }
42;
43; int test3() {
44;   struct SS* bar3 = &S;
45;   struct SS* foo3 = &S;
46;   return (int)foo3 + (int)bar3;
47; }
48;
49; int test4() {
50;   struct SS* foo4 = &S;
51;   struct SS* bar4 = &S;
52;   foo = 0;
53;   return (int)foo4 + (int)bar4;
54; }
55;
56; int test5() {
57;   struct SS* bar5 = &S;
58;   struct SS* foo5 = &S;
59;   foo5 = 0;
60;   return (int)foo5 + (int)bar5;
61; }
62;--------------------------------------------------------------------
63
64; CHECK:  ![[FOO1:.*]] = !DILocalVariable(name: "foo1"
65; CHECK:  ![[BAR1:.*]] = !DILocalVariable(name: "bar1"
66; CHECK:  ![[FOO2:.*]] = !DILocalVariable(name: "foo2"
67; CHECK:  ![[BAR2:.*]] = !DILocalVariable(name: "bar2"
68; CHECK:  ![[FOO3:.*]] = !DILocalVariable(name: "bar3"
69; CHECK:  ![[BAR3:.*]] = !DILocalVariable(name: "foo3"
70; CHECK:  ![[FOO4:.*]] = !DILocalVariable(name: "foo4"
71; CHECK:  ![[BAR4:.*]] = !DILocalVariable(name: "bar4"
72; CHECK:  ![[BAR5:.*]] = !DILocalVariable(name: "bar5"
73; CHECK:  ![[FOO5:.*]] = !DILocalVariable(name: "foo5"
74
75source_filename = "sdag-dangling-dbgvalue.c"
76target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
77target triple = "x86_64-apple-macosx10.4.0"
78
79%struct.SS = type { i32, i32 }
80
81@S = global %struct.SS { i32 23, i32 -17 }, align 4, !dbg !0
82
83; Verify that the def comes before the for foo1.
84define i32 @test1() local_unnamed_addr #0 !dbg !17 {
85; CHECK-LABEL: bb.0.entry1
86; CHECK-NEXT:    DBG_VALUE 0, $noreg, ![[BAR1]], !DIExpression()
87; CHECK-NEXT:    [[REG1:%[0-9]+]]:gr64 = LEA64r
88; INSTRREF-SAME:    debug-instr-number 1
89; INSTRREF-NEXT:  DBG_INSTR_REF ![[FOO1]], !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(1, 0)
90; DBGVALUE-NEXT:  DBG_VALUE [[REG1]], $noreg, ![[FOO1]], !DIExpression()
91entry1:
92  call void @llvm.dbg.assign(metadata ptr @S, metadata !20, metadata !DIExpression(), metadata !54, metadata ptr undef, metadata !DIExpression()), !dbg !23
93  call void @llvm.dbg.assign(metadata ptr null, metadata !22, metadata !DIExpression(), metadata !54, metadata ptr undef, metadata !DIExpression()), !dbg !24
94  ret i32 ptrtoint (ptr @S to i32), !dbg !25
95}
96
97; Verify that the def comes before the for foo2 and bar2.
98define i32 @test2() local_unnamed_addr #0 !dbg !26 {
99; CHECK-LABEL: bb.0.entry2
100; CHECK-NEXT:    [[REG2:%[0-9]+]]:gr64 = LEA64r
101; INSTRREF-SAME:    debug-instr-number 1
102; INSTRREF-NEXT: DBG_INSTR_REF ![[FOO2]], !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(1, 0)
103; INSTRREF-NEXT: DBG_INSTR_REF ![[BAR2]], !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(1, 0)
104; DBGVALUE-NEXT: DBG_VALUE [[REG2]], $noreg, ![[FOO2]], !DIExpression
105; DBGVALUE-NEXT: DBG_VALUE [[REG2]], $noreg, ![[BAR2]], !DIExpression
106entry2:
107  call void @llvm.dbg.assign(metadata ptr @S, metadata !28, metadata !DIExpression(), metadata !54, metadata ptr undef, metadata !DIExpression()), !dbg !30
108  call void @llvm.dbg.assign(metadata ptr @S, metadata !29, metadata !DIExpression(), metadata !54, metadata ptr undef, metadata !DIExpression()), !dbg !31
109  ret i32 add (i32 ptrtoint (ptr @S to i32), i32 ptrtoint (ptr @S to i32)), !dbg !32
110}
111
112; Verify that the def comes before the for foo3 and bar3.
113define i32 @test3() local_unnamed_addr #0 !dbg !33 {
114; CHECK-LABEL: bb.0.entry3
115; CHECK-NEXT:    [[REG3:%[0-9]+]]:gr64 = LEA64r
116; INSTRREF-SAME:    debug-instr-number 1
117; INSTRREF-NEXT: DBG_INSTR_REF ![[BAR3]], !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(1, 0)
118; INSTRREF-NEXT: DBG_INSTR_REF ![[FOO3]], !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(1, 0)
119; DBGVALUE-NEXT: DBG_VALUE [[REG3]], $noreg, ![[BAR3]], !DIExpression()
120; DBGVALUE-NEXT: DBG_VALUE [[REG3]], $noreg, ![[FOO3]], !DIExpression()
121entry3:
122  call void @llvm.dbg.assign(metadata ptr @S, metadata !36, metadata !DIExpression(), metadata !54, metadata ptr undef, metadata !DIExpression()), !dbg !38
123  call void @llvm.dbg.assign(metadata ptr @S, metadata !35, metadata !DIExpression(), metadata !54, metadata ptr undef, metadata !DIExpression()), !dbg !37
124  ret i32 add (i32 ptrtoint (ptr @S to i32), i32 ptrtoint (ptr @S to i32)), !dbg !39
125}
126
127; Verify that the def comes before the for bar4.
128define i32 @test4() local_unnamed_addr #0 !dbg !40 {
129; CHECK-LABEL: bb.0.entry4
130;; NOTE: The check for `DBG_VALUE $noreg, $noreg, ![[FOO4]], !DIExpression()`
131;; has been removed because AT lowering removes redundant debug intrinsics.
132; CHECK-NEXT:    DBG_VALUE 0, $noreg, ![[FOO4]], !DIExpression()
133; CHECK-NEXT:    [[REG4:%[0-9]+]]:gr64 = LEA64r
134; INSTRREF-SAME:    debug-instr-number 1
135; INSTRREF-NEXT: DBG_INSTR_REF ![[BAR4]], !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(1, 0)
136; DBGVALUE-NEXT: DBG_VALUE [[REG4]], $noreg, ![[BAR4]], !DIExpression()
137entry4:
138  call void @llvm.dbg.assign(metadata ptr @S, metadata !42, metadata !DIExpression(), metadata !54, metadata ptr undef, metadata !DIExpression()), !dbg !44
139  call void @llvm.dbg.assign(metadata ptr @S, metadata !43, metadata !DIExpression(), metadata !54, metadata ptr undef, metadata !DIExpression()), !dbg !45
140  call void @llvm.dbg.assign(metadata ptr null, metadata !42, metadata !DIExpression(), metadata !54, metadata ptr undef, metadata !DIExpression()), !dbg !44
141  ret i32 ptrtoint (ptr @S to i32), !dbg !46
142}
143
144; Verify that we do not get a DBG_VALUE that maps foo5 to @S here.
145define i32 @test5() local_unnamed_addr #0 !dbg !47 {
146; CHECK-LABEL: bb.0.entry5:
147; cHECK-NEXT:    DBG_VALUE $noreg, $noreg, ![[FOO5]], !DIExpression()
148; CHECK-NEXT:    DBG_VALUE 0, $noreg, ![[FOO5]], !DIExpression()
149; CHECK-NEXT:    [[REG5:%[0-9]+]]:gr64 = LEA64r
150; INSTRREF-SAME:    debug-instr-number 1
151; INSTRREF-NEXT: DBG_INSTR_REF ![[BAR5]], !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(1, 0)
152; DBGVALUE-NEXT: DBG_VALUE [[REG5]], $noreg, ![[BAR5]], !DIExpression()
153; CHECK-NOT:     DBG_{{.*}} ![[FOO5]], !DIExpression()
154; CHECK:         RET
155entry5:
156  call void @llvm.dbg.assign(metadata ptr @S, metadata !49, metadata !DIExpression(), metadata !54, metadata ptr undef, metadata !DIExpression()), !dbg !51
157  call void @llvm.dbg.assign(metadata ptr @S, metadata !50, metadata !DIExpression(), metadata !54, metadata ptr undef, metadata !DIExpression()), !dbg !52
158  call void @llvm.dbg.assign(metadata ptr null, metadata !50, metadata !DIExpression(), metadata !54, metadata ptr undef, metadata !DIExpression()), !dbg !52
159  ret i32 ptrtoint (ptr @S to i32), !dbg !53
160}
161
162declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata) #1
163
164attributes #0 = { nounwind readnone uwtable }
165attributes #1 = { nounwind readnone speculatable }
166
167!llvm.dbg.cu = !{!2}
168!llvm.module.flags = !{!12, !13, !14, !15, !1000}
169!llvm.ident = !{!16}
170
171!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
172!1 = distinct !DIGlobalVariable(name: "S", scope: !2, file: !3, line: 4, type: !8, isLocal: false, isDefinition: true)
173!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 7.0.0 (trunk 327229) (llvm/trunk 327239)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, retainedTypes: !5, globals: !7)
174!3 = !DIFile(filename: "sdag-dangling-dbgvalue.c", directory: "/repo/uabbpet/llvm-master")
175!4 = !{}
176!5 = !{!6}
177!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
178!7 = !{!0}
179!8 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "SS", file: !3, line: 1, size: 64, elements: !9)
180!9 = !{!10, !11}
181!10 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !8, file: !3, line: 2, baseType: !6, size: 32)
182!11 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !8, file: !3, line: 3, baseType: !6, size: 32, offset: 32)
183!12 = !{i32 2, !"Dwarf Version", i32 2}
184!13 = !{i32 2, !"Debug Info Version", i32 3}
185!14 = !{i32 1, !"wchar_size", i32 4}
186!15 = !{i32 7, !"PIC Level", i32 2}
187!16 = !{!"clang version 7.0.0 (trunk 327229) (llvm/trunk 327239)"}
188!17 = distinct !DISubprogram(name: "test1", scope: !3, file: !3, line: 6, type: !18, isLocal: false, isDefinition: true, scopeLine: 6, isOptimized: true, unit: !2, retainedNodes: !19)
189!18 = !DISubroutineType(types: !5)
190!19 = !{!20, !22}
191!20 = !DILocalVariable(name: "foo1", scope: !17, file: !3, line: 7, type: !21)
192!21 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !8, size: 64)
193!22 = !DILocalVariable(name: "bar1", scope: !17, file: !3, line: 8, type: !21)
194!23 = !DILocation(line: 7, column: 14, scope: !17)
195!24 = !DILocation(line: 8, column: 14, scope: !17)
196!25 = !DILocation(line: 9, column: 3, scope: !17)
197!26 = distinct !DISubprogram(name: "test2", scope: !3, file: !3, line: 12, type: !18, isLocal: false, isDefinition: true, scopeLine: 12, isOptimized: true, unit: !2, retainedNodes: !27)
198!27 = !{!28, !29}
199!28 = !DILocalVariable(name: "foo2", scope: !26, file: !3, line: 13, type: !21)
200!29 = !DILocalVariable(name: "bar2", scope: !26, file: !3, line: 14, type: !21)
201!30 = !DILocation(line: 13, column: 14, scope: !26)
202!31 = !DILocation(line: 14, column: 14, scope: !26)
203!32 = !DILocation(line: 15, column: 3, scope: !26)
204!33 = distinct !DISubprogram(name: "test3", scope: !3, file: !3, line: 18, type: !18, isLocal: false, isDefinition: true, scopeLine: 18, isOptimized: true, unit: !2, retainedNodes: !34)
205!34 = !{!35, !36}
206!35 = !DILocalVariable(name: "bar3", scope: !33, file: !3, line: 19, type: !21)
207!36 = !DILocalVariable(name: "foo3", scope: !33, file: !3, line: 20, type: !21)
208!37 = !DILocation(line: 19, column: 14, scope: !33)
209!38 = !DILocation(line: 20, column: 14, scope: !33)
210!39 = !DILocation(line: 21, column: 3, scope: !33)
211!40 = distinct !DISubprogram(name: "test4", scope: !3, file: !3, line: 24, type: !18, isLocal: false, isDefinition: true, scopeLine: 24, isOptimized: true, unit: !2, retainedNodes: !41)
212!41 = !{!42, !43}
213!42 = !DILocalVariable(name: "foo4", scope: !40, file: !3, line: 25, type: !21)
214!43 = !DILocalVariable(name: "bar4", scope: !40, file: !3, line: 26, type: !21)
215!44 = !DILocation(line: 25, column: 14, scope: !40)
216!45 = !DILocation(line: 26, column: 14, scope: !40)
217!46 = !DILocation(line: 28, column: 3, scope: !40)
218!47 = distinct !DISubprogram(name: "test5", scope: !3, file: !3, line: 31, type: !18, isLocal: false, isDefinition: true, scopeLine: 31, isOptimized: true, unit: !2, retainedNodes: !48)
219!48 = !{!49, !50}
220!49 = !DILocalVariable(name: "bar5", scope: !47, file: !3, line: 32, type: !21)
221!50 = !DILocalVariable(name: "foo5", scope: !47, file: !3, line: 33, type: !21)
222!51 = !DILocation(line: 32, column: 14, scope: !47)
223!52 = !DILocation(line: 33, column: 14, scope: !47)
224!53 = !DILocation(line: 35, column: 3, scope: !47)
225!54 = distinct !DIAssignID()
226!1000 = !{i32 7, !"debug-info-assignment-tracking", i1 true}
227