1 ; RUN: llc < %s | FileCheck %s --check-prefix=ASM
2 ; RUN: llc < %s -filetype=obj | llvm-readobj --codeview - | FileCheck %s --check-prefix=CODEVIEW
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.
9 ; The following source can be used with a debugger to check that locals are
10 ; displayed correctly:
13 ; void __attribute__((optnone)) __declspec(noinline) f(int &a, int &b) {
17 ; void __attribute__((optnone)) __declspec(noinline) g(int &a, int &b, int &c) {
23 ; void f(int &a, int &b);
24 ; void g(int &a, int &b, int &c);
33 ; $ clang -S -g -gcodeview t.cpp -emit-llvm -o vframe-fpo.ll -Os
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
48 ; ASM: movl $1, {{.*}}
49 ; ASM: movl $2, {{.*}}
50 ; ASM: movl $3, {{.*}}
52 ; ASM that store-to-push conversion fires.
55 ; ASM-NEXT: calll "?f@@YAXAAH0@Z"
56 ; ASM-NEXT: addl $8, %esp
60 ; ASM-NEXT: calll "?g@@YAXAAH00@Z"
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: ObjNameSym {
69 ; CODEVIEW-NEXT: Kind: S_OBJNAME (0x1101)
70 ; CODEVIEW: Compile3Sym {
71 ; CODEVIEW-NEXT: Kind: S_COMPILE3 (0x113C)
74 ; CODEVIEW: Subsection [
75 ; CODEVIEW-NEXT: SubSectionType: FrameData (0xF5)
76 ; CODEVIEW-NEXT: SubSectionSize:
77 ; CODEVIEW-NEXT: LinkageName: _main
78 ; CODEVIEW: FrameData {
80 ; CODEVIEW: FrameData {
82 ; CODEVIEW: FrameData {
84 ; CODEVIEW: FrameData {
86 ; CODEVIEW: FrameData {
87 ; CODEVIEW-NEXT: RvaStart:
88 ; CODEVIEW-NEXT: CodeSize:
89 ; CODEVIEW-NEXT: LocalSize: 0xC
90 ; CODEVIEW-NEXT: ParamsSize: 0x0
91 ; CODEVIEW-NEXT: MaxStackSize: 0x0
92 ; CODEVIEW-NEXT: PrologSize:
93 ; CODEVIEW-NEXT: SavedRegsSize: 0xC
94 ; CODEVIEW-NEXT: Flags [ (0x0)
97 ; $T0 is the CFA, the address of the return address, and our defranges are
99 ; CODEVIEW-NEXT: FrameFunc [
100 ; CODEVIEW-NEXT: $T0 .raSearch =
101 ; CODEVIEW-NEXT: $eip $T0 ^ =
102 ; CODEVIEW-NEXT: $esp $T0 4 + =
103 ; CODEVIEW-NEXT: $ebx $T0 4 - ^ =
104 ; CODEVIEW-NEXT: $edi $T0 8 - ^ =
105 ; CODEVIEW-NEXT: $esi $T0 12 - ^ =
109 ; We push 16 bytes in the prologue, so our local variables are at offsets -16,
112 ; CODEVIEW: Subsection [
113 ; CODEVIEW-NEXT: SubSectionType: Symbols (0xF1)
114 ; CODEVIEW-NEXT: SubSectionSize:
115 ; CODEVIEW-NEXT: GlobalProcIdSym {
116 ; CODEVIEW-NEXT: Kind: S_GPROC32_ID (0x1147)
117 ; CODEVIEW: DisplayName: main
118 ; CODEVIEW: LinkageName: _main
120 ; CODEVIEW-NEXT: FrameProcSym {
121 ; CODEVIEW-NEXT: Kind: S_FRAMEPROC (0x1012)
122 ; CODEVIEW-NEXT: TotalFrameBytes: 0xC
123 ; CODEVIEW-NEXT: PaddingFrameBytes: 0x0
124 ; CODEVIEW-NEXT: OffsetToPadding: 0x0
125 ; CODEVIEW-NEXT: BytesOfCalleeSavedRegisters: 0xC
126 ; CODEVIEW-NEXT: OffsetOfExceptionHandler: 0x0
127 ; CODEVIEW-NEXT: SectionIdOfExceptionHandler: 0x0
128 ; CODEVIEW-NEXT: Flags [ (0x14000)
130 ; CODEVIEW-NEXT: LocalFramePtrReg: VFRAME (0x7536)
131 ; CODEVIEW-NEXT: ParamFramePtrReg: VFRAME (0x7536)
133 ; CODEVIEW-NEXT: LocalSym {
134 ; CODEVIEW-NEXT: Kind: S_LOCAL (0x113E)
135 ; CODEVIEW: VarName: a
137 ; CODEVIEW-NEXT: DefRangeFramePointerRelSym {
138 ; CODEVIEW-NEXT: Kind: S_DEFRANGE_FRAMEPOINTER_REL (0x1142)
139 ; CODEVIEW-NEXT: Offset: -16
140 ; CODEVIEW-NEXT: LocalVariableAddrRange {
141 ; CODEVIEW-NEXT: OffsetStart:
142 ; CODEVIEW-NEXT: ISectStart:
143 ; CODEVIEW-NEXT: Range:
146 ; CODEVIEW-NEXT: LocalSym {
147 ; CODEVIEW-NEXT: Kind: S_LOCAL (0x113E)
148 ; CODEVIEW: VarName: b
150 ; CODEVIEW-NEXT: DefRangeFramePointerRelSym {
151 ; CODEVIEW-NEXT: Kind: S_DEFRANGE_FRAMEPOINTER_REL (0x1142)
152 ; CODEVIEW-NEXT: Offset: -20
153 ; CODEVIEW-NEXT: LocalVariableAddrRange {
154 ; CODEVIEW-NEXT: OffsetStart:
155 ; CODEVIEW-NEXT: ISectStart:
156 ; CODEVIEW-NEXT: Range:
159 ; CODEVIEW-NEXT: LocalSym {
160 ; CODEVIEW-NEXT: Kind: S_LOCAL (0x113E)
161 ; CODEVIEW: VarName: c
163 ; CODEVIEW-NEXT: DefRangeFramePointerRelSym {
164 ; CODEVIEW-NEXT: Kind: S_DEFRANGE_FRAMEPOINTER_REL (0x1142)
165 ; CODEVIEW-NEXT: Offset: -24
166 ; CODEVIEW-NEXT: LocalVariableAddrRange {
167 ; CODEVIEW-NEXT: OffsetStart:
168 ; CODEVIEW-NEXT: ISectStart:
169 ; CODEVIEW-NEXT: Range:
172 ; CODEVIEW-NEXT: ProcEnd {
173 ; CODEVIEW-NEXT: Kind: S_PROC_ID_END (0x114F)
178 ; ModuleID = 'fpo.cpp'
179 source_filename = "fpo.cpp"
180 target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
181 target triple = "i386-pc-windows-msvc19.14.26433"
183 ; Function Attrs: norecurse optsize
184 define dso_local i32 @main() local_unnamed_addr #0 !dbg !8 {
186 %a = alloca i32, align 4
187 %b = alloca i32, align 4
188 %c = alloca i32, align 4
189 %0 = bitcast i32* %a to i8*, !dbg !16
190 call void @llvm.lifetime.start.p0i8(i64 4, i8* nonnull %0) #4, !dbg !16
191 call void @llvm.dbg.declare(metadata i32* %a, metadata !13, metadata !DIExpression()), !dbg !16
192 store i32 1, i32* %a, align 4, !dbg !16, !tbaa !17
193 %1 = bitcast i32* %b to i8*, !dbg !21
194 call void @llvm.lifetime.start.p0i8(i64 4, i8* nonnull %1) #4, !dbg !21
195 call void @llvm.dbg.declare(metadata i32* %b, metadata !14, metadata !DIExpression()), !dbg !21
196 store i32 2, i32* %b, align 4, !dbg !21, !tbaa !17
197 %2 = bitcast i32* %c to i8*, !dbg !22
198 call void @llvm.lifetime.start.p0i8(i64 4, i8* nonnull %2) #4, !dbg !22
199 call void @llvm.dbg.declare(metadata i32* %c, metadata !15, metadata !DIExpression()), !dbg !22
200 store i32 3, i32* %c, align 4, !dbg !22, !tbaa !17
201 call void @"?f@@YAXAAH0@Z"(i32* nonnull dereferenceable(4) %a, i32* nonnull dereferenceable(4) %b) #5, !dbg !23
202 call void @"?g@@YAXAAH00@Z"(i32* nonnull dereferenceable(4) %a, i32* nonnull dereferenceable(4) %b, i32* nonnull dereferenceable(4) %c) #5, !dbg !24
203 %3 = load i32, i32* %a, align 4, !dbg !25, !tbaa !17
204 %4 = load i32, i32* %b, align 4, !dbg !25, !tbaa !17
205 %add = add nsw i32 %4, %3, !dbg !25
206 %5 = load i32, i32* %c, align 4, !dbg !25, !tbaa !17
207 %add1 = add nsw i32 %add, %5, !dbg !25
208 call void @llvm.lifetime.end.p0i8(i64 4, i8* nonnull %2) #4, !dbg !26
209 call void @llvm.lifetime.end.p0i8(i64 4, i8* nonnull %1) #4, !dbg !26
210 call void @llvm.lifetime.end.p0i8(i64 4, i8* nonnull %0) #4, !dbg !26
211 ret i32 %add1, !dbg !25
214 ; Function Attrs: argmemonly nounwind
215 declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) #1
217 ; Function Attrs: nounwind readnone speculatable
218 declare void @llvm.dbg.declare(metadata, metadata, metadata) #2
220 ; Function Attrs: optsize
221 declare dso_local void @"?f@@YAXAAH0@Z"(i32* dereferenceable(4), i32* dereferenceable(4)) local_unnamed_addr #3
223 ; Function Attrs: optsize
224 declare dso_local void @"?g@@YAXAAH00@Z"(i32* dereferenceable(4), i32* dereferenceable(4), i32* dereferenceable(4)) local_unnamed_addr #3
226 ; Function Attrs: argmemonly nounwind
227 declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) #1
229 attributes #0 = { norecurse optsize "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="none" "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" }
230 attributes #1 = { argmemonly nounwind }
231 attributes #2 = { nounwind readnone speculatable }
232 attributes #3 = { optsize "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="none" "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" }
233 attributes #4 = { nounwind }
234 attributes #5 = { optsize }
237 !llvm.module.flags = !{!3, !4, !5, !6}
240 !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)
241 !1 = !DIFile(filename: "fpo.cpp", directory: "C:\5Csrc\5Cllvm-project\5Cbuild", checksumkind: CSK_MD5, checksum: "d0bb7e43f4e54936a94da008319a7de3")
243 !3 = !{i32 1, !"NumRegisterParameters", i32 0}
244 !4 = !{i32 2, !"CodeView", i32 1}
245 !5 = !{i32 2, !"Debug Info Version", i32 3}
246 !6 = !{i32 1, !"wchar_size", i32 2}
247 !7 = !{!"clang version 8.0.0 "}
248 !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)
249 !9 = !DISubroutineType(types: !10)
251 !11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
252 !12 = !{!13, !14, !15}
253 !13 = !DILocalVariable(name: "a", scope: !8, file: !1, line: 15, type: !11)
254 !14 = !DILocalVariable(name: "b", scope: !8, file: !1, line: 16, type: !11)
255 !15 = !DILocalVariable(name: "c", scope: !8, file: !1, line: 17, type: !11)
256 !16 = !DILocation(line: 15, scope: !8)
257 !17 = !{!18, !18, i64 0}
258 !18 = !{!"int", !19, i64 0}
259 !19 = !{!"omnipotent char", !20, i64 0}
260 !20 = !{!"Simple C++ TBAA"}
261 !21 = !DILocation(line: 16, scope: !8)
262 !22 = !DILocation(line: 17, scope: !8)
263 !23 = !DILocation(line: 18, scope: !8)
264 !24 = !DILocation(line: 19, scope: !8)
265 !25 = !DILocation(line: 20, scope: !8)
266 !26 = !DILocation(line: 21, scope: !8)