xref: /llvm-project/llvm/test/DebugInfo/COFF/local-variables.ll (revision 836703087d761f9cbf81b6f9593bc5313660f559)
1; RUN: llc -mtriple=x86_64-windows-msvc < %s | FileCheck %s --check-prefix=ASM
2; RUN: llc -mtriple=x86_64-windows-msvc < %s -filetype=obj | llvm-readobj --codeview - | FileCheck %s --check-prefix=OBJ
3
4; This LL file was generated by running 'clang -g -gcodeview' on the
5; following code:
6;  1: extern "C" volatile int x;
7;  2: extern "C" void capture(int *p);
8;  3: static __forceinline inline void will_be_inlined() {
9;  4:   int v = 3;
10;  5:   capture(&v);
11;  6: }
12;  7: extern "C" void f(int param) {
13;  8:   if (param) {
14;  9:     int a = 42;
15; 10:     will_be_inlined();
16; 11:     capture(&a);
17; 12:   } else {
18; 13:     int b = 42;
19; 14:     will_be_inlined();
20; 15:     capture(&b);
21; 16:   }
22; 17: }
23
24; ASM: f:                                      # @f
25; ASM:         .cv_func_id 0
26; ASM:         .cv_file        1 "D:\\src\\llvm\\build\\t.cpp"
27; ASM:         .cv_loc 0 1 7 0       # t.cpp:7:0
28; ASM: .seh_proc f
29; ASM: # %bb.0:                                 # %entry
30; ASM:         subq    $56, %rsp
31; ASM:         movl    %ecx, 52(%rsp)
32; ASM: [[prologue_end:\.Ltmp.*]]:
33; ASM:         .cv_loc 0 1 8 7                 # t.cpp:8:7
34; ASM:         testl   %ecx, %ecx
35; ASM:         je      .LBB0_2
36; ASM: # %bb.1:                                 # %if.then
37; ASM: [[if_start:\.Ltmp.*]]:
38; ASM:         .cv_loc 0 1 9 9                 # t.cpp:9:9
39; ASM:         movl    $42, 40(%rsp)
40; ASM: [[inline_site1:\.Ltmp.*]]:
41; ASM:         .cv_inline_site_id 1 within 0 inlined_at 1 10 5
42; ASM:         .cv_loc 1 1 4 7                 # t.cpp:4:7
43; ASM:         movl    $3, 44(%rsp)
44; ASM:         leaq    44(%rsp), %rcx
45; ASM:         .cv_loc 1 1 5 3                 # t.cpp:5:3
46; ASM:         callq   capture
47; ASM:         leaq    40(%rsp), %rcx
48; ASM: [[end_inline_1:\.Ltmp.*]]:
49; ASM:         .cv_loc 0 1 11 5                # t.cpp:11:5
50; ASM:         jmp     .LBB0_3
51; ASM: [[else_start:\.Ltmp.*]]:
52; ASM: .LBB0_2:                                # %if.else
53; ASM:         .cv_loc 0 1 13 9                # t.cpp:13:9
54; ASM:         movl    $42, 36(%rsp)
55; ASM: [[inline_site2:\.Ltmp.*]]:
56; ASM:         .cv_inline_site_id 2 within 0 inlined_at 1 14 5
57; ASM:         .cv_loc 2 1 4 7                 # t.cpp:4:7
58; ASM:         movl    $3, 48(%rsp)
59; ASM:         leaq    48(%rsp), %rcx
60; ASM:         .cv_loc 2 1 5 3                 # t.cpp:5:3
61; ASM:         callq   capture
62; ASM:         leaq    36(%rsp), %rcx
63; ASM: [[else_end:\.Ltmp.*]]:
64; ASM: .LBB0_3:                                # %if.end
65; ASM:         .cv_loc 0 1 17 1                # t.cpp:17:1
66; ASM:         callq   capture
67; ASM:         nop
68; ASM:         addq    $56, %rsp
69; ASM:         retq
70; ASM: [[param_end:\.Ltmp.*]]:
71
72; ASM: .short  4414                    # Record kind: S_LOCAL
73; ASM: .long   116                     # TypeIndex
74; ASM: .short  1                       # Flags
75; ASM: .asciz  "param"
76; ASM: .cv_def_range    [[prologue_end]] [[param_end]], frame_ptr_rel, 52
77; ASM: .short  4414                    # Record kind: S_LOCAL
78; ASM: .long   116                     # TypeIndex
79; ASM: .short  0                       # Flags
80; ASM: .asciz  "a"
81; ASM: .cv_def_range    [[if_start]] [[else_start]], frame_ptr_rel, 40
82; ASM: .short  4414                    # Record kind: S_LOCAL
83; ASM: .long   116                     # TypeIndex
84; ASM: .short  0                       # Flags
85; ASM: .asciz  "b"
86; ASM: .cv_def_range    [[else_start]] [[else_end]], frame_ptr_rel, 36
87; ASM: .short  4429                    # Record kind: S_INLINESITE
88; ASM: .short  4414                    # Record kind: S_LOCAL
89; ASM: .long   116                     # TypeIndex
90; ASM: .short  0                       # Flags
91; ASM: .asciz  "v"
92; ASM: .cv_def_range    [[inline_site1]] [[end_inline_1]], frame_ptr_rel, 44
93; ASM: .short  4430                    # Record kind: S_INLINESITE_END
94; ASM: .short  4429                    # Record kind: S_INLINESITE
95; ASM: .short  4414                    # Record kind: S_LOCAL
96; ASM: .long   116                     # TypeIndex
97; ASM: .short  0                       # Flags
98; ASM: .asciz  "v"
99; ASM: .cv_def_range    [[inline_site2]] [[else_end]], frame_ptr_rel, 48
100; ASM: .short  4430                    # Record kind: S_INLINESITE_END
101
102; OBJ:  Subsection [
103; OBJ:    SubSectionType: Symbols (0xF1)
104; OBJ:    {{.*}}Proc{{.*}}Sym {
105; OBJ:      DisplayName: f
106; OBJ:      LinkageName: f
107; OBJ:    }
108; OBJ:    LocalSym {
109; OBJ:      Type: int (0x74)
110; OBJ:      Flags [ (0x1)
111; OBJ:        IsParameter (0x1)
112; OBJ:      ]
113; OBJ:      VarName: param
114; OBJ:    }
115; OBJ:    DefRangeFramePointerRelSym {
116; OBJ:      Offset: 52
117; OBJ:      LocalVariableAddrRange {
118; OBJ:        OffsetStart: .text+0x8
119; OBJ:        ISectStart: 0x0
120; OBJ:        Range: 0x4F
121; OBJ:      }
122; OBJ:    }
123; OBJ:    LocalSym {
124; OBJ:      Type: int (0x74)
125; OBJ:      Flags [ (0x0)
126; OBJ:      ]
127; OBJ:      VarName: a
128; OBJ:    }
129; OBJ:    DefRangeFramePointerRelSym {
130; OBJ:      Offset: 40
131; OBJ:      LocalVariableAddrRange {
132; OBJ:        OffsetStart: .text+0xC
133; OBJ:        ISectStart: 0x0
134; OBJ:        Range: 0x21
135; OBJ:      }
136; OBJ:    }
137; OBJ:    LocalSym {
138; OBJ:      Type: int (0x74)
139; OBJ:      Flags [ (0x0)
140; OBJ:      ]
141; OBJ:      VarName: b
142; OBJ:    }
143; OBJ:    DefRangeFramePointerRelSym {
144; OBJ:      Offset: 36
145; OBJ:      LocalVariableAddrRange {
146; OBJ:        OffsetStart: .text+0x2D
147; OBJ:        ISectStart: 0x0
148; OBJ:        Range: 0x1F
149; OBJ:      }
150; OBJ:    }
151; OBJ:    InlineSiteSym {
152; OBJ:      PtrParent: 0x0
153; OBJ:      PtrEnd: 0x0
154; OBJ:      Inlinee: will_be_inlined (0x1002)
155; OBJ:      BinaryAnnotations [
156; OBJ:        ChangeLineOffset: 1
157; OBJ:        ChangeCodeOffset: 0x14
158; OBJ:        ChangeCodeOffsetAndLineOffset: {CodeOffset: 0xD, LineOffset: 1}
159; OBJ:        ChangeCodeLength: 0xA
160; OBJ:      ]
161; OBJ:    }
162; OBJ:    LocalSym {
163; OBJ:      Type: int (0x74)
164; OBJ:      Flags [ (0x0)
165; OBJ:      ]
166; OBJ:      VarName: v
167; OBJ:    }
168; OBJ:    DefRangeFramePointerRelSym {
169; OBJ:      Offset: 44
170; OBJ:      LocalVariableAddrRange {
171; OBJ:        OffsetStart: .text+0x14
172; OBJ:        ISectStart: 0x0
173; OBJ:        Range: 0x17
174; OBJ:      }
175; OBJ:    }
176; OBJ:    InlineSiteEnd {
177; OBJ:    }
178; OBJ:    InlineSiteSym {
179; OBJ:      PtrParent: 0x0
180; OBJ:      PtrEnd: 0x0
181; OBJ:      Inlinee: will_be_inlined (0x1002)
182; OBJ:      BinaryAnnotations [
183; OBJ:        ChangeLineOffset: 1
184; OBJ:        ChangeCodeOffset: 0x35
185; OBJ:        ChangeCodeOffsetAndLineOffset: {CodeOffset: 0xD, LineOffset: 1}
186; OBJ:        ChangeCodeLength: 0xA
187; OBJ:      ]
188; OBJ:    }
189; OBJ:    LocalSym {
190; OBJ:      Type: int (0x74)
191; OBJ:      Flags [ (0x0)
192; OBJ:      ]
193; OBJ:      VarName: v
194; OBJ:    }
195; OBJ:    DefRangeFramePointerRelSym {
196; OBJ:      Offset: 48
197; OBJ:      LocalVariableAddrRange {
198; OBJ:        OffsetStart: .text+0x35
199; OBJ:        ISectStart: 0x0
200; OBJ:        Range: 0x17
201; OBJ:      }
202; OBJ:    }
203; OBJ:    InlineSiteEnd {
204; OBJ:    }
205; OBJ:    ProcEnd
206; OBJ:  ]
207
208; ModuleID = 't.cpp'
209target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
210target triple = "x86_64-pc-windows-msvc18.0.0"
211
212; Function Attrs: nounwind uwtable
213define void @f(i32 %param) #0 !dbg !4 {
214entry:
215  %v.i1 = alloca i32, align 4
216  call void @llvm.dbg.declare(metadata ptr %v.i1, metadata !15, metadata !16), !dbg !17
217  %v.i = alloca i32, align 4
218  call void @llvm.dbg.declare(metadata ptr %v.i, metadata !15, metadata !16), !dbg !21
219  %param.addr = alloca i32, align 4
220  %a = alloca i32, align 4
221  %b = alloca i32, align 4
222  store i32 %param, ptr %param.addr, align 4
223  call void @llvm.dbg.declare(metadata ptr %param.addr, metadata !24, metadata !16), !dbg !25
224  %0 = load i32, ptr %param.addr, align 4, !dbg !26
225  %tobool = icmp ne i32 %0, 0, !dbg !26
226  br i1 %tobool, label %if.then, label %if.else, !dbg !27
227
228if.then:                                          ; preds = %entry
229  call void @llvm.dbg.declare(metadata ptr %a, metadata !28, metadata !16), !dbg !29
230  store i32 42, ptr %a, align 4, !dbg !29
231  store i32 3, ptr %v.i, align 4, !dbg !21
232  call void @capture(ptr %v.i) #3, !dbg !30
233  call void @capture(ptr %a), !dbg !31
234  br label %if.end, !dbg !32
235
236if.else:                                          ; preds = %entry
237  call void @llvm.dbg.declare(metadata ptr %b, metadata !33, metadata !16), !dbg !34
238  store i32 42, ptr %b, align 4, !dbg !34
239  store i32 3, ptr %v.i1, align 4, !dbg !17
240  call void @capture(ptr %v.i1) #3, !dbg !35
241  call void @capture(ptr %b), !dbg !36
242  br label %if.end
243
244if.end:                                           ; preds = %if.else, %if.then
245  ret void, !dbg !37
246}
247
248; Function Attrs: nounwind readnone
249declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
250
251declare void @capture(ptr) #2
252
253attributes #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" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" }
254attributes #1 = { nounwind readnone }
255attributes #2 = { "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" }
256attributes #3 = { nounwind }
257
258!llvm.dbg.cu = !{!0}
259!llvm.module.flags = !{!11, !12, !13}
260!llvm.ident = !{!14}
261
262!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.9.0 ", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
263!1 = !DIFile(filename: "t.cpp", directory: "D:\5Csrc\5Cllvm\5Cbuild")
264!2 = !{}
265!4 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 7, type: !5, isLocal: false, isDefinition: true, scopeLine: 7, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
266!5 = !DISubroutineType(types: !6)
267!6 = !{null, !7}
268!7 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
269!8 = distinct !DISubprogram(name: "will_be_inlined", linkageName: "\01?will_be_inlined@@YAXXZ", scope: !1, file: !1, line: 3, type: !9, isLocal: true, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
270!9 = !DISubroutineType(types: !10)
271!10 = !{null}
272!11 = !{i32 2, !"CodeView", i32 1}
273!12 = !{i32 2, !"Debug Info Version", i32 3}
274!13 = !{i32 1, !"PIC Level", i32 2}
275!14 = !{!"clang version 3.9.0 "}
276!15 = !DILocalVariable(name: "v", scope: !8, file: !1, line: 4, type: !7)
277!16 = !DIExpression()
278!17 = !DILocation(line: 4, column: 7, scope: !8, inlinedAt: !18)
279!18 = distinct !DILocation(line: 14, column: 5, scope: !19)
280!19 = distinct !DILexicalBlock(scope: !20, file: !1, line: 12, column: 10)
281!20 = distinct !DILexicalBlock(scope: !4, file: !1, line: 8, column: 7)
282!21 = !DILocation(line: 4, column: 7, scope: !8, inlinedAt: !22)
283!22 = distinct !DILocation(line: 10, column: 5, scope: !23)
284!23 = distinct !DILexicalBlock(scope: !20, file: !1, line: 8, column: 14)
285!24 = !DILocalVariable(name: "param", arg: 1, scope: !4, file: !1, line: 7, type: !7)
286!25 = !DILocation(line: 7, column: 23, scope: !4)
287!26 = !DILocation(line: 8, column: 7, scope: !20)
288!27 = !DILocation(line: 8, column: 7, scope: !4)
289!28 = !DILocalVariable(name: "a", scope: !23, file: !1, line: 9, type: !7)
290!29 = !DILocation(line: 9, column: 9, scope: !23)
291!30 = !DILocation(line: 5, column: 3, scope: !8, inlinedAt: !22)
292!31 = !DILocation(line: 11, column: 5, scope: !23)
293!32 = !DILocation(line: 12, column: 3, scope: !23)
294!33 = !DILocalVariable(name: "b", scope: !19, file: !1, line: 13, type: !7)
295!34 = !DILocation(line: 13, column: 9, scope: !19)
296!35 = !DILocation(line: 5, column: 3, scope: !8, inlinedAt: !18)
297!36 = !DILocation(line: 15, column: 5, scope: !19)
298!37 = !DILocation(line: 17, column: 1, scope: !4)
299