]> git.lizzy.rs Git - rust.git/blob - tests/run-make/raw-dylib-alt-calling-convention/extern.c
Move /src/test to /tests
[rust.git] / tests / run-make / raw-dylib-alt-calling-convention / extern.c
1 #include <stdio.h>
2 #include <stdint.h>
3
4 struct S {
5     uint8_t x;
6     int32_t y;
7 };
8
9 struct S2 {
10     int32_t x;
11     uint8_t y;
12 };
13
14 struct S3 {
15     uint8_t x[5];
16 };
17
18 __declspec(dllexport) void __stdcall stdcall_fn_1(int i) {
19     printf("stdcall_fn_1(%d)\n", i);
20     fflush(stdout);
21 }
22
23 __declspec(dllexport) void __stdcall stdcall_fn_2(uint8_t i, float f) {
24     printf("stdcall_fn_2(%d, %.1f)\n", i, f);
25     fflush(stdout);
26 }
27
28 __declspec(dllexport) void __stdcall stdcall_fn_3(double d) {
29     printf("stdcall_fn_3(%.1f)\n", d);
30     fflush(stdout);
31 }
32
33 __declspec(dllexport) void __stdcall stdcall_fn_4(uint8_t i, uint8_t j, float f) {
34     printf("stdcall_fn_4(%d, %d, %.1f)\n", i, j, f);
35     fflush(stdout);
36 }
37
38 __declspec(dllexport) void __stdcall stdcall_fn_5(struct S s, int i) {
39     printf("stdcall_fn_5(S { x: %d, y: %d }, %d)\n", s.x, s.y, i);
40     fflush(stdout);
41 }
42
43 // Test that stdcall support works correctly with the nullable pointer optimization.
44 __declspec(dllexport) void __stdcall stdcall_fn_6(struct S* s) {
45     if (s) {
46         printf("stdcall_fn_6(S { x: %d, y: %d })\n", s->x, s->y);
47     } else {
48         printf("stdcall_fn_6(null)\n");
49     }
50     fflush(stdout);
51 }
52
53 __declspec(dllexport) void __stdcall stdcall_fn_7(struct S2 s, int i) {
54     printf("stdcall_fn_7(S2 { x: %d, y: %d }, %d)\n", s.x, s.y, i);
55     fflush(stdout);
56 }
57
58 // Verify that we compute the correct amount of space in the argument list for a 5-byte struct.
59 __declspec(dllexport) void __stdcall stdcall_fn_8(struct S3 s, struct S3 t) {
60     printf("stdcall_fn_8(S3 { x: [%d, %d, %d, %d, %d] }, S3 { x: [%d, %d, %d, %d, %d] })\n",
61            s.x[0], s.x[1], s.x[2], s.x[3], s.x[4],
62            t.x[0], t.x[1], t.x[2], t.x[3], t.x[4]
63         );
64     fflush(stdout);
65 }
66
67 // test whether f64/double values are aligned on 4-byte or 8-byte boundaries.
68 __declspec(dllexport) void __stdcall stdcall_fn_9(uint8_t x, double y) {
69     printf("stdcall_fn_9(%d, %.1f)\n", x, y);
70     fflush(stdout);
71 }
72
73 __declspec(dllexport) void __stdcall stdcall_fn_10(int i) {
74     printf("stdcall_fn_10(%d)\n", i);
75     fflush(stdout);
76 }
77
78 __declspec(dllexport) void __fastcall fastcall_fn_1(int i) {
79     printf("fastcall_fn_1(%d)\n", i);
80     fflush(stdout);
81 }
82
83 __declspec(dllexport) void __fastcall fastcall_fn_2(uint8_t i, float f) {
84     printf("fastcall_fn_2(%d, %.1f)\n", i, f);
85     fflush(stdout);
86 }
87
88 __declspec(dllexport) void __fastcall fastcall_fn_3(double d) {
89     printf("fastcall_fn_3(%.1f)\n", d);
90     fflush(stdout);
91 }
92
93 __declspec(dllexport) void __fastcall fastcall_fn_4(uint8_t i, uint8_t j, float f) {
94     printf("fastcall_fn_4(%d, %d, %.1f)\n", i, j, f);
95     fflush(stdout);
96 }
97
98 __declspec(dllexport) void __fastcall fastcall_fn_5(struct S s, int i) {
99     printf("fastcall_fn_5(S { x: %d, y: %d }, %d)\n", s.x, s.y, i);
100     fflush(stdout);
101 }
102
103 __declspec(dllexport) void __fastcall fastcall_fn_6(struct S* s) {
104     if (s) {
105         printf("fastcall_fn_6(S { x: %d, y: %d })\n", s->x, s->y);
106     } else {
107         printf("fastcall_fn_6(null)\n");
108     }
109     fflush(stdout);
110 }
111
112 __declspec(dllexport) void __fastcall fastcall_fn_7(struct S2 s, int i) {
113     printf("fastcall_fn_7(S2 { x: %d, y: %d }, %d)\n", s.x, s.y, i);
114     fflush(stdout);
115 }
116
117 __declspec(dllexport) void __fastcall fastcall_fn_8(struct S3 s, struct S3 t) {
118     printf("fastcall_fn_8(S3 { x: [%d, %d, %d, %d, %d] }, S3 { x: [%d, %d, %d, %d, %d] })\n",
119            s.x[0], s.x[1], s.x[2], s.x[3], s.x[4],
120            t.x[0], t.x[1], t.x[2], t.x[3], t.x[4]
121         );
122     fflush(stdout);
123 }
124
125 __declspec(dllexport) void __fastcall fastcall_fn_9(uint8_t x, double y) {
126     printf("fastcall_fn_9(%d, %.1f)\n", x, y);
127     fflush(stdout);
128 }
129
130 __declspec(dllexport) void __fastcall fastcall_fn_10(int i) {
131     printf("fastcall_fn_10(%d)\n", i);
132     fflush(stdout);
133 }
134
135 // GCC doesn't support vectorcall: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89485
136 #ifdef _MSC_VER
137 __declspec(dllexport) void __vectorcall vectorcall_fn_1(int i) {
138     printf("vectorcall_fn_1(%d)\n", i);
139     fflush(stdout);
140 }
141
142 __declspec(dllexport) void __vectorcall vectorcall_fn_2(uint8_t i, float f) {
143     printf("vectorcall_fn_2(%d, %.1f)\n", i, f);
144     fflush(stdout);
145 }
146
147 __declspec(dllexport) void __vectorcall vectorcall_fn_3(double d) {
148     printf("vectorcall_fn_3(%.1f)\n", d);
149     fflush(stdout);
150 }
151
152 __declspec(dllexport) void __vectorcall vectorcall_fn_4(uint8_t i, uint8_t j, float f) {
153     printf("vectorcall_fn_4(%d, %d, %.1f)\n", i, j, f);
154     fflush(stdout);
155 }
156
157 __declspec(dllexport) void __vectorcall vectorcall_fn_5(struct S s, int i) {
158     printf("vectorcall_fn_5(S { x: %d, y: %d }, %d)\n", s.x, s.y, i);
159     fflush(stdout);
160 }
161
162 __declspec(dllexport) void __vectorcall vectorcall_fn_6(struct S* s) {
163     if (s) {
164         printf("vectorcall_fn_6(S { x: %d, y: %d })\n", s->x, s->y);
165     } else {
166         printf("vectorcall_fn_6(null)\n");
167     }
168     fflush(stdout);
169 }
170
171 __declspec(dllexport) void __vectorcall vectorcall_fn_7(struct S2 s, int i) {
172     printf("vectorcall_fn_7(S2 { x: %d, y: %d }, %d)\n", s.x, s.y, i);
173     fflush(stdout);
174 }
175
176 __declspec(dllexport) void __vectorcall vectorcall_fn_8(struct S3 s, struct S3 t) {
177     printf("vectorcall_fn_8(S3 { x: [%d, %d, %d, %d, %d] }, S3 { x: [%d, %d, %d, %d, %d] })\n",
178            s.x[0], s.x[1], s.x[2], s.x[3], s.x[4],
179            t.x[0], t.x[1], t.x[2], t.x[3], t.x[4]
180         );
181     fflush(stdout);
182 }
183
184 __declspec(dllexport) void __vectorcall vectorcall_fn_9(uint8_t x, double y) {
185     printf("vectorcall_fn_9(%d, %.1f)\n", x, y);
186     fflush(stdout);
187 }
188
189 __declspec(dllexport) void __vectorcall vectorcall_fn_10(int i) {
190     printf("vectorcall_fn_10(%d)\n", i);
191     fflush(stdout);
192 }
193 #endif