xref: /llvm-project/llvm/test/DebugInfo/X86/dbg-declare-inalloca.ll (revision 10b03e66629aedad79a804e22d23b575077303b3)
1; RUN: llc -O0 < %s | FileCheck %s --check-prefix=CHECK --check-prefix=DEBUG
2; RUN: llc < %s | FileCheck %s
3; RUN: llc -filetype=obj -O0 < %s | llvm-readobj --codeview - | FileCheck %s --check-prefix=OBJ
4
5; Same checks, this time with experimental debuginfo iterators.
6; RUN: llc --try-experimental-debuginfo-iterators -O0 < %s | FileCheck %s --check-prefix=CHECK --check-prefix=DEBUG
7; RUN: llc --try-experimental-debuginfo-iterators < %s | FileCheck %s
8; RUN: llc --try-experimental-debuginfo-iterators -filetype=obj -O0 < %s | llvm-readobj --codeview - | FileCheck %s --check-prefix=OBJ
9
10; IR generated by the following source:
11; struct NonTrivial {
12;   NonTrivial();// : x(42) {}
13;   ~NonTrivial();// {}
14;   int x;
15; };
16; extern "C" void g(int);// {}
17; extern "C" void h(int);// {}
18; extern "C" void f(NonTrivial a, int b, int unused, int c) {
19;   if (b) {
20;     g(c);
21;   } else {
22;     h(a.x);
23;   }
24;   (void)unused;
25; }
26; //int main() {
27; //  NonTrivial x;
28; //  f(x, 1, 2, 3);
29; //}
30;
31; Remove C++ comments to have a complete, debuggable program.
32
33; We don't need (or want) DBG_VALUE instructions to describe the location of
34; inalloca arguments. We want frame indices in the side table, especially at
35; -O0, because they are reliable across the entire function and don't require
36; any propagation or analysis.
37
38; CHECK: _f:                                     # @f
39; CHECK: Lfunc_begin0:
40; CHECK-NOT: DEBUG_VALUE
41; CHECK: [[start:Ltmp[0-9]+]]:
42; CHECK-NOT: DEBUG_VALUE
43; CHECK:         cmpl
44; CHECK:         calll   _g
45; CHECK:         calll   _h
46; CHECK:         jmp "??1NonTrivial@@QAE@XZ"
47; CHECK: [[end:Ltmp[0-9]+]]:
48; CHECK: Lfunc_end0:
49
50; FIXME: Optimized debug info should preserve this.
51; DEBUG:         .short  4414                    # Record kind: S_LOCAL
52; DEBUG:         .asciz  "a"
53; DEBUG:         .cv_def_range    [[start]] [[end]]
54
55; CHECK:         .short  4414                    # Record kind: S_LOCAL
56; CHECK:         .asciz  "b"
57; CHECK:         .cv_def_range    [[start]] [[end]]
58
59; CHECK:         .short  4414                    # Record kind: S_LOCAL
60; CHECK:         .asciz  "c"
61; CHECK:         .cv_def_range    [[start]] [[end]]
62
63; OBJ-LABEL: {{.*}}Proc{{.*}}Sym {
64; OBJ:   Kind: S_GPROC32_ID (0x1147)
65; OBJ:   DisplayName: f
66; OBJ: }
67; OBJ: FrameProcSym {
68; OBJ:   Kind: S_FRAMEPROC (0x1012)
69; OBJ:   TotalFrameBytes: 0x8
70; OBJ:   LocalFramePtrReg: VFRAME (0x7536)
71; OBJ:   ParamFramePtrReg: VFRAME (0x7536)
72; OBJ: }
73; OBJ: LocalSym {
74; OBJ:   Kind: S_LOCAL (0x113E)
75; OBJ:   Type: NonTrivial (0x{{.*}})
76; OBJ:   Flags [ (0x1)
77; OBJ:     IsParameter (0x1)
78; OBJ:   ]
79; OBJ:   VarName: a
80; OBJ: }
81; OBJ: DefRangeFramePointerRelSym {
82; OBJ:   Offset: 4
83; OBJ: }
84; OBJ: LocalSym {
85; OBJ:   Type: int (0x74)
86; OBJ:   Flags [ (0x1)
87; OBJ:     IsParameter (0x1)
88; OBJ:   ]
89; OBJ:   VarName: b
90; OBJ: }
91; OBJ: DefRangeFramePointerRelSym {
92; OBJ:   Offset: 8
93; OBJ: }
94; FIXME: Retain unused.
95; OBJ: LocalSym {
96; OBJ:   Type: int (0x74)
97; OBJ:   Flags [ (0x1)
98; OBJ:     IsParameter (0x1)
99; OBJ:   ]
100; OBJ:   VarName: c
101; OBJ: }
102; OBJ: DefRangeFramePointerRelSym {
103; OBJ:   Offset: 16
104; OBJ: }
105; OBJ-LABEL: ProcEnd {
106; OBJ: }
107
108
109; ModuleID = 't.cpp'
110source_filename = "t.cpp"
111target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
112target triple = "i386-pc-windows-msvc19.10.24728"
113
114%struct.NonTrivial = type { i32 }
115
116; Function Attrs: nounwind
117define void @f(ptr inalloca(<{ %struct.NonTrivial, i32, i32, i32 }>)) local_unnamed_addr #0 !dbg !7 {
118entry:
119  %a = getelementptr inbounds <{ %struct.NonTrivial, i32, i32, i32 }>, ptr %0, i32 0, i32 0
120  %b = getelementptr inbounds <{ %struct.NonTrivial, i32, i32, i32 }>, ptr %0, i32 0, i32 1
121  call void @llvm.dbg.declare(metadata ptr %b, metadata !22, metadata !24), !dbg !26
122  call void @llvm.dbg.declare(metadata ptr %a, metadata !23, metadata !24), !dbg !27
123  %1 = load i32, ptr %b, align 4, !dbg !28, !tbaa !30
124  %tobool = icmp eq i32 %1, 0, !dbg !28
125  br i1 %tobool, label %if.else, label %if.then, !dbg !34
126
127if.then:                                          ; preds = %entry
128  %c = getelementptr inbounds <{ %struct.NonTrivial, i32, i32, i32 }>, ptr %0, i32 0, i32 3
129  call void @llvm.dbg.declare(metadata ptr %c, metadata !20, metadata !24), !dbg !25
130  %2 = load i32, ptr %c, align 4, !dbg !35, !tbaa !30
131  tail call void @g(i32 %2) #4, !dbg !37
132  br label %if.end, !dbg !38
133
134if.else:                                          ; preds = %entry
135  %x = getelementptr inbounds <{ %struct.NonTrivial, i32, i32, i32 }>, ptr %0, i32 0, i32 0, i32 0, !dbg !39
136  %3 = load i32, ptr %x, align 4, !dbg !39, !tbaa !41
137  tail call void @h(i32 %3) #4, !dbg !43
138  br label %if.end
139
140if.end:                                           ; preds = %if.else, %if.then
141  tail call x86_thiscallcc void @"\01??1NonTrivial@@QAE@XZ"(ptr nonnull %a) #4, !dbg !44
142  ret void, !dbg !44
143}
144
145; Function Attrs: nounwind readnone speculatable
146declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
147
148declare void @g(i32) local_unnamed_addr
149
150declare void @h(i32) local_unnamed_addr
151
152; Function Attrs: nounwind
153declare x86_thiscallcc void @"\01??1NonTrivial@@QAE@XZ"(ptr) unnamed_addr #3
154
155attributes #0 = { nounwind }
156attributes #1 = { nounwind readnone speculatable }
157attributes #3 = { nounwind }
158attributes #4 = { nounwind }
159
160!llvm.dbg.cu = !{!0}
161!llvm.module.flags = !{!3, !4, !5}
162!llvm.ident = !{!6}
163
164!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 5.0.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
165!1 = !DIFile(filename: "t.cpp", directory: "C:\5Csrc\5Cllvm-project\5Cbuild", checksumkind: CSK_MD5, checksum: "e41e3fda2a91b52e121ed6c29a209eae")
166!2 = !{}
167!3 = !{i32 1, !"NumRegisterParameters", i32 0}
168!4 = !{i32 2, !"CodeView", i32 1}
169!5 = !{i32 2, !"Debug Info Version", i32 3}
170!6 = !{!"clang version 5.0.0 "}
171!7 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 8, type: !8, isLocal: false, isDefinition: true, scopeLine: 8, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !19)
172!8 = !DISubroutineType(types: !9)
173!9 = !{null, !10, !13, !13, !13}
174!10 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "NonTrivial", file: !1, line: 1, size: 32, elements: !11, identifier: ".?AUNonTrivial@@")
175!11 = !{!12, !14, !18}
176!12 = !DIDerivedType(tag: DW_TAG_member, name: "x", scope: !10, file: !1, line: 4, baseType: !13, size: 32)
177!13 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
178!14 = !DISubprogram(name: "NonTrivial", scope: !10, file: !1, line: 2, type: !15, isLocal: false, isDefinition: false, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: true)
179!15 = !DISubroutineType(cc: DW_CC_BORLAND_thiscall, types: !16)
180!16 = !{null, !17}
181!17 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !10, size: 32, flags: DIFlagArtificial | DIFlagObjectPointer)
182!18 = !DISubprogram(name: "~NonTrivial", scope: !10, file: !1, line: 3, type: !15, isLocal: false, isDefinition: false, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: true)
183!19 = !{!20, !21, !22, !23}
184!20 = !DILocalVariable(name: "c", arg: 4, scope: !7, file: !1, line: 8, type: !13)
185!21 = !DILocalVariable(name: "unused", arg: 3, scope: !7, file: !1, line: 8, type: !13)
186!22 = !DILocalVariable(name: "b", arg: 2, scope: !7, file: !1, line: 8, type: !13)
187!23 = !DILocalVariable(name: "a", arg: 1, scope: !7, file: !1, line: 8, type: !10)
188!24 = !DIExpression()
189!25 = !DILocation(line: 8, column: 56, scope: !7)
190!26 = !DILocation(line: 8, column: 37, scope: !7)
191!27 = !DILocation(line: 8, column: 30, scope: !7)
192!28 = !DILocation(line: 9, column: 7, scope: !29)
193!29 = distinct !DILexicalBlock(scope: !7, file: !1, line: 9, column: 7)
194!30 = !{!31, !31, i64 0}
195!31 = !{!"int", !32, i64 0}
196!32 = !{!"omnipotent char", !33, i64 0}
197!33 = !{!"Simple C++ TBAA"}
198!34 = !DILocation(line: 9, column: 7, scope: !7)
199!35 = !DILocation(line: 10, column: 7, scope: !36)
200!36 = distinct !DILexicalBlock(scope: !29, file: !1, line: 9, column: 10)
201!37 = !DILocation(line: 10, column: 5, scope: !36)
202!38 = !DILocation(line: 11, column: 3, scope: !36)
203!39 = !DILocation(line: 12, column: 9, scope: !40)
204!40 = distinct !DILexicalBlock(scope: !29, file: !1, line: 11, column: 10)
205!41 = !{!42, !31, i64 0}
206!42 = !{!"?AUNonTrivial@@", !31, i64 0}
207!43 = !DILocation(line: 12, column: 5, scope: !40)
208!44 = !DILocation(line: 15, column: 1, scope: !7)
209