xref: /llvm-project/llvm/test/DebugInfo/COFF/register-variables.ll (revision 5a288fa32e0c91b211e39f3e370255916902f898)
1; RUN: llc < %s -experimental-debug-variable-locations=true | FileCheck %s --check-prefix=ASM
2; RUN: llc < %s -filetype=obj -experimental-debug-variable-locations=true | llvm-readobj --codeview - | FileCheck %s --check-prefix=OBJ
3
4; Generated from:
5; volatile int x;
6; int getint(void);
7; void putint(int);
8; static inline int inlineinc(int a) {
9;   int b = a + 1;
10;   ++x;
11;   return b;
12; }
13; void f(int p) {
14;   if (p) {
15;     int a = getint();
16;     int b = inlineinc(a);
17;     putint(b);
18;   } else {
19;     int c = getint();
20;     putint(c);
21;   }
22; }
23
24; ASM: f:                                      # @f
25; ASM: .Lfunc_begin0:
26; ASM: # %bb.0:                                 # %entry
27; ASM:         #DEBUG_VALUE: f:p <- $ecx
28; ASM:         pushq   %rsi
29; ASM:         subq    $32, %rsp
30; ASM:         movl    %ecx, %esi
31; ASM: [[p_ecx_esi:\.Ltmp.*]]:
32; ASM:         callq   getint
33; ASM: [[after_getint:\.Ltmp.*]]:
34; ASM:         testl   %esi, %esi
35; ASM:         je      .LBB0_2
36; ASM: [[after_je:\.Ltmp.*]]:
37; ASM: # %bb.1:                                 # %if.then
38; ASM-DAG:     #DEBUG_VALUE: inlineinc:a <- $eax
39; ASM-DAG:     #DEBUG_VALUE: a <- $eax
40; ASM-DAG:     #DEBUG_VALUE: f:p <- $esi
41; ASM:         addl    $1, %eax
42; ASM: [[after_inc_eax:\.Ltmp.*]]:
43; ASM:         #DEBUG_VALUE: inlineinc:b <- $eax
44; ASM:         addl    $1, x(%rip)
45; ASM: [[after_if:\.Ltmp.*]]:
46; ASM: .LBB0_2:                                # %if.else
47; ASM:         #DEBUG_VALUE: f:p <- $esi
48;; FIXME: tail-merging causes the location of "c" to be dropped in instruction
49;; referencing mode.
50; ASM:         #DEBUG_VALUE: c <- undef
51; ASM:         movl    %eax, %ecx
52; ASM:         addq    $32, %rsp
53; ASM:         popq    %rsi
54; ASM: [[func_end:\.Ltmp.*]]:
55; ASM:         jmp     putint                  # TAILCALL
56; ASM: [[func_finished:\.Ltmp.*]]:
57
58; ASM:         .short  4414                    # Record kind: S_LOCAL
59; ASM:         .asciz  "p"
60; ASM:         .cv_def_range    .Lfunc_begin0 [[after_getint]], reg, 18
61; ASM:         .cv_def_range    [[after_getint]] [[func_end]], reg, 23
62; ASM:         .short  4414                    # Record kind: S_LOCAL
63; ASM:         .asciz  "c"
64; ASM:         .short  4414                    # Record kind: S_LOCAL
65; ASM:         .asciz  "a"
66; ASM:         .cv_def_range    [[after_je]] [[after_inc_eax]], reg, 17
67; ASM:         .short  4414                    # Record kind: S_LOCAL
68; ASM:         .asciz  "b"
69
70; Note: "b" is a victim of tail de-duplication / branch folding.
71
72; ASM:         .short  4429                    # Record kind: S_INLINESITE
73; ASM:         .short  4414                    # Record kind: S_LOCAL
74; ASM:         .asciz  "a"
75; ASM:         .cv_def_range    [[after_je]] [[after_inc_eax]], reg, 17
76; ASM:         .short  4414                    # Record kind: S_LOCAL
77; ASM:         .asciz  "b"
78; ASM:         .cv_def_range    [[after_inc_eax]] [[after_if]], reg, 17
79; ASM:         .short  4430                    # Record kind: S_INLINESITE_END
80
81; OBJ: Subsection [
82; OBJ:   SubSectionType: Symbols (0xF1)
83; OBJ:   {{.*}}Proc{{.*}}Sym {
84; OBJ:     DisplayName: f
85; OBJ:   }
86; OBJ:   LocalSym {
87; OBJ:     Type: int (0x74)
88; OBJ:     Flags [ (0x1)
89; OBJ:       IsParameter (0x1)
90; OBJ:     ]
91; OBJ:     VarName: p
92; OBJ:   }
93; OBJ:   DefRangeRegisterSym {
94; OBJ:     Register: ECX (0x12)
95; OBJ:     LocalVariableAddrRange {
96; OBJ:       OffsetStart: .text+0x0
97; OBJ:       ISectStart: 0x0
98; OBJ:       Range: 0xC
99; OBJ:     }
100; OBJ:   }
101; OBJ:   DefRangeRegisterSym {
102; OBJ:     Register: ESI (0x17)
103; OBJ:     LocalVariableAddrRange {
104; OBJ:       OffsetStart: .text+0xC
105; OBJ:       ISectStart: 0x0
106; OBJ:       Range: 0x15
107; OBJ:     }
108; OBJ:   }
109; OBJ:   LocalSym {
110; OBJ:     Type: int (0x74)
111; OBJ:     Flags [ (0x100)
112; OBJ:       IsOptimizedOut (0x100)
113; OBJ:     ]
114; OBJ:     VarName: c
115; OBJ:   }
116; OBJ:   LocalSym {
117; OBJ:     Type: int (0x74)
118; OBJ:     Flags [ (0x0)
119; OBJ:     ]
120; OBJ:     VarName: a
121; OBJ:   }
122; OBJ:   DefRangeRegisterSym {
123; OBJ:     Register: EAX (0x11)
124; OBJ:     LocalVariableAddrRange {
125; OBJ:       OffsetStart: .text+0x10
126; OBJ:       ISectStart: 0x0
127; OBJ:       Range: 0x3
128; OBJ:     }
129; OBJ:   }
130; OBJ:   InlineSiteSym {
131; OBJ:     PtrParent: 0x0
132; OBJ:     PtrEnd: 0x0
133; OBJ:     Inlinee: inlineinc (0x1002)
134; OBJ:   }
135; OBJ:   LocalSym {
136; OBJ:     Type: int (0x74)
137; OBJ:     Flags [ (0x1)
138; OBJ:       IsParameter (0x1)
139; OBJ:     ]
140; OBJ:     VarName: a
141; OBJ:   }
142; OBJ:   DefRangeRegisterSym {
143; OBJ:     Register: EAX (0x11)
144; OBJ:     LocalVariableAddrRange {
145; OBJ:       OffsetStart: .text+0x10
146; OBJ:       ISectStart: 0x0
147; OBJ:       Range: 0x3
148; OBJ:     }
149; OBJ:   }
150; OBJ:   LocalSym {
151; OBJ:     Type: int (0x74)
152; OBJ:     Flags [ (0x0)
153; OBJ:     ]
154; OBJ:     VarName: b
155; OBJ:   }
156; OBJ:   DefRangeRegisterSym {
157; OBJ:     Register: EAX (0x11)
158; OBJ:     LocalVariableAddrRange {
159; OBJ:       OffsetStart: .text+0x13
160; OBJ:       ISectStart: 0x0
161; OBJ:       Range: 0x7
162; OBJ:     }
163; OBJ:   }
164; OBJ:   InlineSiteEnd {
165; OBJ:   }
166; OBJ:   ProcEnd
167; OBJ: ]
168
169; ModuleID = 't.cpp'
170source_filename = "test/DebugInfo/COFF/register-variables.ll"
171target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
172target triple = "x86_64-pc-windows-msvc18.0.0"
173
174@x = internal global i32 0, align 4, !dbg !0
175
176; Function Attrs: nounwind uwtable
177define void @f(i32 %p) #0 !dbg !12 {
178entry:
179  tail call void @llvm.dbg.value(metadata i32 %p, metadata !16, metadata !23), !dbg !24
180  %tobool = icmp eq i32 %p, 0, !dbg !25
181  %call2 = tail call i32 @getint() #3, !dbg !26
182  br i1 %tobool, label %if.else, label %if.then, !dbg !27
183
184if.then:                                          ; preds = %entry
185  tail call void @llvm.dbg.value(metadata i32 %call2, metadata !17, metadata !23), !dbg !28
186  tail call void @llvm.dbg.value(metadata i32 %call2, metadata !29, metadata !23), !dbg !35
187  %add.i = add nsw i32 %call2, 1, !dbg !37
188  tail call void @llvm.dbg.value(metadata i32 %add.i, metadata !34, metadata !23), !dbg !38
189  %0 = load volatile i32, ptr @x, align 4, !dbg !39, !tbaa !40
190  %inc.i = add nsw i32 %0, 1, !dbg !39
191  store volatile i32 %inc.i, ptr @x, align 4, !dbg !39, !tbaa !40
192  tail call void @llvm.dbg.value(metadata i32 %add.i, metadata !20, metadata !23), !dbg !44
193  tail call void @putint(i32 %add.i) #3, !dbg !45
194  br label %if.end, !dbg !46
195
196if.else:                                          ; preds = %entry
197  tail call void @llvm.dbg.value(metadata i32 %call2, metadata !21, metadata !23), !dbg !47
198  tail call void @putint(i32 %call2) #3, !dbg !48
199  br label %if.end
200
201if.end:                                           ; preds = %if.else, %if.then
202  ret void, !dbg !49
203}
204
205declare i32 @getint() #1
206
207declare void @putint(i32) #1
208
209; Function Attrs: nounwind readnone
210declare void @llvm.dbg.value(metadata, metadata, metadata) #2
211
212attributes #0 = { nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "tune-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" }
213attributes #1 = { "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" }
214attributes #2 = { nounwind readnone }
215attributes #3 = { nounwind }
216
217!llvm.dbg.cu = !{!2}
218!llvm.module.flags = !{!8, !9, !10}
219!llvm.ident = !{!11}
220
221!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
222!1 = !DIGlobalVariable(name: "x", scope: !2, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true)
223!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 3.9.0 (trunk 260617) (llvm/trunk 260619)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5)
224!3 = !DIFile(filename: "t.cpp", directory: "D:\5Csrc\5Cllvm\5Cbuild")
225!4 = !{}
226!5 = !{!0}
227!6 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !7)
228!7 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
229!8 = !{i32 2, !"CodeView", i32 1}
230!9 = !{i32 2, !"Debug Info Version", i32 3}
231!10 = !{i32 1, !"PIC Level", i32 2}
232!11 = !{!"clang version 3.9.0 (trunk 260617) (llvm/trunk 260619)"}
233!12 = distinct !DISubprogram(name: "f", scope: !3, file: !3, line: 9, type: !13, isLocal: false, isDefinition: true, scopeLine: 9, flags: DIFlagPrototyped, isOptimized: true, unit: !2, retainedNodes: !15)
234!13 = !DISubroutineType(types: !14)
235!14 = !{null, !7}
236!15 = !{!16, !17, !20, !21}
237!16 = !DILocalVariable(name: "p", arg: 1, scope: !12, file: !3, line: 9, type: !7)
238!17 = !DILocalVariable(name: "a", scope: !18, file: !3, line: 11, type: !7)
239!18 = distinct !DILexicalBlock(scope: !19, file: !3, line: 10, column: 10)
240!19 = distinct !DILexicalBlock(scope: !12, file: !3, line: 10, column: 7)
241!20 = !DILocalVariable(name: "b", scope: !18, file: !3, line: 12, type: !7)
242!21 = !DILocalVariable(name: "c", scope: !22, file: !3, line: 15, type: !7)
243!22 = distinct !DILexicalBlock(scope: !19, file: !3, line: 14, column: 10)
244!23 = !DIExpression()
245!24 = !DILocation(line: 9, column: 12, scope: !12)
246!25 = !DILocation(line: 10, column: 7, scope: !19)
247!26 = !DILocation(line: 15, column: 13, scope: !22)
248!27 = !DILocation(line: 10, column: 7, scope: !12)
249!28 = !DILocation(line: 11, column: 9, scope: !18)
250!29 = !DILocalVariable(name: "a", arg: 1, scope: !30, file: !3, line: 4, type: !7)
251!30 = distinct !DISubprogram(name: "inlineinc", scope: !3, file: !3, line: 4, type: !31, isLocal: true, isDefinition: true, scopeLine: 4, flags: DIFlagPrototyped, isOptimized: true, unit: !2, retainedNodes: !33)
252!31 = !DISubroutineType(types: !32)
253!32 = !{!7, !7}
254!33 = !{!29, !34}
255!34 = !DILocalVariable(name: "b", scope: !30, file: !3, line: 5, type: !7)
256!35 = !DILocation(line: 4, column: 33, scope: !30, inlinedAt: !36)
257!36 = distinct !DILocation(line: 12, column: 13, scope: !18)
258!37 = !DILocation(line: 5, column: 13, scope: !30, inlinedAt: !36)
259!38 = !DILocation(line: 5, column: 7, scope: !30, inlinedAt: !36)
260!39 = !DILocation(line: 6, column: 3, scope: !30, inlinedAt: !36)
261!40 = !{!41, !41, i64 0}
262!41 = !{!"int", !42, i64 0}
263!42 = !{!"omnipotent char", !43, i64 0}
264!43 = !{!"Simple C/C++ TBAA"}
265!44 = !DILocation(line: 12, column: 9, scope: !18)
266!45 = !DILocation(line: 13, column: 5, scope: !18)
267!46 = !DILocation(line: 14, column: 3, scope: !18)
268!47 = !DILocation(line: 15, column: 9, scope: !22)
269!48 = !DILocation(line: 16, column: 5, scope: !22)
270!49 = !DILocation(line: 18, column: 1, scope: !12)
271
272