]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/DebugInfo/COFF/vframe-fpo.ll
Vendor import of llvm trunk r351319 (just before the release_80 branch
[FreeBSD/FreeBSD.git] / test / DebugInfo / COFF / vframe-fpo.ll
1 ; RUN: llc < %s | FileCheck %s --check-prefix=ASM
2 ; RUN: llc < %s -filetype=obj | llvm-readobj -codeview | FileCheck %s --check-prefix=CODEVIEW
3
4 ; This test checks that for 32-bit x86 we use VFRAME and
5 ; S_DEFRANGE_FRAMEPOINTER_REL with the right offsets. The test has two function
6 ; calls with different stack depths, which makes it impossible to correctly
7 ; describe locals in memory as being ESP-relative.
8
9 ; The following source can be used with a debugger to check that locals are
10 ; displayed correctly:
11 ; $ cat fpo.cpp
12 ; #if 0
13 ; void __attribute__((optnone)) __declspec(noinline) f(int &a, int &b) {
14 ;   __debugbreak();
15 ;   a += b;
16 ; }
17 ; void __attribute__((optnone)) __declspec(noinline) g(int &a, int &b, int &c) {
18 ;   __debugbreak();
19 ;   a += b;
20 ;   a += c;
21 ; }
22 ; #endif
23 ; void f(int &a, int &b);
24 ; void g(int &a, int &b, int &c);
25 ; int main() {
26 ;   int a = 1;
27 ;   int b = 2;
28 ;   int c = 3;
29 ;   f(a, b);
30 ;   g(a, b, c);
31 ;   return a + b + c;
32 ; }
33 ; $ clang -S -g -gcodeview t.cpp -emit-llvm -o vframe-fpo.ll -Os
34
35 ; ASM-LABEL: _main:
36 ; ASM:      # %bb.0:                                # %entry
37 ; ASM-NEXT:         pushl   %ebx
38 ; ASM-NEXT:         .cv_fpo_pushreg %ebx
39 ; ASM-NEXT:         pushl   %edi
40 ; ASM-NEXT:         .cv_fpo_pushreg %edi
41 ; ASM-NEXT:         pushl   %esi
42 ; ASM-NEXT:         .cv_fpo_pushreg %esi
43 ; ASM-NEXT:         subl    $12, %esp
44 ; ASM-NEXT:         .cv_fpo_stackalloc      12
45 ; ASM-NEXT:         .cv_fpo_endprologue
46
47 ; Store locals.
48 ; ASM:         movl    $1, {{.*}}
49 ; ASM:         movl    $2, {{.*}}
50 ; ASM:         movl    $3, {{.*}}
51
52 ; ASM that store-to-push conversion fires.
53 ; ASM:         pushl
54 ; ASM-NEXT:    pushl
55 ; ASM-NEXT:    calll   "?f@@YAXAAH0@Z"
56 ; ASM-NEXT:    addl    $8, %esp
57 ; ASM:         pushl
58 ; ASM-NEXT:    pushl
59 ; ASM-NEXT:    pushl
60 ; ASM-NEXT:    calll   "?g@@YAXAAH00@Z"
61
62 ; CODEVIEW:      CodeViewDebugInfo [
63 ; CODEVIEW-NEXT:   Section: .debug$S (4)
64 ; CODEVIEW-NEXT:   Magic: 0x4
65 ; CODEVIEW-NEXT:   Subsection [
66 ; CODEVIEW-NEXT:     SubSectionType: Symbols (0xF1)
67 ; CODEVIEW-NEXT:     SubSectionSize:
68 ; CODEVIEW-NEXT:     Compile3Sym {
69 ; CODEVIEW-NEXT:       Kind: S_COMPILE3 (0x113C)
70 ; CODEVIEW:          }
71 ; CODEVIEW:        ]
72 ; CODEVIEW:        Subsection [
73 ; CODEVIEW-NEXT:     SubSectionType: FrameData (0xF5)
74 ; CODEVIEW-NEXT:     SubSectionSize:
75 ; CODEVIEW-NEXT:     LinkageName: _main
76 ; CODEVIEW:          FrameData {
77 ; CODEVIEW:          }
78 ; CODEVIEW:          FrameData {
79 ; CODEVIEW:          }
80 ; CODEVIEW:          FrameData {
81 ; CODEVIEW:          }
82 ; CODEVIEW:          FrameData {
83 ; CODEVIEW:          }
84 ; CODEVIEW:          FrameData {
85 ; CODEVIEW-NEXT:       RvaStart:
86 ; CODEVIEW-NEXT:       CodeSize:
87 ; CODEVIEW-NEXT:       LocalSize: 0xC
88 ; CODEVIEW-NEXT:       ParamsSize: 0x0
89 ; CODEVIEW-NEXT:       MaxStackSize: 0x0
90 ; CODEVIEW-NEXT:       PrologSize:
91 ; CODEVIEW-NEXT:       SavedRegsSize: 0xC
92 ; CODEVIEW-NEXT:       Flags [ (0x0)
93 ; CODEVIEW-NEXT:       ]
94
95 ; $T0 is the CFA, the address of the return address, and our defranges are
96 ; relative to it.
97 ; CODEVIEW-NEXT:       FrameFunc [
98 ; CODEVIEW-NEXT:         $T0 .raSearch =
99 ; CODEVIEW-NEXT:         $eip $T0 ^ =
100 ; CODEVIEW-NEXT:         $esp $T0 4 + =
101 ; CODEVIEW-NEXT:         $ebx $T0 4 - ^ =
102 ; CODEVIEW-NEXT:         $edi $T0 8 - ^ =
103 ; CODEVIEW-NEXT:         $esi $T0 12 - ^ =
104 ; CODEVIEW-NEXT:       ]
105 ; CODEVIEW-NEXT:     }
106
107 ; We push 16 bytes in the prologue, so our local variables are at offsets -16,
108 ; -20, and -24.
109
110 ; CODEVIEW:      Subsection [
111 ; CODEVIEW-NEXT:   SubSectionType: Symbols (0xF1)
112 ; CODEVIEW-NEXT:   SubSectionSize:
113 ; CODEVIEW-NEXT:   GlobalProcIdSym {
114 ; CODEVIEW-NEXT:     Kind: S_GPROC32_ID (0x1147)
115 ; CODEVIEW:          DisplayName: main
116 ; CODEVIEW:          LinkageName: _main
117 ; CODEVIEW-NEXT:   }
118 ; CODEVIEW-NEXT:   FrameProcSym {
119 ; CODEVIEW-NEXT:     Kind: S_FRAMEPROC (0x1012)
120 ; CODEVIEW-NEXT:     TotalFrameBytes: 0xC
121 ; CODEVIEW-NEXT:     PaddingFrameBytes: 0x0
122 ; CODEVIEW-NEXT:     OffsetToPadding: 0x0
123 ; CODEVIEW-NEXT:     BytesOfCalleeSavedRegisters: 0xC
124 ; CODEVIEW-NEXT:     OffsetOfExceptionHandler: 0x0
125 ; CODEVIEW-NEXT:     SectionIdOfExceptionHandler: 0x0
126 ; CODEVIEW-NEXT:     Flags [ (0x14000)
127 ; CODEVIEW-NEXT:     ]
128 ; CODEVIEW-NEXT:     LocalFramePtrReg: VFRAME (0x7536)
129 ; CODEVIEW-NEXT:     ParamFramePtrReg: VFRAME (0x7536)
130 ; CODEVIEW-NEXT:   }
131 ; CODEVIEW-NEXT:   LocalSym {
132 ; CODEVIEW-NEXT:     Kind: S_LOCAL (0x113E)
133 ; CODEVIEW:          VarName: a
134 ; CODEVIEW-NEXT:   }
135 ; CODEVIEW-NEXT:   DefRangeFramePointerRelSym {
136 ; CODEVIEW-NEXT:     Kind: S_DEFRANGE_FRAMEPOINTER_REL (0x1142)
137 ; CODEVIEW-NEXT:     Offset: -16
138 ; CODEVIEW-NEXT:     LocalVariableAddrRange {
139 ; CODEVIEW-NEXT:       OffsetStart:
140 ; CODEVIEW-NEXT:       ISectStart:
141 ; CODEVIEW-NEXT:       Range:
142 ; CODEVIEW-NEXT:     }
143 ; CODEVIEW-NEXT:   }
144 ; CODEVIEW-NEXT:   LocalSym {
145 ; CODEVIEW-NEXT:     Kind: S_LOCAL (0x113E)
146 ; CODEVIEW:          VarName: b
147 ; CODEVIEW-NEXT:   }
148 ; CODEVIEW-NEXT:   DefRangeFramePointerRelSym {
149 ; CODEVIEW-NEXT:     Kind: S_DEFRANGE_FRAMEPOINTER_REL (0x1142)
150 ; CODEVIEW-NEXT:     Offset: -20
151 ; CODEVIEW-NEXT:     LocalVariableAddrRange {
152 ; CODEVIEW-NEXT:       OffsetStart:
153 ; CODEVIEW-NEXT:       ISectStart:
154 ; CODEVIEW-NEXT:       Range:
155 ; CODEVIEW-NEXT:     }
156 ; CODEVIEW-NEXT:   }
157 ; CODEVIEW-NEXT:   LocalSym {
158 ; CODEVIEW-NEXT:     Kind: S_LOCAL (0x113E)
159 ; CODEVIEW:          VarName: c
160 ; CODEVIEW-NEXT:   }
161 ; CODEVIEW-NEXT:   DefRangeFramePointerRelSym {
162 ; CODEVIEW-NEXT:     Kind: S_DEFRANGE_FRAMEPOINTER_REL (0x1142)
163 ; CODEVIEW-NEXT:     Offset: -24
164 ; CODEVIEW-NEXT:     LocalVariableAddrRange {
165 ; CODEVIEW-NEXT:       OffsetStart:
166 ; CODEVIEW-NEXT:       ISectStart:
167 ; CODEVIEW-NEXT:       Range:
168 ; CODEVIEW-NEXT:     }
169 ; CODEVIEW-NEXT:   }
170 ; CODEVIEW-NEXT:   ProcEnd {
171 ; CODEVIEW-NEXT:     Kind: S_PROC_ID_END (0x114F)
172 ; CODEVIEW-NEXT:   }
173 ; CODEVIEW-NEXT: ]
174
175
176 ; ModuleID = 'fpo.cpp'
177 source_filename = "fpo.cpp"
178 target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
179 target triple = "i386-pc-windows-msvc19.14.26433"
180
181 ; Function Attrs: norecurse optsize
182 define dso_local i32 @main() local_unnamed_addr #0 !dbg !8 {
183 entry:
184   %a = alloca i32, align 4
185   %b = alloca i32, align 4
186   %c = alloca i32, align 4
187   %0 = bitcast i32* %a to i8*, !dbg !16
188   call void @llvm.lifetime.start.p0i8(i64 4, i8* nonnull %0) #4, !dbg !16
189   call void @llvm.dbg.declare(metadata i32* %a, metadata !13, metadata !DIExpression()), !dbg !16
190   store i32 1, i32* %a, align 4, !dbg !16, !tbaa !17
191   %1 = bitcast i32* %b to i8*, !dbg !21
192   call void @llvm.lifetime.start.p0i8(i64 4, i8* nonnull %1) #4, !dbg !21
193   call void @llvm.dbg.declare(metadata i32* %b, metadata !14, metadata !DIExpression()), !dbg !21
194   store i32 2, i32* %b, align 4, !dbg !21, !tbaa !17
195   %2 = bitcast i32* %c to i8*, !dbg !22
196   call void @llvm.lifetime.start.p0i8(i64 4, i8* nonnull %2) #4, !dbg !22
197   call void @llvm.dbg.declare(metadata i32* %c, metadata !15, metadata !DIExpression()), !dbg !22
198   store i32 3, i32* %c, align 4, !dbg !22, !tbaa !17
199   call void @"?f@@YAXAAH0@Z"(i32* nonnull dereferenceable(4) %a, i32* nonnull dereferenceable(4) %b) #5, !dbg !23
200   call void @"?g@@YAXAAH00@Z"(i32* nonnull dereferenceable(4) %a, i32* nonnull dereferenceable(4) %b, i32* nonnull dereferenceable(4) %c) #5, !dbg !24
201   %3 = load i32, i32* %a, align 4, !dbg !25, !tbaa !17
202   %4 = load i32, i32* %b, align 4, !dbg !25, !tbaa !17
203   %add = add nsw i32 %4, %3, !dbg !25
204   %5 = load i32, i32* %c, align 4, !dbg !25, !tbaa !17
205   %add1 = add nsw i32 %add, %5, !dbg !25
206   call void @llvm.lifetime.end.p0i8(i64 4, i8* nonnull %2) #4, !dbg !26
207   call void @llvm.lifetime.end.p0i8(i64 4, i8* nonnull %1) #4, !dbg !26
208   call void @llvm.lifetime.end.p0i8(i64 4, i8* nonnull %0) #4, !dbg !26
209   ret i32 %add1, !dbg !25
210 }
211
212 ; Function Attrs: argmemonly nounwind
213 declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) #1
214
215 ; Function Attrs: nounwind readnone speculatable
216 declare void @llvm.dbg.declare(metadata, metadata, metadata) #2
217
218 ; Function Attrs: optsize
219 declare dso_local void @"?f@@YAXAAH0@Z"(i32* dereferenceable(4), i32* dereferenceable(4)) local_unnamed_addr #3
220
221 ; Function Attrs: optsize
222 declare dso_local void @"?g@@YAXAAH00@Z"(i32* dereferenceable(4), i32* dereferenceable(4), i32* dereferenceable(4)) local_unnamed_addr #3
223
224 ; Function Attrs: argmemonly nounwind
225 declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) #1
226
227 attributes #0 = { norecurse optsize "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="pentium4" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
228 attributes #1 = { argmemonly nounwind }
229 attributes #2 = { nounwind readnone speculatable }
230 attributes #3 = { optsize "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="pentium4" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
231 attributes #4 = { nounwind }
232 attributes #5 = { optsize }
233
234 !llvm.dbg.cu = !{!0}
235 !llvm.module.flags = !{!3, !4, !5, !6}
236 !llvm.ident = !{!7}
237
238 !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 8.0.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
239 !1 = !DIFile(filename: "fpo.cpp", directory: "C:\5Csrc\5Cllvm-project\5Cbuild", checksumkind: CSK_MD5, checksum: "d0bb7e43f4e54936a94da008319a7de3")
240 !2 = !{}
241 !3 = !{i32 1, !"NumRegisterParameters", i32 0}
242 !4 = !{i32 2, !"CodeView", i32 1}
243 !5 = !{i32 2, !"Debug Info Version", i32 3}
244 !6 = !{i32 1, !"wchar_size", i32 2}
245 !7 = !{!"clang version 8.0.0 "}
246 !8 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 14, type: !9, isLocal: false, isDefinition: true, scopeLine: 14, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !12)
247 !9 = !DISubroutineType(types: !10)
248 !10 = !{!11}
249 !11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
250 !12 = !{!13, !14, !15}
251 !13 = !DILocalVariable(name: "a", scope: !8, file: !1, line: 15, type: !11)
252 !14 = !DILocalVariable(name: "b", scope: !8, file: !1, line: 16, type: !11)
253 !15 = !DILocalVariable(name: "c", scope: !8, file: !1, line: 17, type: !11)
254 !16 = !DILocation(line: 15, scope: !8)
255 !17 = !{!18, !18, i64 0}
256 !18 = !{!"int", !19, i64 0}
257 !19 = !{!"omnipotent char", !20, i64 0}
258 !20 = !{!"Simple C++ TBAA"}
259 !21 = !DILocation(line: 16, scope: !8)
260 !22 = !DILocation(line: 17, scope: !8)
261 !23 = !DILocation(line: 18, scope: !8)
262 !24 = !DILocation(line: 19, scope: !8)
263 !25 = !DILocation(line: 20, scope: !8)
264 !26 = !DILocation(line: 21, scope: !8)