xref: /llvm-project/llvm/test/DebugInfo/Generic/assignment-tracking/mem2reg/single-store-alloca.ll (revision 094572701dce4aaf36f4521d6cf750420d39f206)
1; RUN: opt -passes=mem2reg -S %s -o - \
2; RUN: | FileCheck %s --implicit-check-not="call void @llvm.dbg"
3; RUN: opt --try-experimental-debuginfo-iterators -passes=mem2reg -S %s -o - \
4; RUN: | FileCheck %s --implicit-check-not="call void @llvm.dbg"
5
6;; Test assignment tracking debug info when mem2reg promotes a single-store
7;; alloca. Additionally, check that all the dbg.assigns linked to the alloca
8;; are cleaned up, including duplciates.
9
10; CHECK: entry:
11; CHECK-NEXT: #dbg_value(i32 %a, ![[B:[0-9]+]]
12; CHECK-NEXT: #dbg_value(i32 %a, ![[A:[0-9]+]]
13; CHECK-NEXT: ret
14
15; CHECK-DAG: ![[A]] = !DILocalVariable(name: "a",
16; CHECK-DAG: ![[B]] = !DILocalVariable(name: "b",
17
18;; 1. using source:
19;; $ cat test.cpp
20;; int f(int a) { return a; }
21;; 2. manually duplicating the dbg.assign lnked to a's alloca to ensure
22;;    duplicates are still cleaned up,
23;; 3. and with a dbg.assign for another variable ("b") attached to a's alloca
24;;    to check that a dbg.value is generated for the variable to represent the
25;;    store despite the store not having a dbg.assign linked for it.
26
27; Function Attrs: mustprogress nounwind uwtable
28define dso_local noundef i32 @_Z1fi(i32 noundef %a) #0 !dbg !7 {
29entry:
30  %a.addr = alloca i32, align 4, !DIAssignID !13
31  call void @llvm.dbg.assign(metadata i1 undef, metadata !12, metadata !DIExpression(), metadata !13, metadata ptr %a.addr, metadata !DIExpression()), !dbg !14
32  call void @llvm.dbg.assign(metadata i1 undef, metadata !12, metadata !DIExpression(), metadata !13, metadata ptr %a.addr, metadata !DIExpression()), !dbg !14
33  call void @llvm.dbg.assign(metadata i1 undef, metadata !22, metadata !DIExpression(), metadata !13, metadata ptr %a.addr, metadata !DIExpression()), !dbg !14
34  store i32 %a, ptr %a.addr, align 4, !DIAssignID !19
35  call void @llvm.dbg.assign(metadata i32 %a, metadata !12, metadata !DIExpression(), metadata !19, metadata ptr %a.addr, metadata !DIExpression()), !dbg !14
36  %0 = load i32, ptr %a.addr, align 4, !dbg !20
37  ret i32 %0, !dbg !21
38}
39
40declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata)
41
42!llvm.dbg.cu = !{!0}
43!llvm.module.flags = !{!2, !3, !4, !5, !1000}
44!llvm.ident = !{!6}
45
46!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)
47!1 = !DIFile(filename: "test.cpp", directory: "/")
48!2 = !{i32 7, !"Dwarf Version", i32 5}
49!3 = !{i32 2, !"Debug Info Version", i32 3}
50!4 = !{i32 1, !"wchar_size", i32 4}
51!5 = !{i32 7, !"uwtable", i32 1}
52!6 = !{!"clang version 14.0.0)"}
53!7 = distinct !DISubprogram(name: "f", linkageName: "_Z1fi", scope: !1, file: !1, line: 1, type: !8, scopeLine: 1, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !11)
54!8 = !DISubroutineType(types: !9)
55!9 = !{!10, !10}
56!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
57!11 = !{!12}
58!12 = !DILocalVariable(name: "a", arg: 1, scope: !7, file: !1, line: 1, type: !10)
59!13 = distinct !DIAssignID()
60!14 = !DILocation(line: 0, scope: !7)
61!19 = distinct !DIAssignID()
62!20 = !DILocation(line: 1, column: 23, scope: !7)
63!21 = !DILocation(line: 1, column: 16, scope: !7)
64!22 = !DILocalVariable(name: "b", scope: !7, file: !1, line: 1, type: !10)
65!1000 = !{i32 7, !"debug-info-assignment-tracking", i1 true}
66