PR ada/82785
[official-gcc.git] / libffi / testsuite / libffi.call / uninitialized.c
blobf00d8302349dfc1e2de3b2f01a33b18763ee884d
1 /* { dg-do run } */
2 #include "ffitest.h"
4 typedef struct
6 unsigned char uc;
7 double d;
8 unsigned int ui;
9 } test_structure_1;
11 static test_structure_1 struct1(test_structure_1 ts)
13 ts.uc++;
14 ts.d--;
15 ts.ui++;
17 return ts;
20 int main (void)
22 ffi_cif cif;
23 ffi_type *args[MAX_ARGS];
24 void *values[MAX_ARGS];
25 ffi_type ts1_type;
26 ffi_type *ts1_type_elements[4];
28 memset(&cif, 1, sizeof(cif));
29 ts1_type.size = 0;
30 ts1_type.alignment = 0;
31 ts1_type.type = FFI_TYPE_STRUCT;
32 ts1_type.elements = ts1_type_elements;
33 ts1_type_elements[0] = &ffi_type_uchar;
34 ts1_type_elements[1] = &ffi_type_double;
35 ts1_type_elements[2] = &ffi_type_uint;
36 ts1_type_elements[3] = NULL;
38 test_structure_1 ts1_arg;
39 /* This is a hack to get a properly aligned result buffer */
40 test_structure_1 *ts1_result =
41 (test_structure_1 *) malloc (sizeof(test_structure_1));
43 args[0] = &ts1_type;
44 values[0] = &ts1_arg;
46 /* Initialize the cif */
47 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
48 &ts1_type, args) == FFI_OK);
50 ts1_arg.uc = '\x01';
51 ts1_arg.d = 3.14159;
52 ts1_arg.ui = 555;
54 ffi_call(&cif, FFI_FN(struct1), ts1_result, values);
56 CHECK(ts1_result->ui == 556);
57 CHECK(ts1_result->d == 3.14159 - 1);
59 free (ts1_result);
60 exit(0);