xref: /llvm-project/clang/test/Frontend/stack-layout-remark.c (revision 557a5bc336ffb9b03c53d4d13fd8f0bc9418ec96)
1*557a5bc3SPaul Kirth // Check that backend stack layout diagnostics are working correctly with and
2*557a5bc3SPaul Kirth // without debug information, and when optimizations are enabled
3*557a5bc3SPaul Kirth //
4*557a5bc3SPaul Kirth // REQUIRES: x86-registered-target
5*557a5bc3SPaul Kirth //
6*557a5bc3SPaul Kirth // RUN: rm -rf %t
7*557a5bc3SPaul Kirth // RUN: mkdir -p %t
8*557a5bc3SPaul Kirth // RUN: %clang_cc1 %s -emit-codegen-only -triple x86_64-unknown-linux-gnu -target-cpu corei7 -Rpass-analysis=stack-frame-layout -o /dev/null  -O0  2>&1 | FileCheck %s --check-prefix=O0-NODEBUG
9*557a5bc3SPaul Kirth // RUN: %clang_cc1 %s -emit-codegen-only -triple x86_64-unknown-linux-gnu -target-cpu corei7 -Rpass-analysis=stack-frame-layout -o /dev/null  -O0  -debug-info-kind=constructor  -dwarf-version=5 -debugger-tuning=gdb 2>&1 | FileCheck %s --check-prefix=O0-DEBUG
10*557a5bc3SPaul Kirth // RUN: %clang_cc1 %s -emit-codegen-only -triple x86_64-unknown-linux-gnu -target-cpu corei7 -funwind-tables=2 -O3 -Rpass-analysis=stack-frame-layout   -debug-info-kind=constructor  -dwarf-version=5 -debugger-tuning=gdb -opt-record-file %t/stack-layout-remark.c.yml -opt-record-passes stack-frame-layout 2>&1 | FileCheck %s --check-prefix=O3-DEBUG
11*557a5bc3SPaul Kirth // RUN: cat %t/stack-layout-remark.c.yml | FileCheck %s --check-prefix=YAML
12*557a5bc3SPaul Kirth 
13*557a5bc3SPaul Kirth #define NULL (void*)0
14*557a5bc3SPaul Kirth 
15*557a5bc3SPaul Kirth extern void* allocate(unsigned size);
16*557a5bc3SPaul Kirth extern void deallocate(void* ptr);
17*557a5bc3SPaul Kirth extern int work(char *ary, int size);
18*557a5bc3SPaul Kirth extern int rand(void);
19*557a5bc3SPaul Kirth 
20*557a5bc3SPaul Kirth // Test YAML Ouput
21*557a5bc3SPaul Kirth // YAML: --- !Analysis
22*557a5bc3SPaul Kirth // YAML: Pass:            stack-frame-layout
23*557a5bc3SPaul Kirth // YAML: Name:            StackLayout
24*557a5bc3SPaul Kirth // YAML: DebugLoc:        { File: '{{.*}}stack-layout-remark.c',{{[[:space:]]*}}Line: [[# @LINE + 24]],
25*557a5bc3SPaul Kirth // YAML: Function:        foo
26*557a5bc3SPaul Kirth // YAML: Args:
27*557a5bc3SPaul Kirth // YAML:   - Offset:          '-40'
28*557a5bc3SPaul Kirth // YAML:   - Type:            Variable
29*557a5bc3SPaul Kirth // YAML:   - Align:           '16'
30*557a5bc3SPaul Kirth // YAML:   - Size:            '32'
31*557a5bc3SPaul Kirth // YAML:   - DataLoc:         'a @ {{.*}}stack-layout-remark.c:[[# @LINE + 19]]'
32*557a5bc3SPaul Kirth // YAML:   - DataLoc:         'f @ {{.*}}stack-layout-remark.c:[[# @LINE + 21]]'
33*557a5bc3SPaul Kirth 
34*557a5bc3SPaul Kirth //      O0-NODEBUG: Function: foo
35*557a5bc3SPaul Kirth // O0-NODEBUG-NEXT: Offset: [SP-40], Type: Variable, Align: 16, Size: 32
36*557a5bc3SPaul Kirth // O0-NODEBUG-NEXT: Offset: [SP-72], Type: Variable, Align: 16, Size: 32
37*557a5bc3SPaul Kirth //
38*557a5bc3SPaul Kirth //      O0-DEBUG: Function: foo
39*557a5bc3SPaul Kirth // O0-DEBUG-NEXT: Offset: [SP-40], Type: Variable, Align: 16, Size: 32
40*557a5bc3SPaul Kirth // O0-DEBUG-NEXT:     a @ {{.*}}stack-layout-remark.c:[[# @LINE + 10]]
41*557a5bc3SPaul Kirth // O0-DEBUG-NEXT: Offset: [SP-72], Type: Variable, Align: 16, Size: 32
42*557a5bc3SPaul Kirth // O0-DEBUG-NEXT:     f @ {{.*}}stack-layout-remark.c:[[# @LINE + 11]]
43*557a5bc3SPaul Kirth 
44*557a5bc3SPaul Kirth //      O3-DEBUG: Function: foo
45*557a5bc3SPaul Kirth // O3-DEBUG-NEXT: Offset: [SP-40], Type: Variable, Align: 16, Size: 32
46*557a5bc3SPaul Kirth // O3-DEBUG-NEXT:     a @ {{.*}}stack-layout-remark.c:[[# @LINE + 4]]
47*557a5bc3SPaul Kirth // O3-DEBUG-NEXT:     f @ {{.*}}stack-layout-remark.c:[[# @LINE + 6]]
foo()48*557a5bc3SPaul Kirth void foo() {
49*557a5bc3SPaul Kirth   {
50*557a5bc3SPaul Kirth     char a[32] = {0};
51*557a5bc3SPaul Kirth     work(a, sizeof(a));
52*557a5bc3SPaul Kirth   }
53*557a5bc3SPaul Kirth   char f[32] = {0};
54*557a5bc3SPaul Kirth   work(f, sizeof(f));
55*557a5bc3SPaul Kirth }
56*557a5bc3SPaul Kirth //      O0-NODEBUG: Function: bar
57*557a5bc3SPaul Kirth // O0-NODEBUG-NEXT: Offset: [SP-40], Type: Variable, Align: 16, Size: 32
58*557a5bc3SPaul Kirth // O0-NODEBUG-NEXT: Offset: [SP-72], Type: Variable, Align: 16, Size: 32
59*557a5bc3SPaul Kirth 
60*557a5bc3SPaul Kirth //      O0-DEBUG: Function: bar
61*557a5bc3SPaul Kirth // O0-DEBUG-NEXT: Offset: [SP-40], Type: Variable, Align: 16, Size: 32
62*557a5bc3SPaul Kirth // O0-DEBUG-NEXT:     f @ {{.*}}stack-layout-remark.c:[[# @LINE + 10]]
63*557a5bc3SPaul Kirth // O0-DEBUG-NEXT: Offset: [SP-72], Type: Variable, Align: 16, Size: 32
64*557a5bc3SPaul Kirth // O0-DEBUG-NEXT:     a @ {{.*}}stack-layout-remark.c:[[# @LINE + 10]]
65*557a5bc3SPaul Kirth 
66*557a5bc3SPaul Kirth //      O3-DEBUG: Function: bar
67*557a5bc3SPaul Kirth // O3-DEBUG-NEXT: Offset: [SP-40], Type: Variable, Align: 16, Size: 32
68*557a5bc3SPaul Kirth // O3-DEBUG-NEXT:     f @ {{.*}}stack-layout-remark.c:[[# @LINE + 4]]
69*557a5bc3SPaul Kirth // O3-DEBUG-NEXT: Offset: [SP-72], Type: Variable, Align: 16, Size: 32
70*557a5bc3SPaul Kirth // O3-DEBUG-NEXT:     a @ {{.*}}stack-layout-remark.c:[[# @LINE + 4]]
bar()71*557a5bc3SPaul Kirth void bar() {
72*557a5bc3SPaul Kirth   char f[32] = {0};
73*557a5bc3SPaul Kirth   {
74*557a5bc3SPaul Kirth     char a[32] = {0};
75*557a5bc3SPaul Kirth     work(a, sizeof(a));
76*557a5bc3SPaul Kirth   }
77*557a5bc3SPaul Kirth   work(f, sizeof(f));
78*557a5bc3SPaul Kirth }
79*557a5bc3SPaul Kirth 
80*557a5bc3SPaul Kirth struct Array {
81*557a5bc3SPaul Kirth   int *data;
82*557a5bc3SPaul Kirth   int size;
83*557a5bc3SPaul Kirth };
84*557a5bc3SPaul Kirth 
85*557a5bc3SPaul Kirth struct Result {
86*557a5bc3SPaul Kirth   struct Array *data;
87*557a5bc3SPaul Kirth   int sum;
88*557a5bc3SPaul Kirth };
89*557a5bc3SPaul Kirth 
90*557a5bc3SPaul Kirth //      O0-NODEBUG: Function: cleanup_array
91*557a5bc3SPaul Kirth // O0-NODEBUG-NEXT: Offset: [SP-8], Type: Variable, Align: 8, Size: 8
92*557a5bc3SPaul Kirth 
93*557a5bc3SPaul Kirth //      O0-DEBUG: Function: cleanup_array
94*557a5bc3SPaul Kirth // O0-DEBUG-NEXT: Offset: [SP-8], Type: Variable, Align: 8, Size: 8
95*557a5bc3SPaul Kirth // O0-DEBUG-NEXT:     a @ {{.*}}stack-layout-remark.c:[[# @LINE + 5]]
96*557a5bc3SPaul Kirth 
97*557a5bc3SPaul Kirth //      O3-DEBUG: Function: cleanup_array
98*557a5bc3SPaul Kirth //      O3-DEBUG: Function: cleanup_result
99*557a5bc3SPaul Kirth // O3-DEBUG-NEXT: Offset: [SP-8], Type: Spill, Align: 16, Size: 8
cleanup_array(struct Array * a)100*557a5bc3SPaul Kirth void cleanup_array(struct Array *a) {
101*557a5bc3SPaul Kirth   if (!a)
102*557a5bc3SPaul Kirth     return;
103*557a5bc3SPaul Kirth   if (!a->data)
104*557a5bc3SPaul Kirth     return;
105*557a5bc3SPaul Kirth   deallocate(a->data);
106*557a5bc3SPaul Kirth }
107*557a5bc3SPaul Kirth 
108*557a5bc3SPaul Kirth //      O0-NODEBUG: Function: cleanup_result
109*557a5bc3SPaul Kirth // O0-NODEBUG-NEXT: Offset: [SP-8], Type: Variable, Align: 8, Size: 8
110*557a5bc3SPaul Kirth 
111*557a5bc3SPaul Kirth //      O0-DEBUG: Function: cleanup_result
112*557a5bc3SPaul Kirth // O0-DEBUG-NEXT: Offset: [SP-8], Type: Variable, Align: 8, Size: 8
113*557a5bc3SPaul Kirth // O0-DEBUG-NEXT:     res @ {{.*}}stack-layout-remark.c:[[# @LINE + 1]]
cleanup_result(struct Result * res)114*557a5bc3SPaul Kirth void cleanup_result(struct Result *res) {
115*557a5bc3SPaul Kirth   if (!res)
116*557a5bc3SPaul Kirth     return;
117*557a5bc3SPaul Kirth   if (!res->data)
118*557a5bc3SPaul Kirth     return;
119*557a5bc3SPaul Kirth   cleanup_array(res->data);
120*557a5bc3SPaul Kirth   deallocate(res->data);
121*557a5bc3SPaul Kirth }
122*557a5bc3SPaul Kirth 
123*557a5bc3SPaul Kirth extern void use_dot_vector(struct Array *data);
124*557a5bc3SPaul Kirth 
125*557a5bc3SPaul Kirth //      O0-NODEBUG: Function: do_work
126*557a5bc3SPaul Kirth // O0-NODEBUG-NEXT: Offset: [SP-4], Type: Variable, Align: 4, Size: 4
127*557a5bc3SPaul Kirth // O0-NODEBUG-NEXT: Offset: [SP-16], Type: Variable, Align: 8, Size: 8
128*557a5bc3SPaul Kirth // O0-NODEBUG-NEXT: Offset: [SP-24], Type: Variable, Align: 8, Size: 8
129*557a5bc3SPaul Kirth // O0-NODEBUG-NEXT: Offset: [SP-32], Type: Variable, Align: 8, Size: 8
130*557a5bc3SPaul Kirth // O0-NODEBUG-NEXT: Offset: [SP-36], Type: Variable, Align: 4, Size: 4
131*557a5bc3SPaul Kirth // O0-NODEBUG-NEXT: Offset: [SP-48], Type: Variable, Align: 8, Size: 8
132*557a5bc3SPaul Kirth // O0-NODEBUG-NEXT: Offset: [SP-52], Type: Variable, Align: 4, Size: 4
133*557a5bc3SPaul Kirth // O0-NODEBUG-NEXT: Offset: [SP-56], Type: Variable, Align: 4, Size: 4
134*557a5bc3SPaul Kirth 
135*557a5bc3SPaul Kirth //      O0-DEBUG: Function: do_work
136*557a5bc3SPaul Kirth // O0-DEBUG-NEXT: Offset: [SP-4], Type: Variable, Align: 4, Size: 4
137*557a5bc3SPaul Kirth // O0-DEBUG-NEXT: Offset: [SP-16], Type: Variable, Align: 8, Size: 8
138*557a5bc3SPaul Kirth // O0-DEBUG-NEXT:     A @ {{.*}}stack-layout-remark.c:[[# @LINE + 20]]
139*557a5bc3SPaul Kirth // O0-DEBUG-NEXT: Offset: [SP-24], Type: Variable, Align: 8, Size: 8
140*557a5bc3SPaul Kirth // O0-DEBUG-NEXT:     B @ {{.*}}stack-layout-remark.c:[[# @LINE + 18]]
141*557a5bc3SPaul Kirth // O0-DEBUG-NEXT: Offset: [SP-32], Type: Variable, Align: 8, Size: 8
142*557a5bc3SPaul Kirth // O0-DEBUG-NEXT:     out @ {{.*}}stack-layout-remark.c:[[# @LINE + 16]]
143*557a5bc3SPaul Kirth // O0-DEBUG-NEXT: Offset: [SP-36], Type: Variable, Align: 4, Size: 4
144*557a5bc3SPaul Kirth // O0-DEBUG-NEXT:     len @ {{.*}}stack-layout-remark.c:[[# @LINE + 19]]
145*557a5bc3SPaul Kirth // O0-DEBUG-NEXT: Offset: [SP-48], Type: Variable, Align: 8, Size: 8
146*557a5bc3SPaul Kirth // O0-DEBUG-NEXT:     AB @ {{.*}}stack-layout-remark.c:[[# @LINE + 18]]
147*557a5bc3SPaul Kirth // O0-DEBUG-NEXT: Offset: [SP-52], Type: Variable, Align: 4, Size: 4
148*557a5bc3SPaul Kirth // O0-DEBUG-NEXT:     sum @ {{.*}}stack-layout-remark.c:[[# @LINE + 32]]
149*557a5bc3SPaul Kirth // O0-DEBUG-NEXT: Offset: [SP-56], Type: Variable, Align: 4, Size: 4
150*557a5bc3SPaul Kirth // O0-DEBUG-NEXT:     i @ {{.*}}stack-layout-remark.c:[[# @LINE + 31]]
151*557a5bc3SPaul Kirth 
152*557a5bc3SPaul Kirth //      O3-DEBUG: Function: do_work
153*557a5bc3SPaul Kirth // O3-DEBUG-NEXT: Offset: [SP-8], Type: Spill, Align: 16, Size: 8
154*557a5bc3SPaul Kirth // O3-DEBUG-NEXT: Offset: [SP-16], Type: Spill, Align: 8, Size: 8
155*557a5bc3SPaul Kirth // O3-DEBUG-NEXT: Offset: [SP-24], Type: Spill, Align: 16, Size: 8
156*557a5bc3SPaul Kirth // O3-DEBUG-NEXT: Offset: [SP-32], Type: Spill, Align: 8, Size: 8
157*557a5bc3SPaul Kirth // O3-DEBUG-NEXT: Offset: [SP-40], Type: Spill, Align: 16, Size: 8
do_work(struct Array * A,struct Array * B,struct Result * out)158*557a5bc3SPaul Kirth int do_work(struct Array *A, struct Array *B, struct Result *out) {
159*557a5bc3SPaul Kirth   if (!A || !B)
160*557a5bc3SPaul Kirth     return -1;
161*557a5bc3SPaul Kirth   if (A->size != B->size)
162*557a5bc3SPaul Kirth     return -1;
163*557a5bc3SPaul Kirth   const int len = A->size;
164*557a5bc3SPaul Kirth   struct Array *AB;
165*557a5bc3SPaul Kirth   if (out->data == NULL) {
166*557a5bc3SPaul Kirth     AB = (struct Array *)allocate(sizeof(struct Array));
167*557a5bc3SPaul Kirth     AB->data = NULL;
168*557a5bc3SPaul Kirth     AB->size = 0;
169*557a5bc3SPaul Kirth     out->data = AB;
170*557a5bc3SPaul Kirth   } else {
171*557a5bc3SPaul Kirth     AB = out->data;
172*557a5bc3SPaul Kirth   }
173*557a5bc3SPaul Kirth 
174*557a5bc3SPaul Kirth   if (AB->data)
175*557a5bc3SPaul Kirth     deallocate(AB->data);
176*557a5bc3SPaul Kirth 
177*557a5bc3SPaul Kirth   AB->data = (int *)allocate(len * sizeof(int));
178*557a5bc3SPaul Kirth   AB->size = len;
179*557a5bc3SPaul Kirth 
180*557a5bc3SPaul Kirth   int sum = 0;
181*557a5bc3SPaul Kirth   for (int i = 0; i < len; ++i) {
182*557a5bc3SPaul Kirth     AB->data[i] = A->data[i] * B->data[i];
183*557a5bc3SPaul Kirth     sum += AB->data[i];
184*557a5bc3SPaul Kirth   }
185*557a5bc3SPaul Kirth   return sum;
186*557a5bc3SPaul Kirth }
187*557a5bc3SPaul Kirth 
188*557a5bc3SPaul Kirth //      O0-NODEBUG: Function: gen_array
189*557a5bc3SPaul Kirth // O0-NODEBUG-NEXT: Offset: [SP-8], Type: Variable, Align: 8, Size: 8
190*557a5bc3SPaul Kirth // O0-NODEBUG-NEXT: Offset: [SP-12], Type: Variable, Align: 4, Size: 4
191*557a5bc3SPaul Kirth // O0-NODEBUG-NEXT: Offset: [SP-24], Type: Variable, Align: 8, Size: 8
192*557a5bc3SPaul Kirth // O0-NODEBUG-NEXT: Offset: [SP-28], Type: Variable, Align: 4, Size: 4
193*557a5bc3SPaul Kirth 
194*557a5bc3SPaul Kirth //      O0-DEBUG: Function: gen_array
195*557a5bc3SPaul Kirth // O0-DEBUG-NEXT: Offset: [SP-8], Type: Variable, Align: 8, Size: 8
196*557a5bc3SPaul Kirth // O0-DEBUG-NEXT: Offset: [SP-12], Type: Variable, Align: 4, Size: 4
197*557a5bc3SPaul Kirth // O0-DEBUG-NEXT:     size @ {{.*}}stack-layout-remark.c:[[# @LINE + 10]]
198*557a5bc3SPaul Kirth // O0-DEBUG-NEXT: Offset: [SP-24], Type: Variable, Align: 8, Size: 8
199*557a5bc3SPaul Kirth // O0-DEBUG-NEXT:     res @ {{.*}}stack-layout-remark.c:[[# @LINE + 11]]
200*557a5bc3SPaul Kirth // O0-DEBUG-NEXT: Offset: [SP-28], Type: Variable, Align: 4, Size: 4
201*557a5bc3SPaul Kirth // O0-DEBUG-NEXT:     i @ {{.*}}stack-layout-remark.c:[[# @LINE + 13]]
202*557a5bc3SPaul Kirth 
203*557a5bc3SPaul Kirth //      O3-DEBUG: Function: gen_array
204*557a5bc3SPaul Kirth // O3-DEBUG-NEXT: Offset: [SP-8], Type: Spill, Align: 16, Size: 8
205*557a5bc3SPaul Kirth // O3-DEBUG-NEXT: Offset: [SP-16], Type: Spill, Align: 8, Size: 8
206*557a5bc3SPaul Kirth // O3-DEBUG-NEXT: Offset: [SP-24], Type: Spill, Align: 16, Size: 8
gen_array(int size)207*557a5bc3SPaul Kirth struct Array *gen_array(int size) {
208*557a5bc3SPaul Kirth   if (size < 0)
209*557a5bc3SPaul Kirth     return NULL;
210*557a5bc3SPaul Kirth   struct Array *res = (struct Array *)allocate(sizeof(struct Array));
211*557a5bc3SPaul Kirth   res->size = size;
212*557a5bc3SPaul Kirth   res->data = (int *)allocate(size * sizeof(int));
213*557a5bc3SPaul Kirth 
214*557a5bc3SPaul Kirth   for (int i = 0; i < size; ++i) {
215*557a5bc3SPaul Kirth     res->data[i] = rand();
216*557a5bc3SPaul Kirth   }
217*557a5bc3SPaul Kirth 
218*557a5bc3SPaul Kirth   return res;
219*557a5bc3SPaul Kirth }
220*557a5bc3SPaul Kirth 
221*557a5bc3SPaul Kirth // YAML: --- !Analysis
222*557a5bc3SPaul Kirth // YAML: Pass:            stack-frame-layout
223*557a5bc3SPaul Kirth // YAML: Name:            StackLayout
224*557a5bc3SPaul Kirth // YAML: DebugLoc:        { File: '{{.*}}stack-layout-remark.c',{{[[:space:]]*}}Line: [[# @LINE + 59]],
225*557a5bc3SPaul Kirth // YAML: Function:        caller
226*557a5bc3SPaul Kirth // YAML: Args:
227*557a5bc3SPaul Kirth // YAML:   - Offset:          '-8'
228*557a5bc3SPaul Kirth // YAML:   - Type:            Spill
229*557a5bc3SPaul Kirth // YAML:   - Align:           '16'
230*557a5bc3SPaul Kirth // YAML:   - Size:            '8'
231*557a5bc3SPaul Kirth // YAML:   - Offset:          '-16'
232*557a5bc3SPaul Kirth // YAML:   - Type:            Spill
233*557a5bc3SPaul Kirth // YAML:   - Align:           '8'
234*557a5bc3SPaul Kirth // YAML:   - Size:            '8'
235*557a5bc3SPaul Kirth // YAML:   - Offset:          '-24'
236*557a5bc3SPaul Kirth // YAML:   - Type:            Spill
237*557a5bc3SPaul Kirth // YAML:   - Align:           '16'
238*557a5bc3SPaul Kirth // YAML:   - Size:            '8'
239*557a5bc3SPaul Kirth // YAML:   - Offset:          '-32'
240*557a5bc3SPaul Kirth // YAML:   - Type:            Spill
241*557a5bc3SPaul Kirth // YAML:   - Align:           '8'
242*557a5bc3SPaul Kirth // YAML:   - Size:            '8'
243*557a5bc3SPaul Kirth // YAML:   - Offset:          '-40'
244*557a5bc3SPaul Kirth // YAML:   - Type:            Spill
245*557a5bc3SPaul Kirth // YAML:   - Align:           '16'
246*557a5bc3SPaul Kirth // YAML:   - Size:            '8'
247*557a5bc3SPaul Kirth // YAML:   - Offset:          '-48'
248*557a5bc3SPaul Kirth // YAML:   - Type:            Spill
249*557a5bc3SPaul Kirth // YAML:   - Align:           '8'
250*557a5bc3SPaul Kirth // YAML:   - Size:            '8'
251*557a5bc3SPaul Kirth 
252*557a5bc3SPaul Kirth //      O0-NODEBUG: Function: caller
253*557a5bc3SPaul Kirth // O0-NODEBUG-NEXT: Offset: [SP-4], Type: Variable, Align: 4, Size: 4
254*557a5bc3SPaul Kirth // O0-NODEBUG-NEXT: Offset: [SP-8], Type: Variable, Align: 4, Size: 4
255*557a5bc3SPaul Kirth // O0-NODEBUG-NEXT: Offset: [SP-16], Type: Variable, Align: 8, Size: 8
256*557a5bc3SPaul Kirth // O0-NODEBUG-NEXT: Offset: [SP-24], Type: Variable, Align: 8, Size: 8
257*557a5bc3SPaul Kirth // O0-NODEBUG-NEXT: Offset: [SP-32], Type: Variable, Align: 8, Size: 8
258*557a5bc3SPaul Kirth // O0-NODEBUG-NEXT: Offset: [SP-36], Type: Variable, Align: 4, Size: 4
259*557a5bc3SPaul Kirth // O0-NODEBUG-NEXT: Offset: [SP-40], Type: Variable, Align: 4, Size: 4
260*557a5bc3SPaul Kirth 
261*557a5bc3SPaul Kirth //      O0-DEBUG: Function: caller
262*557a5bc3SPaul Kirth // O0-DEBUG-NEXT: Offset: [SP-4], Type: Variable, Align: 4, Size: 4
263*557a5bc3SPaul Kirth // O0-DEBUG-NEXT: Offset: [SP-8], Type: Variable, Align: 4, Size: 4
264*557a5bc3SPaul Kirth // O0-DEBUG-NEXT:     size @ {{.*}}stack-layout-remark.c:[[# @LINE + 20]]
265*557a5bc3SPaul Kirth // O0-DEBUG-NEXT: Offset: [SP-16], Type: Variable, Align: 8, Size: 8
266*557a5bc3SPaul Kirth // O0-DEBUG-NEXT:     A @ {{.*}}stack-layout-remark.c:[[# @LINE + 19]]
267*557a5bc3SPaul Kirth // O0-DEBUG-NEXT: Offset: [SP-24], Type: Variable, Align: 8, Size: 8
268*557a5bc3SPaul Kirth // O0-DEBUG-NEXT:     B @ {{.*}}stack-layout-remark.c:[[# @LINE + 18]]
269*557a5bc3SPaul Kirth // O0-DEBUG-NEXT: Offset: [SP-32], Type: Variable, Align: 8, Size: 8
270*557a5bc3SPaul Kirth // O0-DEBUG-NEXT:     res @ {{.*}}stack-layout-remark.c:[[# @LINE + 17]]
271*557a5bc3SPaul Kirth // O0-DEBUG-NEXT: Offset: [SP-36], Type: Variable, Align: 4, Size: 4
272*557a5bc3SPaul Kirth // O0-DEBUG-NEXT:     ret @ {{.*}}stack-layout-remark.c:[[# @LINE + 16]]
273*557a5bc3SPaul Kirth // O0-DEBUG-NEXT: Offset: [SP-40], Type: Variable, Align: 4, Size: 4
274*557a5bc3SPaul Kirth // O0-DEBUG-NEXT:     err @ {{.*}}stack-layout-remark.c:[[# @LINE + 16]]
275*557a5bc3SPaul Kirth 
276*557a5bc3SPaul Kirth //      O3-DEBUG: Function: caller
277*557a5bc3SPaul Kirth // O3-DEBUG-NEXT: Offset: [SP-8], Type: Spill, Align: 16, Size: 8
278*557a5bc3SPaul Kirth // O3-DEBUG-NEXT: Offset: [SP-16], Type: Spill, Align: 8, Size: 8
279*557a5bc3SPaul Kirth // O3-DEBUG-NEXT: Offset: [SP-24], Type: Spill, Align: 16, Size: 8
280*557a5bc3SPaul Kirth // O3-DEBUG-NEXT: Offset: [SP-32], Type: Spill, Align: 8, Size: 8
281*557a5bc3SPaul Kirth // O3-DEBUG-NEXT: Offset: [SP-40], Type: Spill, Align: 16, Size: 8
282*557a5bc3SPaul Kirth // O3-DEBUG-NEXT: Offset: [SP-48], Type: Spill, Align: 8, Size: 8
caller()283*557a5bc3SPaul Kirth int caller() {
284*557a5bc3SPaul Kirth   const int size = 100;
285*557a5bc3SPaul Kirth   struct Array *A = gen_array(size);
286*557a5bc3SPaul Kirth   struct Array *B = gen_array(size);
287*557a5bc3SPaul Kirth   struct Result *res = (struct Result *)allocate(sizeof(struct Result));
288*557a5bc3SPaul Kirth   int ret = -1;
289*557a5bc3SPaul Kirth 
290*557a5bc3SPaul Kirth   int err = do_work(A, B, res);
291*557a5bc3SPaul Kirth   if (err == -1) {
292*557a5bc3SPaul Kirth     goto cleanup;
293*557a5bc3SPaul Kirth   }
294*557a5bc3SPaul Kirth 
295*557a5bc3SPaul Kirth   ret = res->sum;
296*557a5bc3SPaul Kirth   if (ret == -1)
297*557a5bc3SPaul Kirth     return caller();
298*557a5bc3SPaul Kirth 
299*557a5bc3SPaul Kirth   use_dot_vector(res->data);
300*557a5bc3SPaul Kirth 
301*557a5bc3SPaul Kirth cleanup:
302*557a5bc3SPaul Kirth   cleanup_array(A);
303*557a5bc3SPaul Kirth   cleanup_array(B);
304*557a5bc3SPaul Kirth   cleanup_result(res);
305*557a5bc3SPaul Kirth 
306*557a5bc3SPaul Kirth   return ret;
307*557a5bc3SPaul Kirth }
308*557a5bc3SPaul Kirth 
309