]> git.lizzy.rs Git - rust.git/blob - src/test/run-make/raw-dylib-alt-calling-convention/extern.c
0c4d12af9b2ca62a3fa10d407408211a2c9a7c0a
[rust.git] / src / test / 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 __fastcall fastcall_fn_1(int i) {
74     printf("fastcall_fn_1(%d)\n", i);
75     fflush(stdout);
76 }
77
78 __declspec(dllexport) void __fastcall fastcall_fn_2(uint8_t i, float f) {
79     printf("fastcall_fn_2(%d, %.1f)\n", i, f);
80     fflush(stdout);
81 }
82
83 __declspec(dllexport) void __fastcall fastcall_fn_3(double d) {
84     printf("fastcall_fn_3(%.1f)\n", d);
85     fflush(stdout);
86 }
87
88 __declspec(dllexport) void __fastcall fastcall_fn_4(uint8_t i, uint8_t j, float f) {
89     printf("fastcall_fn_4(%d, %d, %.1f)\n", i, j, f);
90     fflush(stdout);
91 }
92
93 __declspec(dllexport) void __fastcall fastcall_fn_5(struct S s, int i) {
94     printf("fastcall_fn_5(S { x: %d, y: %d }, %d)\n", s.x, s.y, i);
95     fflush(stdout);
96 }
97
98 __declspec(dllexport) void __fastcall fastcall_fn_6(struct S* s) {
99     if (s) {
100         printf("fastcall_fn_6(S { x: %d, y: %d })\n", s->x, s->y);
101     } else {
102         printf("fastcall_fn_6(null)\n");
103     }
104     fflush(stdout);
105 }
106
107 __declspec(dllexport) void __fastcall fastcall_fn_7(struct S2 s, int i) {
108     printf("fastcall_fn_7(S2 { x: %d, y: %d }, %d)\n", s.x, s.y, i);
109     fflush(stdout);
110 }
111
112 __declspec(dllexport) void __fastcall fastcall_fn_8(struct S3 s, struct S3 t) {
113     printf("fastcall_fn_8(S3 { x: [%d, %d, %d, %d, %d] }, S3 { x: [%d, %d, %d, %d, %d] })\n",
114            s.x[0], s.x[1], s.x[2], s.x[3], s.x[4],
115            t.x[0], t.x[1], t.x[2], t.x[3], t.x[4]
116         );
117     fflush(stdout);
118 }
119
120 __declspec(dllexport) void __fastcall fastcall_fn_9(uint8_t x, double y) {
121     printf("fastcall_fn_9(%d, %.1f)\n", x, y);
122     fflush(stdout);
123 }
124
125 // GCC doesn't support vectorcall: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89485
126 #ifdef _MSC_VER
127 __declspec(dllexport) void __vectorcall vectorcall_fn_1(int i) {
128     printf("vectorcall_fn_1(%d)\n", i);
129     fflush(stdout);
130 }
131
132 __declspec(dllexport) void __vectorcall vectorcall_fn_2(uint8_t i, float f) {
133     printf("vectorcall_fn_2(%d, %.1f)\n", i, f);
134     fflush(stdout);
135 }
136
137 __declspec(dllexport) void __vectorcall vectorcall_fn_3(double d) {
138     printf("vectorcall_fn_3(%.1f)\n", d);
139     fflush(stdout);
140 }
141
142 __declspec(dllexport) void __vectorcall vectorcall_fn_4(uint8_t i, uint8_t j, float f) {
143     printf("vectorcall_fn_4(%d, %d, %.1f)\n", i, j, f);
144     fflush(stdout);
145 }
146
147 __declspec(dllexport) void __vectorcall vectorcall_fn_5(struct S s, int i) {
148     printf("vectorcall_fn_5(S { x: %d, y: %d }, %d)\n", s.x, s.y, i);
149     fflush(stdout);
150 }
151
152 __declspec(dllexport) void __vectorcall vectorcall_fn_6(struct S* s) {
153     if (s) {
154         printf("vectorcall_fn_6(S { x: %d, y: %d })\n", s->x, s->y);
155     } else {
156         printf("vectorcall_fn_6(null)\n");
157     }
158     fflush(stdout);
159 }
160
161 __declspec(dllexport) void __vectorcall vectorcall_fn_7(struct S2 s, int i) {
162     printf("vectorcall_fn_7(S2 { x: %d, y: %d }, %d)\n", s.x, s.y, i);
163     fflush(stdout);
164 }
165
166 __declspec(dllexport) void __vectorcall vectorcall_fn_8(struct S3 s, struct S3 t) {
167     printf("vectorcall_fn_8(S3 { x: [%d, %d, %d, %d, %d] }, S3 { x: [%d, %d, %d, %d, %d] })\n",
168            s.x[0], s.x[1], s.x[2], s.x[3], s.x[4],
169            t.x[0], t.x[1], t.x[2], t.x[3], t.x[4]
170         );
171     fflush(stdout);
172 }
173
174 __declspec(dllexport) void __vectorcall vectorcall_fn_9(uint8_t x, double y) {
175     printf("vectorcall_fn_9(%d, %.1f)\n", x, y);
176     fflush(stdout);
177 }
178 #endif