Debian Codegraph @

gcc/testsuite/jit.dg/test-sizeof.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_sizeof ()
16 {
17 return sizeof(int32_t);
18 }
19 */
20 gcc_jit_type *int32 =
21 gcc_jit_context_get_int_type (ctxt, 4, 1);
22 gcc_jit_type *int_type =
23 gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
24
25 gcc_jit_function *func =
26 gcc_jit_context_new_function (ctxt,
27 NULL,
28 GCC_JIT_FUNCTION_EXPORTED,
29 int_type,
30 "my_sizeof",
31 0, NULL, 0);
32
33 gcc_jit_block *initial =
34 gcc_jit_function_new_block (func, "initial");
35
36 gcc_jit_block_end_with_return(initial, NULL,
37 gcc_jit_context_new_sizeof(ctxt, int32));
38 }
39
40 void
41 verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
42 {
43 typedef int (*my_sizeof_type) ();
44 CHECK_NON_NULL (result);
45 my_sizeof_type my_sizeof =
46 (my_sizeof_type)gcc_jit_result_get_code (result, "my_sizeof");
47 CHECK_NON_NULL (my_sizeof);
48 int val = my_sizeof ();
49 CHECK_VALUE (val, 4);
50 }