1 // Helper functions used only in tests
7 // These functions are used in the unit tests for C ABI calls.
10 rust_dbg_extern_identity_u32(uint32_t u) {
15 rust_dbg_extern_identity_u64(uint64_t u) {
20 rust_dbg_extern_identity_double(double u) {
25 rust_dbg_extern_identity_u8(char u) {
29 typedef void *(*dbg_callback)(void*);
32 rust_dbg_call(dbg_callback cb, void *data) {
36 void rust_dbg_do_nothing() { }
44 rust_dbg_extern_return_TwoU8s() {
52 rust_dbg_extern_identity_TwoU8s(struct TwoU8s u) {
62 rust_dbg_extern_return_TwoU16s() {
70 rust_dbg_extern_identity_TwoU16s(struct TwoU16s u) {
80 rust_dbg_extern_return_TwoU32s() {
88 rust_dbg_extern_identity_TwoU32s(struct TwoU32s u) {
98 rust_dbg_extern_return_TwoU64s() {
106 rust_dbg_extern_identity_TwoU64s(struct TwoU64s u) {
116 rust_dbg_extern_identity_TwoDoubles(struct TwoDoubles u) {
129 // MSVC doesn't allow empty structs or unions
135 rust_dbg_extern_empty_struct(struct ManyInts v1, struct Empty e, struct ManyInts v2) {
136 assert(v1.arg1 == v2.arg1 + 1);
137 assert(v1.arg2 == v2.arg2 + 1);
138 assert(v1.arg3 == v2.arg3 + 1);
139 assert(v1.arg4 == v2.arg4 + 1);
140 assert(v1.arg5 == v2.arg5 + 1);
141 assert(v1.arg6.one == v2.arg6.one + 1);
142 assert(v1.arg6.two == v2.arg6.two + 1);
147 rust_get_test_int() {
152 rust_get_null_ptr() {
156 // Debug helpers strictly to verify ABI conformance.
171 struct char_char_double {
177 struct char_char_float {
184 rust_dbg_abi_1(struct quad q) {
185 struct quad qq = { q.c + 1,
193 rust_dbg_abi_2(struct floats f) {
194 struct floats ff = { f.c + 1.0,
200 struct char_char_double
201 rust_dbg_abi_3(struct char_char_double a) {
202 struct char_char_double ccd = { a.a + 1,
208 struct char_char_float
209 rust_dbg_abi_4(struct char_char_float a) {
210 struct char_char_float ccd = { a.a + 1,
218 rust_dbg_static_mut = 3;
221 rust_dbg_static_mut_check_four() {
222 assert(rust_dbg_static_mut == 4);
231 uint64_t get_x(struct S s) {
235 uint64_t get_y(struct S s) {
239 uint64_t get_z(struct S s) {
243 uint64_t get_c_many_params(void *a, void *b, void *c, void *d, struct quad f) {
254 float get_c_exhaust_sysv64_ints(
261 // `f` used the last integer register, so `g` goes on the stack.
262 // It also used to bring the "count of available integer registers" down to
263 // `-1` which broke the next SSE-only aggregate argument (`h`) - see #62350.
270 // Calculates the average of `(x + y) / n` where x: i64, y: f64. There must be exactly n pairs
271 // passed as variadic arguments. There are two versions of this function: the
272 // variadic one, and the one that takes a `va_list`.
273 double rust_valist_interesting_average(uint64_t n, va_list pairs) {
276 for(i = 0; i < n; i += 1) {
277 sum += (double)va_arg(pairs, int64_t);
278 sum += va_arg(pairs, double);
283 double rust_interesting_average(uint64_t n, ...) {
287 sum = rust_valist_interesting_average(n, pairs);
292 int32_t rust_int8_to_int32(int8_t x) {
296 typedef union LARGE_INTEGER {
308 LARGE_INTEGER increment_all_parts(LARGE_INTEGER li) {
317 #if __SIZEOF_INT128__ == 16
319 unsigned __int128 identity(unsigned __int128 a) {
323 __int128 square(__int128 a) {
327 __int128 sub(__int128 a, __int128 b) {
333 #define OPTION_TAG_NONE (0)
334 #define OPTION_TAG_SOME (1)
336 struct U8TaggedEnumOptionU64 {
343 struct U8TaggedEnumOptionU64
344 rust_dbg_new_some_u64(uint64_t some) {
345 struct U8TaggedEnumOptionU64 r = {
346 .tag = OPTION_TAG_SOME,
352 struct U8TaggedEnumOptionU64
353 rust_dbg_new_none_u64(void) {
354 struct U8TaggedEnumOptionU64 r = {
355 .tag = OPTION_TAG_NONE,
361 rust_dbg_unpack_option_u64(struct U8TaggedEnumOptionU64 o, uint64_t *into) {
364 case OPTION_TAG_SOME:
367 case OPTION_TAG_NONE:
370 assert(0 && "unexpected tag");
375 struct U8TaggedEnumOptionU64U64 {
385 struct U8TaggedEnumOptionU64U64
386 rust_dbg_new_some_u64u64(uint64_t a, uint64_t b) {
387 struct U8TaggedEnumOptionU64U64 r = {
388 .tag = OPTION_TAG_SOME,
389 .some = { .a = a, .b = b },
394 struct U8TaggedEnumOptionU64U64
395 rust_dbg_new_none_u64u64(void) {
396 struct U8TaggedEnumOptionU64U64 r = {
397 .tag = OPTION_TAG_NONE,
403 rust_dbg_unpack_option_u64u64(struct U8TaggedEnumOptionU64U64 o, uint64_t *a, uint64_t *b) {
407 case OPTION_TAG_SOME:
411 case OPTION_TAG_NONE:
414 assert(0 && "unexpected tag");