1 /* Area:		Struct layout
2    Purpose:		Test ffi_get_struct_offsets
3    Limitations:		none.
4    PR:			none.
5    Originator: 		Tom Tromey. */
6 
7 /* { dg-do run } */
8 #include "ffitest.h"
9 #include <stddef.h>
10 
11 struct test_1
12 {
13   char c;
14   float f;
15   char c2;
16   int i;
17 };
18 
19 int
main(void)20 main (void)
21 {
22   ffi_type test_1_type;
23   ffi_type *test_1_elements[5];
24   size_t test_1_offsets[4];
25 
26   test_1_elements[0] = &ffi_type_schar;
27   test_1_elements[1] = &ffi_type_float;
28   test_1_elements[2] = &ffi_type_schar;
29   test_1_elements[3] = &ffi_type_sint;
30   test_1_elements[4] = NULL;
31 
32   test_1_type.size = 0;
33   test_1_type.alignment = 0;
34   test_1_type.type = FFI_TYPE_STRUCT;
35   test_1_type.elements = test_1_elements;
36 
37   CHECK (ffi_get_struct_offsets (FFI_DEFAULT_ABI, &test_1_type, test_1_offsets)
38 	 == FFI_OK);
39   CHECK (test_1_type.size == sizeof (struct test_1));
40   CHECK (offsetof (struct test_1, c) == test_1_offsets[0]);
41   CHECK (offsetof (struct test_1, f) == test_1_offsets[1]);
42   CHECK (offsetof (struct test_1, c2) == test_1_offsets[2]);
43   CHECK (offsetof (struct test_1, i) == test_1_offsets[3]);
44 
45   return 0;
46 }
47