1 /* This test has architecture specific function passing details.  */
2 /* { dg-do compile } */
3 /* { dg-options "-O2 -fdump-tree-stdarg" } */
4 
5 #include <stdarg.h>
6 
7 extern void foo (int, va_list);
8 extern void bar (int);
9 struct S1 { int i; double d; int j; double e; } s1;
10 struct S2 { double d; long i; } s2;
11 int y;
12 _Complex int ci;
13 _Complex double cd;
14 
15 /* Here va_arg can be executed more than once for one va_start.  */
16 void
f1(int i,...)17 f1 (int i, ...)
18 {
19   va_list ap;
20   va_start (ap, i);
21   while (i-- > 0)
22     s1 = va_arg (ap, struct S1);
23   va_end (ap);
24 }
25 /* { dg-final { scan-tree-dump "f1: va_list escapes 0, needs to save 0 GPR units and 0 FPR units" "stdarg" { target { { i?86-*-* x86_64-*-* } && { ! { ia32 || llp64 } } } } } } */
26 /* { dg-final { scan-tree-dump "f1: va_list escapes 0, needs to save all GPR units and 1" "stdarg" { target alpha*-*-linux* } } } */
27 /* { dg-final { scan-tree-dump "f1: va_list escapes 0, needs to save all GPR units and 0 FPR units" "stdarg" { target s390*-*-linux* } } } */
28 /* { dg-final { scan-tree-dump "f1: va_list escapes 0, needs to save all GPR units and 0 FPR units" "stdarg" { target aarch64*-*-* } } } */
29 
30 void
f2(int i,...)31 f2 (int i, ...)
32 {
33   va_list ap;
34   va_start (ap, i);
35   while (i-- > 0)
36     s2 = va_arg (ap, struct S2);
37   va_end (ap);
38 }
39 /* { dg-final { scan-tree-dump "f2: va_list escapes 0, needs to save all GPR units and all FPR units" "stdarg" { target { { i?86-*-* x86_64-*-* } && { ! { ia32 || llp64 } } } } } } */
40 /* { dg-final { scan-tree-dump "f2: va_list escapes 0, needs to save all GPR units and 1" "stdarg" { target alpha*-*-linux* } } } */
41 /* { dg-final { scan-tree-dump "f2: va_list escapes 0, needs to save all GPR units and 0 FPR units" "stdarg" { target s390*-*-linux* } } } */
42 /* { dg-final { scan-tree-dump "f2: va_list escapes 0, needs to save all GPR units and 0 FPR units" "stdarg" { target aarch64*-*-* } } } */
43 
44 /* Here va_arg can be executed at most as many times as va_start.  */
45 void
f3(int i,...)46 f3 (int i, ...)
47 {
48   va_list ap;
49   int j = i;
50   while (j-- > 0)
51     {
52       va_start (ap, i);
53       s1 = va_arg (ap, struct S1);
54       va_end (ap);
55       bar (s1.i);
56     }
57 }
58 /* { dg-final { scan-tree-dump "f3: va_list escapes 0, needs to save 0 GPR units and 0 FPR units" "stdarg" { target { { i?86-*-* x86_64-*-* } && { ! { ia32 || llp64 } } } } } } */
59 /* { dg-final { scan-tree-dump "f3: va_list escapes 0, needs to save 32 GPR units and 1" "stdarg" { target alpha*-*-linux* } } } */
60 /* { dg-final { scan-tree-dump "f3: va_list escapes 0, needs to save 1 GPR units and 0 FPR units" "stdarg" { target s390*-*-linux* } } } */
61 /* { dg-final { scan-tree-dump "f3: va_list escapes 0, needs to save 8 GPR units and 0 FPR units" "stdarg" { target aarch64*-*-* } } } */
62 
63 void
f4(int i,...)64 f4 (int i, ...)
65 {
66   va_list ap;
67   int j = i;
68   while (j-- > 0)
69     {
70       va_start (ap, i);
71       s2 = va_arg (ap, struct S2);
72       y = va_arg (ap, int);
73       va_end (ap);
74       bar (s2.i);
75     }
76 }
77 /* { dg-final { scan-tree-dump "f4: va_list escapes 0, needs to save 16 GPR units and 16 FPR units" "stdarg" { target { { i?86-*-* x86_64-*-* } && { ! { ia32 || llp64 } } } } } } */
78 /* { dg-final { scan-tree-dump "f4: va_list escapes 0, needs to save 24 GPR units and 1" "stdarg" { target alpha*-*-linux* } } } */
79 /* { dg-final { scan-tree-dump "f4: va_list escapes 0, needs to save 2 GPR units and 0 FPR units" "stdarg" { target s390*-*-linux* } } } */
80 /* { dg-final { scan-tree-dump "f4: va_list escapes 0, needs to save 24 GPR units and 0 FPR units" "stdarg" { target aarch64*-*-* } } } */
81 
82 void
f5(int i,...)83 f5 (int i, ...)
84 {
85   va_list ap;
86   va_start (ap, i);
87   ci = va_arg (ap, _Complex int);
88   ci += va_arg (ap, _Complex int);
89   va_end (ap);
90   bar (__real__ ci + __imag__ ci);
91 }
92 /* { dg-final { scan-tree-dump "f5: va_list escapes 0, needs to save 16 GPR units and 0 FPR units" "stdarg" { target { { i?86-*-* x86_64-*-* } && { ! { ia32 || llp64 } } } } } } */
93 /* { dg-final { scan-tree-dump "f5: va_list escapes 0, needs to save 32 GPR units and 1" "stdarg" { target alpha*-*-linux* } } } */
94 /* { dg-final { scan-tree-dump "f5: va_list escapes 0, needs to save (4|2) GPR units and 0 FPR units" "stdarg" { target s390*-*-linux* } } } */
95 /* { dg-final { scan-tree-dump "f5: va_list escapes 0, needs to save 16 GPR units and 0 FPR units" "stdarg" { target aarch64*-*-* } } } */
96 
97 void
f6(int i,...)98 f6 (int i, ...)
99 {
100   va_list ap;
101   va_start (ap, i);
102   ci = va_arg (ap, _Complex int);
103   cd = va_arg (ap, _Complex double);
104   va_end (ap);
105   bar (__real__ ci + __imag__ cd);
106 }
107 /* { dg-final { scan-tree-dump "f6: va_list escapes 0, needs to save 8 GPR units and 32 FPR units" "stdarg" { target { { i?86-*-* x86_64-*-* } && { ! { ia32 || llp64 } } } } } } */
108 /* { dg-final { scan-tree-dump "f6: va_list escapes 0, needs to save 32 GPR units and 3" "stdarg" { target alpha*-*-linux* } } } */
109 /* { dg-final { scan-tree-dump "f6: va_list escapes 0, needs to save (3|2) GPR units and 0 FPR units" "stdarg" { target s390*-*-linux* } } } */
110 /* { dg-final { scan-tree-dump "f6: va_list escapes 0, needs to save 8 GPR units and 32 FPR units" "stdarg" { target aarch64*-*-* } } } */
111 
112 void
f7(int i,...)113 f7 (int i, ...)
114 {
115   va_list ap;
116   va_start (ap, i);
117   cd = va_arg (ap, _Complex double);
118   cd += va_arg (ap, _Complex double);
119   va_end (ap);
120   bar (__real__ cd + __imag__ cd);
121 }
122 /* { dg-final { scan-tree-dump "f7: va_list escapes 0, needs to save 0 GPR units and 64 FPR units" "stdarg" { target { { i?86-*-* x86_64-*-* } && { ! { ia32 || llp64 } } } } } } */
123 /* { dg-final { scan-tree-dump "f7: va_list escapes 0, needs to save 32 GPR units and 2" "stdarg" { target alpha*-*-linux* } } } */
124 /* { dg-final { scan-tree-dump "f7: va_list escapes 0, needs to save 2 GPR units and 0 FPR units" "stdarg" { target s390*-*-linux* } } } */
125 /* { dg-final { scan-tree-dump "f7: va_list escapes 0, needs to save 0 GPR units and 64 FPR units" "stdarg" { target aarch64*-*-* } } } */
126