1 /* Test call argument ABI: passing structs */
2
3 /* { dg-do run } */
4
5 #include <stdarg.h>
6
7 extern void abort (void);
8
9 struct S3 { char a[3]; };
10 struct S7 { char a[7]; };
11 struct S8 { char a[8]; };
12
13 struct S3 gs3 = {{11, 22, 33}};
14 struct S7 gs7 = {{1, 2, 3, 4, 5, 6, 7}};
15 struct S8 gs8 = {{1, 2, 3, 4, 5, 6, 7, 8}};
16
17 int test3_struct(char a0, char a1, char a2, char a3,
18 char a4, char a5, char a6, char a7,
19 char a8, char a9, char a10, char a11,
20 int ai)
21 {
22 if (a0 != 11) return 1;
23 if (a1 != 22) return 2;
24 if (a2 != 33) return 3;
25 if (a4 != 101) return 4;
26 if (a5 != 111) return 5;
27 if (a6 != 121) return 6;
28 if (a8 != 55) return 8;
29 if (a9 != 66) return 9;
30 if (a10 != 77) return 10;
31
32 if (ai != 55443322) return 100;
33
34 return 0;
35 }
36
37 void test3(void)
38 {
39 struct S3 s3x = { {101, 111, 121} };
40 struct S3 s3y = { {55, 66, 77} };
41
42 int (* volatile f)(struct S3, struct S3, struct S3, int) =
43 (int (* volatile)(struct S3, struct S3, struct S3, int)) test3_struct;
44
45 if (f(gs3, s3x, s3y, 55443322))
46 abort();
47 }
48
49 int test7_struct(unsigned ai, struct S7 a0, ...)
50 {
51 va_list ap;
52 struct S7 s[3];
53 int i;
54
55 va_start (ap, a0);
56
57 s[0] = a0;
58 for (i = 1; i < 3; i++) {
59 s[i] = va_arg (ap, struct S7);
60 }
61
62 va_end (ap);
63
64 if (ai != 0xaabbccdd)
65 return 1;
66
67 if (s[0].a[0] != 1) return 1;
68 if (s[0].a[1] != 2) return 1;
69 if (s[0].a[2] != 3) return 1;
70 if (s[0].a[3] != 4) return 1;
71 if (s[0].a[4] != 5) return 1;
72 if (s[0].a[5] != 6) return 1;
73 if (s[0].a[6] != 7) return 1;
74
75 if (s[1].a[0] != 11) return 1;
76 if (s[1].a[1] != 12) return 1;
77 if (s[1].a[2] != 13) return 1;
78 if (s[1].a[3] != 14) return 1;
79 if (s[1].a[4] != 15) return 1;
80 if (s[1].a[5] != 16) return 1;
81 if (s[1].a[6] != 17) return 1;
82
83 if (s[2].a[0] != 22) return 1;
84 if (s[2].a[1] != 23) return 1;
85 if (s[2].a[2] != 24) return 1;
86 if (s[2].a[3] != 25) return 1;
87 if (s[2].a[4] != 26) return 1;
88 if (s[2].a[5] != 27) return 1;
89 if (s[2].a[6] != 28) return 1;
90
91 return 0;
92 }
93
94 void test7(void)
95 {
96 struct S7 s7x = { {11, 12, 13, 14, 15, 16, 17} };
97 struct S7 s7y = { {22, 23, 24, 25, 26, 27, 28} };
98
99 int (* volatile f)(unsigned, struct S7, struct S7, struct S7) =
100 (int (* volatile)(unsigned, struct S7, struct S7, struct S7)) test7_struct;
101
102 if (f(0xaabbccdd, gs7, s7x, s7y))
103 abort();
104 }
105
106 int test8_struct(char a0, char a1, char a2, char a3,
107 char a4, char a5, char a6, char a7,
108 char a8, char a9, char a10, char a11,
109 char a12, char a13, char a14, char a15,
110 char a16, char a17, char a18, char a19,
111 char a20, char a21, char a22, char a23)
112 {
113 if (a0 != 1) return 1;
114 if (a1 != 2) return 1;
115 if (a2 != 3) return 1;
116 if (a3 != 4) return 1;
117 if (a4 != 5) return 1;
118 if (a5 != 6) return 1;
119 if (a6 != 7) return 1;
120 if (a7 != 8) return 1;
121
122 if (a8 != 11) return 1;
123 if (a9 != 12) return 1;
124 if (a10 != 13) return 1;
125 if (a11 != 14) return 1;
126 if (a12 != 15) return 1;
127 if (a13 != 16) return 1;
128 if (a14 != 17) return 1;
129 if (a15 != 18) return 1;
130
131 if (a16 != 22) return 1;
132 if (a17 != 23) return 1;
133 if (a18 != 24) return 1;
134 if (a19 != 25) return 1;
135 if (a20 != 26) return 1;
136 if (a21 != 27) return 1;
137 if (a22 != 28) return 1;
138 if (a23 != 29) return 1;
139
140 return 0;
141 }
142
143 void test8(void)
144 {
145 struct S8 s8x = { {11, 12, 13, 14, 15, 16, 17, 18} };
146 struct S8 s8y = { {22, 23, 24, 25, 26, 27, 28, 29} };
147
148 int (* volatile f)(struct S8, struct S8, struct S8) =
149 (int (* volatile)(struct S8, struct S8, struct S8)) test8_struct;
150
151 if (f(gs8, s8x, s8y))
152 abort();
153 }
154
155 int
156 main (int argc, char** argv)
157 {
158 test3();
159 test7();
160 test8();
161
162 return 0;
163 }
164