Debian Codegraph @

gcc/testsuite/jit.dg/test-alignof.c

raw
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <stdint.h>
5
6 #include "libgccjit.h"
7
8 #include "harness.h"
9
10 void
11 create_code (gcc_jit_context *ctxt, void *user_data)
12 {
13 /* Let's try to inject the equivalent of:
14 int
15 my_alignof ()
16 {
17 return _Alignof(int32_t);
18 }
19 */
20 gcc_jit_type *int32 =
21 gcc_jit_context_get_int_type (ctxt, 4, 1);
22 gcc_jit_type *int64 =
23 gcc_jit_context_get_int_type (ctxt, 8, 1);
24 gcc_jit_type *int_type =
25 gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
26
27 gcc_jit_function *func =
28 gcc_jit_context_new_function (ctxt,
29 NULL,
30 GCC_JIT_FUNCTION_EXPORTED,
31 int_type,
32 "my_alignof",
33 0, NULL, 0);
34
35 gcc_jit_block *initial =
36 gcc_jit_function_new_block (func, "initial");
37
38 gcc_jit_field *field1 =
39 gcc_jit_context_new_field (ctxt, NULL, int32, "int32");
40 gcc_jit_field *field2 =
41 gcc_jit_context_new_field (ctxt, NULL, int64, "int64");
42
43 gcc_jit_field *fields[] = {
44 field1,
45 field2,
46 };
47
48 gcc_jit_struct *struct_type =
49 gcc_jit_context_new_struct_type (
50 ctxt,
51 NULL,
52 "ints",
53 2, fields);
54
55 gcc_jit_block_end_with_return(initial, NULL,
56 gcc_jit_context_new_alignof(ctxt, gcc_jit_struct_as_type (struct_type)));
57 }
58
59 void
60 verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
61 {
62 typedef int (*my_alignof_type) ();
63 CHECK_NON_NULL (result);
64 my_alignof_type my_alignof =
65 (my_alignof_type)gcc_jit_result_get_code (result, "my_alignof");
66 CHECK_NON_NULL (my_alignof);
67 int val = my_alignof ();
68 CHECK_VALUE (val, 8);
69 }