annotate libffi/testsuite/libffi.complex/cls_complex_struct.inc @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 04ced10e8804
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* -*-c-*- */
kono
parents:
diff changeset
2 #include "ffitest.h"
kono
parents:
diff changeset
3 #include <complex.h>
kono
parents:
diff changeset
4
kono
parents:
diff changeset
5 typedef struct Cs {
kono
parents:
diff changeset
6 _Complex T_C_TYPE x;
kono
parents:
diff changeset
7 _Complex T_C_TYPE y;
kono
parents:
diff changeset
8 } Cs;
kono
parents:
diff changeset
9
kono
parents:
diff changeset
10 Cs gc;
kono
parents:
diff changeset
11
kono
parents:
diff changeset
12 void
kono
parents:
diff changeset
13 closure_test_fn(Cs p)
kono
parents:
diff changeset
14 {
kono
parents:
diff changeset
15 printf("%.1f,%.1fi %.1f,%.1fi\n",
kono
parents:
diff changeset
16 T_CONV creal (p.x), T_CONV cimag (p.x),
kono
parents:
diff changeset
17 T_CONV creal (p.y), T_CONV cimag (p.y));
kono
parents:
diff changeset
18 gc = p;
kono
parents:
diff changeset
19 }
kono
parents:
diff changeset
20
kono
parents:
diff changeset
21 void
kono
parents:
diff changeset
22 closure_test_gn(ffi_cif* cif __UNUSED__, void* resp __UNUSED__,
kono
parents:
diff changeset
23 void** args, void* userdata __UNUSED__)
kono
parents:
diff changeset
24 {
kono
parents:
diff changeset
25 closure_test_fn(*(Cs*)args[0]);
kono
parents:
diff changeset
26 }
kono
parents:
diff changeset
27
kono
parents:
diff changeset
28 int main(int argc __UNUSED__, char** argv __UNUSED__)
kono
parents:
diff changeset
29 {
kono
parents:
diff changeset
30 ffi_cif cif;
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 void *code;
kono
parents:
diff changeset
33 ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
kono
parents:
diff changeset
34 ffi_type *cl_arg_types[1];
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 ffi_type ts1_type;
kono
parents:
diff changeset
37 ffi_type* ts1_type_elements[4];
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 Cs arg = { 1.0 + 11.0 * I, 2.0 + 22.0 * I};
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 ts1_type.size = 0;
kono
parents:
diff changeset
42 ts1_type.alignment = 0;
kono
parents:
diff changeset
43 ts1_type.type = FFI_TYPE_STRUCT;
kono
parents:
diff changeset
44 ts1_type.elements = ts1_type_elements;
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 ts1_type_elements[0] = &T_FFI_TYPE;
kono
parents:
diff changeset
47 ts1_type_elements[1] = &T_FFI_TYPE;
kono
parents:
diff changeset
48 ts1_type_elements[2] = NULL;
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 cl_arg_types[0] = &ts1_type;
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 /* Initialize the cif */
kono
parents:
diff changeset
53 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
kono
parents:
diff changeset
54 &ffi_type_void, cl_arg_types) == FFI_OK);
kono
parents:
diff changeset
55
kono
parents:
diff changeset
56 CHECK(ffi_prep_closure_loc(pcl, &cif, closure_test_gn, NULL, code) == FFI_OK);
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 gc.x = 0.0 + 0.0 * I;
kono
parents:
diff changeset
59 gc.y = 0.0 + 0.0 * I;
kono
parents:
diff changeset
60 ((void*(*)(Cs))(code))(arg);
kono
parents:
diff changeset
61 /* { dg-output "1.0,11.0i 2.0,22.0i\n" } */
kono
parents:
diff changeset
62 CHECK (gc.x == arg.x && gc.y == arg.y);
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 gc.x = 0.0 + 0.0 * I;
kono
parents:
diff changeset
65 gc.y = 0.0 + 0.0 * I;
kono
parents:
diff changeset
66 closure_test_fn(arg);
kono
parents:
diff changeset
67 /* { dg-output "1.0,11.0i 2.0,22.0i\n" } */
kono
parents:
diff changeset
68 CHECK (gc.x == arg.x && gc.y == arg.y);
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 return 0;
kono
parents:
diff changeset
71 }