summaryrefslogtreecommitdiffstats
path: root/tests/run-make/raw-dylib-alt-calling-convention/extern.c
blob: 344d4a6bf5a8d0394f890700404c4939e815932c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#include <stdio.h>
#include <stdint.h>

struct S {
    uint8_t x;
    int32_t y;
};

struct S2 {
    int32_t x;
    uint8_t y;
};

struct S3 {
    uint8_t x[5];
};

__declspec(dllexport) void __stdcall stdcall_fn_1(int i) {
    printf("stdcall_fn_1(%d)\n", i);
    fflush(stdout);
}

__declspec(dllexport) void __stdcall stdcall_fn_2(uint8_t i, float f) {
    printf("stdcall_fn_2(%d, %.1f)\n", i, f);
    fflush(stdout);
}

__declspec(dllexport) void __stdcall stdcall_fn_3(double d) {
    printf("stdcall_fn_3(%.1f)\n", d);
    fflush(stdout);
}

__declspec(dllexport) void __stdcall stdcall_fn_4(uint8_t i, uint8_t j, float f) {
    printf("stdcall_fn_4(%d, %d, %.1f)\n", i, j, f);
    fflush(stdout);
}

__declspec(dllexport) void __stdcall stdcall_fn_5(struct S s, int i) {
    printf("stdcall_fn_5(S { x: %d, y: %d }, %d)\n", s.x, s.y, i);
    fflush(stdout);
}

// Test that stdcall support works correctly with the nullable pointer optimization.
__declspec(dllexport) void __stdcall stdcall_fn_6(struct S* s) {
    if (s) {
        printf("stdcall_fn_6(S { x: %d, y: %d })\n", s->x, s->y);
    } else {
        printf("stdcall_fn_6(null)\n");
    }
    fflush(stdout);
}

__declspec(dllexport) void __stdcall stdcall_fn_7(struct S2 s, int i) {
    printf("stdcall_fn_7(S2 { x: %d, y: %d }, %d)\n", s.x, s.y, i);
    fflush(stdout);
}

// Verify that we compute the correct amount of space in the argument list for a 5-byte struct.
__declspec(dllexport) void __stdcall stdcall_fn_8(struct S3 s, struct S3 t) {
    printf("stdcall_fn_8(S3 { x: [%d, %d, %d, %d, %d] }, S3 { x: [%d, %d, %d, %d, %d] })\n",
           s.x[0], s.x[1], s.x[2], s.x[3], s.x[4],
           t.x[0], t.x[1], t.x[2], t.x[3], t.x[4]
        );
    fflush(stdout);
}

// test whether f64/double values are aligned on 4-byte or 8-byte boundaries.
__declspec(dllexport) void __stdcall stdcall_fn_9(uint8_t x, double y) {
    printf("stdcall_fn_9(%d, %.1f)\n", x, y);
    fflush(stdout);
}

__declspec(dllexport) void __stdcall stdcall_fn_10(int i) {
    printf("stdcall_fn_10(%d)\n", i);
    fflush(stdout);
}

__declspec(dllexport) void __fastcall fastcall_fn_1(int i) {
    printf("fastcall_fn_1(%d)\n", i);
    fflush(stdout);
}

__declspec(dllexport) void __fastcall fastcall_fn_2(uint8_t i, float f) {
    printf("fastcall_fn_2(%d, %.1f)\n", i, f);
    fflush(stdout);
}

__declspec(dllexport) void __fastcall fastcall_fn_3(double d) {
    printf("fastcall_fn_3(%.1f)\n", d);
    fflush(stdout);
}

__declspec(dllexport) void __fastcall fastcall_fn_4(uint8_t i, uint8_t j, float f) {
    printf("fastcall_fn_4(%d, %d, %.1f)\n", i, j, f);
    fflush(stdout);
}

__declspec(dllexport) void __fastcall fastcall_fn_5(struct S s, int i) {
    printf("fastcall_fn_5(S { x: %d, y: %d }, %d)\n", s.x, s.y, i);
    fflush(stdout);
}

__declspec(dllexport) void __fastcall fastcall_fn_6(struct S* s) {
    if (s) {
        printf("fastcall_fn_6(S { x: %d, y: %d })\n", s->x, s->y);
    } else {
        printf("fastcall_fn_6(null)\n");
    }
    fflush(stdout);
}

__declspec(dllexport) void __fastcall fastcall_fn_7(struct S2 s, int i) {
    printf("fastcall_fn_7(S2 { x: %d, y: %d }, %d)\n", s.x, s.y, i);
    fflush(stdout);
}

__declspec(dllexport) void __fastcall fastcall_fn_8(struct S3 s, struct S3 t) {
    printf("fastcall_fn_8(S3 { x: [%d, %d, %d, %d, %d] }, S3 { x: [%d, %d, %d, %d, %d] })\n",
           s.x[0], s.x[1], s.x[2], s.x[3], s.x[4],
           t.x[0], t.x[1], t.x[2], t.x[3], t.x[4]
        );
    fflush(stdout);
}

__declspec(dllexport) void __fastcall fastcall_fn_9(uint8_t x, double y) {
    printf("fastcall_fn_9(%d, %.1f)\n", x, y);
    fflush(stdout);
}

__declspec(dllexport) void __fastcall fastcall_fn_10(int i) {
    printf("fastcall_fn_10(%d)\n", i);
    fflush(stdout);
}

// GCC doesn't support vectorcall: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89485
#ifdef _MSC_VER
__declspec(dllexport) void __vectorcall vectorcall_fn_1(int i) {
    printf("vectorcall_fn_1(%d)\n", i);
    fflush(stdout);
}

__declspec(dllexport) void __vectorcall vectorcall_fn_2(uint8_t i, float f) {
    printf("vectorcall_fn_2(%d, %.1f)\n", i, f);
    fflush(stdout);
}

__declspec(dllexport) void __vectorcall vectorcall_fn_3(double d) {
    printf("vectorcall_fn_3(%.1f)\n", d);
    fflush(stdout);
}

__declspec(dllexport) void __vectorcall vectorcall_fn_4(uint8_t i, uint8_t j, float f) {
    printf("vectorcall_fn_4(%d, %d, %.1f)\n", i, j, f);
    fflush(stdout);
}

__declspec(dllexport) void __vectorcall vectorcall_fn_5(struct S s, int i) {
    printf("vectorcall_fn_5(S { x: %d, y: %d }, %d)\n", s.x, s.y, i);
    fflush(stdout);
}

__declspec(dllexport) void __vectorcall vectorcall_fn_6(struct S* s) {
    if (s) {
        printf("vectorcall_fn_6(S { x: %d, y: %d })\n", s->x, s->y);
    } else {
        printf("vectorcall_fn_6(null)\n");
    }
    fflush(stdout);
}

__declspec(dllexport) void __vectorcall vectorcall_fn_7(struct S2 s, int i) {
    printf("vectorcall_fn_7(S2 { x: %d, y: %d }, %d)\n", s.x, s.y, i);
    fflush(stdout);
}

__declspec(dllexport) void __vectorcall vectorcall_fn_8(struct S3 s, struct S3 t) {
    printf("vectorcall_fn_8(S3 { x: [%d, %d, %d, %d, %d] }, S3 { x: [%d, %d, %d, %d, %d] })\n",
           s.x[0], s.x[1], s.x[2], s.x[3], s.x[4],
           t.x[0], t.x[1], t.x[2], t.x[3], t.x[4]
        );
    fflush(stdout);
}

__declspec(dllexport) void __vectorcall vectorcall_fn_9(uint8_t x, double y) {
    printf("vectorcall_fn_9(%d, %.1f)\n", x, y);
    fflush(stdout);
}

__declspec(dllexport) void __vectorcall vectorcall_fn_10(int i) {
    printf("vectorcall_fn_10(%d)\n", i);
    fflush(stdout);
}
#endif