]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/funcargs.c
* config/sh/tm-sh.h (BELIEVE_PCC_PROMOTION): Define, so that
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / funcargs.c
CommitLineData
ef44eed1
SS
1/* Test passing of arguments to functions. Use various sorts of arguments,
2 including basic types, pointers to those types, structures, lots of
3 args, etc, in various combinations. */
4
5/* AIX requires this to be the first thing in the file. */
6#ifdef __GNUC__
7# define alloca __builtin_alloca
8# define HAVE_STACK_ALLOCA 1
9#else /* not __GNUC__ */
10# ifdef _AIX
11 #pragma alloca
12# define HAVE_STACK_ALLOCA 1
13# else /* Not AIX */
14# ifdef sparc
15# include <alloca.h>
16# define HAVE_STACK_ALLOCA 1
17 char *alloca ();
18# endif /* sparc */
19# endif /* Not AIX */
20#endif /* not __GNUC__ */
21
22char c = 'a';
23char *cp = &c;
24
25unsigned char uc = 'b';
26unsigned char *ucp = &uc;
27
28short s = 1;
29short *sp = &s;
30
31unsigned short us = 6;
32unsigned short *usp = &us;
33
34int i = 2;
35int *ip = &i;
36
37unsigned int ui = 7;
38unsigned int *uip = &ui;
39
40long l = 3;
41long *lp = &l;
42
43unsigned long ul = 8;
44unsigned long *ulp = &ul;
45
46float f = 4.0;
47float *fp = &f;
48
49double d = 5.0;
50double *dp = &d;
51
52struct stag {
53 int s1;
54 int s2;
55} st = { 101, 102 };
56struct stag *stp = &st;
57
58union utag {
59 int u1;
60 long u2;
61} un;
62union utag *unp = &un;
63
64char carray[] = {'a', 'n', ' ', 'a', 'r', 'r', 'a', 'y', '\0'};
65
66
67/* Test various permutations and interleaving of integral arguments */
68
69
70call0a (c, s, i, l)
71char c; short s; int i; long l;
72{
73 c = 'a';
74 s = 5;
75 i = 6;
76 l = 7;
77}
78
79call0b (s, i, l, c)
80short s; int i; long l; char c;
81{
82 s = 6; i = 7; l = 8; c = 'j';
83}
84
85call0c (i, l, c, s)
86int i; long l; char c; short s;
87{
88 i = 3; l = 4; c = 'k'; s = 5;
89}
90
91call0d (l, c, s, i)
92long l; char c; short s; int i;
93{
94 l = 7; c = 'z'; s = 8; i = 9;
95}
96
97call0e (c1, l, c2, i, c3, s, c4, c5)
98char c1; long l; char c2; int i; char c3; short s; char c4; char c5;
99{
100 c1 = 'a'; l = 5; c2 = 'b'; i = 7; c3 = 'c'; s = 7; c4 = 'f'; c5 = 'g';
101}
102
103
104/* Test various permutations and interleaving of unsigned integral arguments */
105
106
107call1a (uc, us, ui, ul)
108unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul;
109{
110 uc = 5; us = 6; ui = 7; ul = 8;
111}
112
113call1b (us, ui, ul, uc)
114unsigned short us; unsigned int ui; unsigned long ul; unsigned char uc;
115{
116 uc = 5; us = 6; ui = 7; ul = 8;
117}
118
119call1c (ui, ul, uc, us)
120unsigned int ui; unsigned long ul; unsigned char uc; unsigned short us;
121{
122 uc = 5; us = 6; ui = 7; ul = 8;
123}
124
125call1d (ul, uc, us, ui)
126unsigned long ul; unsigned char uc; unsigned short us; unsigned int ui;
127{
128 uc = 5; us = 6; ui = 7; ul = 8;
129}
130
131call1e (uc1, ul, uc2, ui, uc3, us, uc4, uc5)
132unsigned char uc1; unsigned long ul; unsigned char uc2; unsigned int ui;
133unsigned char uc3; unsigned short us; unsigned char uc4; unsigned char uc5;
134{
135 uc1 = 5; ul = 7; uc2 = 8; ui = 9; uc3 = 10; us = 11; uc4 = 12; uc5 = 55;
136}
137
138/* Test various permutations and interleaving of integral arguments with
139 floating point arguments. */
140
141
142call2a (c, f1, s, d1, i, f2, l, d2)
143char c; float f1; short s; double d1; int i; float f2; long l; double d2;
144{
145 c = 'a'; f1 = 0.0; s = 5; d1 = 0.0; i = 6; f2 = 0.1; l = 7; d2 = 0.2;
146}
147
148call2b (f1, s, d1, i, f2, l, d2, c)
149float f1; short s; double d1; int i; float f2; long l; double d2; char c;
150{
151 c = 'a'; f1 = 0.0; s = 5; d1 = 0.0; i = 6; f2 = 0.1; l = 7; d2 = 0.2;
152}
153
154call2c (s, d1, i, f2, l, d2, c, f1)
155short s; double d1; int i; float f2; long l; double d2; char c; float f1;
156{
157 c = 'a'; f1 = 0.0; s = 5; d1 = 0.0; i = 6; f2 = 0.1; l = 7; d2 = 0.2;
158}
159
160call2d (d1, i, f2, l, d2, c, f1, s)
161double d1; int i; float f2; long l; double d2; char c; float f1; short s;
162{
163 c = 'a'; f1 = 0.0; s = 5; d1 = 0.0; i = 6; f2 = 0.1; l = 7; d2 = 0.2;
164}
165
166call2e (i, f2, l, d2, c, f1, s, d1)
167int i; float f2; long l; double d2; char c; float f1; short s; double d1;
168{
169 c = 'a'; f1 = 0.0; s = 5; d1 = 0.0; i = 6; f2 = 0.1; l = 7; d2 = 0.2;
170}
171
172call2f (f2, l, d2, c, f1, s, d1, i)
173float f2; long l; double d2; char c; float f1; short s; double d1; int i;
174{
175 c = 'a'; f1 = 0.0; s = 5; d1 = 0.0; i = 6; f2 = 0.1; l = 7; d2 = 0.2;
176}
177
178call2g (l, d2, c, f1, s, d1, i, f2)
179long l; double d2; char c; float f1; short s; double d1; int i; float f2;
180{
181 c = 'a'; f1 = 0.0; s = 5; d1 = 0.0; i = 6; f2 = 0.1; l = 7; d2 = 0.2;
182}
183
184call2h (d2, c, f1, s, d1, i, f2, l)
185double d2; char c; float f1; short s; double d1; int i; float f2; long l;
186{
187 c = 'a'; f1 = 0.0; s = 5; d1 = 0.0; i = 6; f2 = 0.1; l = 7; d2 = 0.2;
188}
189
190call2i (c1, f1, c2, c3, d1, c4, c5, c6, f2, s, c7, d2)
191char c1; float f1; char c2; char c3; double d1; char c4; char c5; char c6;
192float f2; short s; char c7; double d2;
193{
194 c1 = 'a'; f1 = 0.0; c2 = 5; d1 = 0.0; c3 = 6; f2 = 0.1; c4 = 7; d2 = 0.2;
195 c5 = 's'; c6 = 'f'; c7 = 'z'; s = 77;
196}
197
198
199/* Test pointers to various integral and floating types. */
200
201
202call3a (cp, sp, ip, lp)
203char *cp; short *sp; int *ip; long *lp;
204{
205 cp = 0; sp = 0; ip = 0; lp = 0;
206}
207
208call3b (ucp, usp, uip, ulp)
209unsigned char *ucp; unsigned short *usp; unsigned int *uip;
210unsigned long *ulp;
211{
212 ucp = 0; usp = 0; uip = 0; ulp = 0;
213}
214
215call3c (fp, dp)
216float *fp; double *dp;
217{
218 fp = 0; dp = 0;
219}
220
221
222/* Test passing structures and unions by reference. */
223
224
225call4a (stp)
226struct stag *stp; {
227stp = 0;}
228
229call4b (unp)
230union utag *unp;
231{
232 unp = 0;
233}
234
235
236/* Test passing structures and unions by value. */
237
238
239call5a (st)
240struct stag st; {st.s1 = 5;}
241
242call5b (un)
243union utag un; {un.u1 = 7;}
244
245
246/* Test shuffling of args */
247
248
249call6a (c, s, i, l, f, d, uc, us, ui, ul)
250char c; short s; int i; long l; float f; double d;
251unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul;
252{
253 c = c;
254 call6b (s, i, l, f, d, uc, us, ui, ul);
255}
256
257call6b (s, i, l, f, d, uc, us, ui, ul)
258short s; int i; long l; float f; double d;
259unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul;
260{
261 s = s;
262 call6c (i, l, f, d, uc, us, ui, ul);
263}
264
265call6c (i, l, f, d, uc, us, ui, ul)
266int i; long l; float f; double d;
267unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul;
268{
269 i = i;
270 call6d (l, f, d, uc, us, ui, ul);
271}
272
273call6d (l, f, d, uc, us, ui, ul)
274long l; float f; double d;
275unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul;
276{
277 l = l;
278 call6e (f, d, uc, us, ui, ul);
279}
280
281call6e (f, d, uc, us, ui, ul)
282float f; double d;
283unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul;
284{
285 f = f;
286 call6f (d, uc, us, ui, ul);
287}
288
289call6f (d, uc, us, ui, ul)
290double d;
291unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul;
292{
293 d = d;
294 call6g (uc, us, ui, ul);
295}
296
297call6g (uc, us, ui, ul)
298unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul;
299{
300 uc = uc;
301 call6h (us, ui, ul);
302}
303
304call6h (us, ui, ul)
305unsigned short us; unsigned int ui; unsigned long ul;
306{
307 us = us;
308 call6i (ui, ul);
309}
310
311call6i (ui, ul)
312unsigned int ui; unsigned long ul;
313{
314 ui = ui;
315 call6j (ul);
316}
317
318call6j (ul)
319unsigned long ul;
320{
321 ul = ul;
322 call6k ();
323}
324
325call6k ()
326{
327}
328
329
330/* Test shuffling of args, round robin */
331
332
333call7a (c, i, s, l, f, uc, d, us, ul, ui)
334char c; int i; short s; long l; float f; unsigned char uc; double d; unsigned short us; unsigned long ul; unsigned int ui;
335{
336 call7b (i, s, l, f, uc, d, us, ul, ui, c);
337}
338
339call7b (i, s, l, f, uc, d, us, ul, ui, c)
340int i; short s; long l; float f; unsigned char uc; double d; unsigned short us; unsigned long ul; unsigned int ui; char c;
341{
342 call7c (s, l, f, uc, d, us, ul, ui, c, i);
343}
344
345call7c (s, l, f, uc, d, us, ul, ui, c, i)
346short s; long l; float f; unsigned char uc; double d; unsigned short us; unsigned long ul; unsigned int ui; char c; int i;
347{
348 call7d (l, f, uc, d, us, ul, ui, c, i, s);
349}
350
351call7d (l, f, uc, d, us, ul, ui, c, i, s)
352long l; float f; unsigned char uc; double d; unsigned short us; unsigned long ul; unsigned int ui; char c; int i; short s;
353{
354 call7e (f, uc, d, us, ul, ui, c, i, s, l);
355}
356
357call7e (f, uc, d, us, ul, ui, c, i, s, l)
358float f; unsigned char uc; double d; unsigned short us; unsigned long ul; unsigned int ui; char c; int i; short s; long l;
359{
360 call7f (uc, d, us, ul, ui, c, i, s, l, f);
361}
362
363call7f (uc, d, us, ul, ui, c, i, s, l, f)
364unsigned char uc; double d; unsigned short us; unsigned long ul; unsigned int ui; char c; int i; short s; long l; float f;
365{
366 call7g (d, us, ul, ui, c, i, s, l, f, uc);
367}
368
369call7g (d, us, ul, ui, c, i, s, l, f, uc)
370double d; unsigned short us; unsigned long ul; unsigned int ui; char c; int i; short s; long l; float f; unsigned char uc;
371{
372 call7h (us, ul, ui, c, i, s, l, f, uc, d);
373}
374
375call7h (us, ul, ui, c, i, s, l, f, uc, d)
376unsigned short us; unsigned long ul; unsigned int ui; char c; int i; short s; long l; float f; unsigned char uc; double d;
377{
378 call7i (ul, ui, c, i, s, l, f, uc, d, us);
379}
380
381call7i (ul, ui, c, i, s, l, f, uc, d, us)
382unsigned long ul; unsigned int ui; char c; int i; short s; long l; float f; unsigned char uc; double d; unsigned short us;
383{
384 call7j (ui, c, i, s, l, f, uc, d, us, ul);
385}
386
387call7j (ui, c, i, s, l, f, uc, d, us, ul)
388unsigned int ui; char c; int i; short s; long l; float f; unsigned char uc; double d; unsigned short us; unsigned long ul;
389{
390 call7k (c, i, s, l, f, uc, d, us, ul, ui);
391}
392
393call7k (c, i, s, l, f, uc, d, us, ul, ui)
394char c; int i; short s; long l; float f; unsigned char uc; double d; unsigned short us; unsigned long ul; unsigned int ui;
395{
396 c = 'a'; i = 7; s = 8; l = 7; f = 0.3; uc = 44; d = 0.44; us = 77;
397 ul = 43; ui = 33;
398}
399
400
401/* Test printing of structures passed as arguments to recursive functions. */
402
403
404typedef struct s
405{
406 short s;
407 int i;
408 long l;
409} SVAL;
410
411hitbottom ()
412{
413}
414
415void recurse (a, depth)
416SVAL a;
417int depth;
418{
419 a.s = a.i = a.l = --depth;
420 if (depth == 0)
421 hitbottom ();
422 else
423 recurse (a, depth);
424}
425
426test_struct_args ()
427{
428 SVAL s; s.s = 5; s.i = 5; s.l = 5;
429
430 recurse (s, 5);
431}
432
433/* On various machines (pa, 29k, and rs/6000, at least), a function which
434 calls alloca may do things differently with respect to frames. So give
435 it a try. */
436
437int
438localvars_after_alloca (c, s, i, l)
439 char c;
440 short s;
441 int i;
442 long l;
443{
444#ifdef HAVE_STACK_ALLOCA
445 /* No need to use the alloca.c alloca-on-top-of-malloc; it doesn't
446 test what we are looking for, so if we don't have an alloca which
447 allocates on the stack, just don't bother to call alloca at all. */
448
449 char *z = alloca (s + 50);
450#endif
451 c = 'a';
452 s = 5;
453 i = 6;
454 l = 7;
455}
456\f
457
458/* The point behind this test is the PA will call this indirectly
459 through dyncall. Unlike the indirect calls to call0a, this test
460 will require a trampoline between dyncall and this function on the
461 call path, then another trampoline on between this function and main
462 on the return path. */
463double
464call_with_trampolines (d1)
465double d1;
466{
467 return d1;
468} /* End of call_with_trampolines, this comment is needed by funcargs.exp */
469
470/* Dummy functions which the testsuite can use to run to, etc. */
471
472void
473marker_indirect_call () {}
474
475void
476marker_call_with_trampolines () {}
477\f
478main ()
479{
480 int (*pointer_to_call0a) () = call0a;
481 double (*pointer_to_call_with_trampolines) () = call_with_trampolines;
482
483 /* Test calling with basic integer types */
484 call0a (c, s, i, l);
485 call0b (s, i, l, c);
486 call0c (i, l, c, s);
487 call0d (l, c, s, i);
488 call0e (c, l, c, i, c, s, c, c);
489
490 /* Test calling with unsigned integer types */
491 call1a (uc, us, ui, ul);
492 call1b (us, ui, ul, uc);
493 call1c (ui, ul, uc, us);
494 call1d (ul, uc, us, ui);
495 call1e (uc, ul, uc, ui, uc, us, uc, uc);
496
497 /* Test calling with integral types mixed with floating point types */
498 call2a (c, f, s, d, i, f, l, d);
499 call2b (f, s, d, i, f, l, d, c);
500 call2c (s, d, i, f, l, d, c, f);
501 call2d (d, i, f, l, d, c, f, s);
502 call2e (i, f, l, d, c, f, s, d);
503 call2f (f, l, d, c, f, s, d, i);
504 call2g (l, d, c, f, s, d, i, f);
505 call2h (d, c, f, s, d, i, f, l);
506 call2i (c, f, c, c, d, c, c, c, f, s, c, d);;
507
508 /* Test dereferencing pointers to various integral and floating types */
509
510 call3a (cp, sp, ip, lp);
511 call3b (ucp, usp, uip, ulp);
512 call3c (fp, dp);
513
514 /* Test dereferencing pointers to structs and unions */
515
516 call4a (stp);
517 un.u1 = 1;
518 call4b (unp);
519
520 /* Test calling with structures and unions. */
521
522 call5a (st);
523 un.u1 = 2;
524 call5b (un);
525
526 /* Test shuffling of args */
527
528 call6a (c, s, i, l, f, d, uc, us, ui, ul);
529 call7a (c, i, s, l, f, uc, d, us, ul, ui);
530
531 /* Test passing structures recursively. */
532
533 test_struct_args ();
534
535 localvars_after_alloca (c, s, i, l);
536
537 /* This is for localvars_in_indirect_call. */
538 marker_indirect_call ();
539 /* The comment on the following two lines is used by funcargs.exp,
540 don't change it. */
541 (*pointer_to_call0a) (c, s, i, l); /* First step into call0a. */
542 (*pointer_to_call0a) (c, s, i, l); /* Second step into call0a. */
543 marker_call_with_trampolines ();
544 (*pointer_to_call_with_trampolines) (d); /* Test multiple trampolines. */
545}