]> git.lizzy.rs Git - rust.git/blob - src/test/run-make/extern-fn-struct-passing-abi/test.c
Rollup merge of #41249 - GuillaumeGomez:rustdoc-render, r=steveklabnik,frewsxcv
[rust.git] / src / test / run-make / extern-fn-struct-passing-abi / test.c
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #include <assert.h>
12 #include <stdint.h>
13
14 struct Rect {
15     int32_t a;
16     int32_t b;
17     int32_t c;
18     int32_t d;
19 };
20
21 struct BiggerRect {
22     struct Rect s;
23     int32_t a;
24     int32_t b;
25 };
26
27 struct FloatRect {
28     int32_t a;
29     int32_t b;
30     double c;
31 };
32
33 struct Huge {
34     int32_t a;
35     int32_t b;
36     int32_t c;
37     int32_t d;
38     int32_t e;
39 };
40
41 struct FloatPoint {
42     double x;
43     double y;
44 };
45
46 // System V x86_64 ABI:
47 // a, b, c, d, e should be in registers
48 // s should be byval pointer
49 //
50 // Win64 ABI:
51 // a, b, c, d should be in registers
52 // e should be on the stack
53 // s should be byval pointer
54 void byval_rect(int32_t a, int32_t b, int32_t c, int32_t d, int32_t e, struct Rect s) {
55     assert(a == 1);
56     assert(b == 2);
57     assert(c == 3);
58     assert(d == 4);
59     assert(e == 5);
60     assert(s.a == 553);
61     assert(s.b == 554);
62     assert(s.c == 555);
63     assert(s.d == 556);
64 }
65
66 // System V x86_64 ABI:
67 // a, b, c, d, e, f should be in registers
68 // s should be byval pointer on the stack
69 //
70 // Win64 ABI:
71 // a, b, c, d should be in registers
72 // e, f should be on the stack
73 // s should be byval pointer on the stack
74 void byval_many_rect(int32_t a, int32_t b, int32_t c, int32_t d, int32_t e,
75                      int32_t f, struct Rect s) {
76     assert(a == 1);
77     assert(b == 2);
78     assert(c == 3);
79     assert(d == 4);
80     assert(e == 5);
81     assert(f == 6);
82     assert(s.a == 553);
83     assert(s.b == 554);
84     assert(s.c == 555);
85     assert(s.d == 556);
86 }
87
88 // System V x86_64 ABI:
89 // a, b, c, d, e, f, g should be in sse registers
90 // s should be split across 2 registers
91 // t should be byval pointer
92 //
93 // Win64 ABI:
94 // a, b, c, d should be in sse registers
95 // e, f, g should be on the stack
96 // s should be on the stack (treated as 2 i64's)
97 // t should be on the stack (treated as an i64 and a double)
98 void byval_rect_floats(float a, float b, double c, float d, float e,
99                        float f, double g, struct Rect s, struct FloatRect t) {
100     assert(a == 1.);
101     assert(b == 2.);
102     assert(c == 3.);
103     assert(d == 4.);
104     assert(e == 5.);
105     assert(f == 6.);
106     assert(g == 7.);
107     assert(s.a == 553);
108     assert(s.b == 554);
109     assert(s.c == 555);
110     assert(s.d == 556);
111     assert(t.a == 3489);
112     assert(t.b == 3490);
113     assert(t.c == 8.);
114 }
115
116 // System V x86_64 ABI:
117 // a, b, d, e, f should be in registers
118 // c passed via sse registers
119 // s should be byval pointer
120 //
121 // Win64 ABI:
122 // a, b, d should be in registers
123 // c passed via sse registers
124 // e, f should be on the stack
125 // s should be byval pointer
126 void byval_rect_with_float(int32_t a, int32_t b, float c, int32_t d,
127                            int32_t e, int32_t f, struct Rect s) {
128     assert(a == 1);
129     assert(b == 2);
130     assert(c == 3.);
131     assert(d == 4);
132     assert(e == 5);
133     assert(f == 6);
134     assert(s.a == 553);
135     assert(s.b == 554);
136     assert(s.c == 555);
137     assert(s.d == 556);
138 }
139
140 // System V x86_64 & Win64 ABI:
141 // a, b should be in registers
142 // s should be split across 2 integer registers
143 void split_rect(int32_t a, int32_t b, struct Rect s) {
144     assert(a == 1);
145     assert(b == 2);
146     assert(s.a == 553);
147     assert(s.b == 554);
148     assert(s.c == 555);
149     assert(s.d == 556);
150 }
151
152 // System V x86_64 & Win64 ABI:
153 // a, b should be in sse registers
154 // s should be split across integer & sse registers
155 void split_rect_floats(float a, float b, struct FloatRect s) {
156     assert(a == 1.);
157     assert(b == 2.);
158     assert(s.a == 3489);
159     assert(s.b == 3490);
160     assert(s.c == 8.);
161 }
162
163 // System V x86_64 ABI:
164 // a, b, d, f should be in registers
165 // c, e passed via sse registers
166 // s should be split across 2 registers
167 //
168 // Win64 ABI:
169 // a, b, d should be in registers
170 // c passed via sse registers
171 // e, f should be on the stack
172 // s should be on the stack (treated as 2 i64's)
173 void split_rect_with_floats(int32_t a, int32_t b, float c,
174                             int32_t d, float e, int32_t f, struct Rect s) {
175     assert(a == 1);
176     assert(b == 2);
177     assert(c == 3.);
178     assert(d == 4);
179     assert(e == 5.);
180     assert(f == 6);
181     assert(s.a == 553);
182     assert(s.b == 554);
183     assert(s.c == 555);
184     assert(s.d == 556);
185 }
186
187 // System V x86_64 & Win64 ABI:
188 // a, b, c should be in registers
189 // s should be split across 2 registers
190 // t should be a byval pointer
191 void split_and_byval_rect(int32_t a, int32_t b, int32_t c, struct Rect s, struct Rect t) {
192     assert(a == 1);
193     assert(b == 2);
194     assert(c == 3);
195     assert(s.a == 553);
196     assert(s.b == 554);
197     assert(s.c == 555);
198     assert(s.d == 556);
199     assert(t.a == 553);
200     assert(t.b == 554);
201     assert(t.c == 555);
202     assert(t.d == 556);
203 }
204
205 // System V x86_64 & Win64 ABI:
206 // a, b should in registers
207 // s and return should be split across 2 registers
208 struct Rect split_ret_byval_struct(int32_t a, int32_t b, struct Rect s) {
209     assert(a == 1);
210     assert(b == 2);
211     assert(s.a == 553);
212     assert(s.b == 554);
213     assert(s.c == 555);
214     assert(s.d == 556);
215     return s;
216 }
217
218 // System V x86_64 & Win64 ABI:
219 // a, b, c, d should be in registers
220 // return should be in a hidden sret pointer
221 // s should be a byval pointer
222 struct BiggerRect sret_byval_struct(int32_t a, int32_t b, int32_t c, int32_t d, struct Rect s) {
223     assert(a == 1);
224     assert(b == 2);
225     assert(c == 3);
226     assert(d == 4);
227     assert(s.a == 553);
228     assert(s.b == 554);
229     assert(s.c == 555);
230     assert(s.d == 556);
231
232     struct BiggerRect t;
233     t.s = s; t.a = 27834; t.b = 7657;
234     return t;
235 }
236
237 // System V x86_64 & Win64 ABI:
238 // a, b should be in registers
239 // return should be in a hidden sret pointer
240 // s should be split across 2 registers
241 struct BiggerRect sret_split_struct(int32_t a, int32_t b, struct Rect s) {
242     assert(a == 1);
243     assert(b == 2);
244     assert(s.a == 553);
245     assert(s.b == 554);
246     assert(s.c == 555);
247     assert(s.d == 556);
248
249     struct BiggerRect t;
250     t.s = s; t.a = 27834; t.b = 7657;
251     return t;
252 }
253
254 // System V x86_64 & Win64 ABI:
255 // s should be byval pointer (since sizeof(s) > 16)
256 // return should in a hidden sret pointer
257 struct Huge huge_struct(struct Huge s) {
258     assert(s.a == 5647);
259     assert(s.b == 5648);
260     assert(s.c == 5649);
261     assert(s.d == 5650);
262     assert(s.e == 5651);
263
264     return s;
265 }
266
267 // System V x86_64 ABI:
268 // p should be in registers
269 // return should be in registers
270 //
271 // Win64 ABI:
272 // p should be a byval pointer
273 // return should be in a hidden sret pointer
274 struct FloatPoint float_point(struct FloatPoint p) {
275     assert(p.x == 5.);
276     assert(p.y == -3.);
277
278     return p;
279 }