xref: /llvm-project/llvm/test/DebugInfo/Generic/assignment-tracking/salvage-value.ll (revision 2499978aae8398023363a157185c8021c32ea363)
1; RUN: opt %s -S -o - -passes=instcombine \
2; RUN: | FileCheck %s --implicit-check-not="call void @llvm.dbg"
3; RUN: opt --try-experimental-debuginfo-iterators %s -S -o - -passes=instcombine \
4; RUN: | FileCheck %s --implicit-check-not="call void @llvm.dbg"
5
6;; Hand-written (the debug info doesn't necessarily make sense and isn't fully
7;; formed). Test salvaging a dbg.assign value and address. Checks and comments
8;; are inline.
9
10define dso_local void @fun(i32  %x, i32 %y, ptr %p) !dbg !7 {
11entry:
12  %add = add nsw i32 %x, 1, !dbg !22
13  call void @llvm.dbg.assign(metadata i32 %add, metadata !14, metadata !DIExpression(), metadata !28, metadata ptr %p, metadata !DIExpression()), !dbg !16
14;; %add is salvaged.
15; CHECK: #dbg_assign(i32 %x,{{.+}}!DIExpression(DW_OP_plus_uconst, 1, DW_OP_stack_value),{{.+}}, ptr %p, !DIExpression(),
16
17 %add1 = add nsw i32 %x, %y, !dbg !29
18 call void @llvm.dbg.assign(metadata i32 %add1, metadata !32, metadata !DIExpression(), metadata !31, metadata ptr %p, metadata !DIExpression()), !dbg !16
19;; %add1 is salvaged using a variadic expression.
20; CHECK-NEXT: #dbg_assign(!DIArgList(i32 %x, i32 %y), ![[#]], !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_plus, DW_OP_stack_value), ![[#]], ptr %p, !DIExpression(),
21
22  %arrayidx0 = getelementptr inbounds i32, ptr %p, i32 0
23  call void @llvm.dbg.assign(metadata i32 %x, metadata !14, metadata !DIExpression(), metadata !17, metadata ptr %arrayidx0, metadata !DIExpression()), !dbg !16
24;; %arrayidx0 is salvaged (zero offset, so the gep is just replaced with %p).
25; CHECK-NEXT: #dbg_assign(i32 %x,{{.+}}, !DIExpression(),{{.+}}, ptr %p, !DIExpression(),
26
27  %arrayidx1 = getelementptr inbounds i32, ptr %p, i32 1
28  call void @llvm.dbg.assign(metadata i32 %x, metadata !33, metadata !DIExpression(), metadata !18, metadata ptr %arrayidx1, metadata !DIExpression()), !dbg !16
29;; %arrayidx1 is salvaged.
30; CHECK-NEXT: #dbg_assign(i32 %x,{{.+}}, !DIExpression(),{{.+}}, ptr %p, !DIExpression(DW_OP_plus_uconst, 4),
31
32  %arrayidx2 = getelementptr inbounds i32, ptr %p, i32 %x
33  call void @llvm.dbg.assign(metadata i32 %x, metadata !34, metadata !DIExpression(), metadata !19, metadata ptr %arrayidx2, metadata !DIExpression()), !dbg !16
34;; Variadic DIExpressions for dbg.assign address component is not supported -
35;; set poison.
36; CHECK-NEXT: #dbg_assign(i32 %x,{{.+}}, !DIExpression(),{{.+}}, ptr poison, !DIExpression(),
37
38  ret void
39}
40
41declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata)
42
43!llvm.dbg.cu = !{!0}
44!llvm.module.flags = !{!2, !3, !4, !5, !1000}
45!llvm.ident = !{!6}
46
47!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 14.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
48!1 = !DIFile(filename: "test.cpp", directory: "/")
49!2 = !{i32 7, !"Dwarf Version", i32 5}
50!3 = !{i32 2, !"Debug Info Version", i32 3}
51!4 = !{i32 1, !"wchar_size", i32 4}
52!5 = !{i32 7, !"uwtable", i32 1}
53!6 = !{!"clang version 14.0.0"}
54!7 = distinct !DISubprogram(name: "fun", linkageName: "fun", scope: !1, file: !1, line: 2, type: !8, scopeLine: 2, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !11)
55!8 = !DISubroutineType(types: !9)
56!9 = !{null, !10, !10}
57!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
58!11 = !{!12, !13, !14}
59!12 = !DILocalVariable(name: "x", arg: 1, scope: !7, file: !1, line: 2, type: !10)
60!13 = !DILocalVariable(name: "y", arg: 2, scope: !7, file: !1, line: 2, type: !10)
61!14 = !DILocalVariable(name: "Local", scope: !7, file: !1, line: 3, type: !10)
62!16 = !DILocation(line: 0, scope: !7)
63!17 = distinct !DIAssignID()
64!18 = distinct !DIAssignID()
65!19 = distinct !DIAssignID()
66!21 = !DILocation(line: 3, column: 3, scope: !7)
67!22 = !DILocation(line: 3, column: 17, scope: !7)
68!28 = distinct !DIAssignID()
69!29 = !DILocation(line: 4, column: 13, scope: !7)
70!31 = distinct !DIAssignID()
71!32 = !DILocalVariable(name: "Local1", scope: !7, file: !1, line: 3, type: !10)
72!33 = !DILocalVariable(name: "Local2", scope: !7, file: !1, line: 3, type: !10)
73!34 = !DILocalVariable(name: "Local3", scope: !7, file: !1, line: 3, type: !10)
74!35 = !DILocalVariable(name: "Local4", scope: !7, file: !1, line: 3, type: !10)
75!1000 = !{i32 7, !"debug-info-assignment-tracking", i1 true}
76