8 volatile int the_volatile
;
11 create_code (gcc_jit_context
*ctxt
, void *user_data
)
13 /* Let's try to inject the equivalent of:
14 extern volatile int the_volatile;
17 test_using_volatile (void)
22 gcc_jit_type
*int_type
=
23 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_INT
);
24 gcc_jit_type
*volatile_int_type
=
25 gcc_jit_type_get_volatile (int_type
);
27 /* Build the test_fn. */
28 gcc_jit_function
*test_fn
=
29 gcc_jit_context_new_function (ctxt
, NULL
,
30 GCC_JIT_FUNCTION_EXPORTED
,
32 "test_using_volatile",
35 gcc_jit_block
*block
= gcc_jit_function_new_block (test_fn
, NULL
);
36 gcc_jit_lvalue
*read_of_the_volatile
=
37 gcc_jit_rvalue_dereference (
38 gcc_jit_context_new_rvalue_from_ptr (
40 gcc_jit_type_get_pointer (volatile_int_type
),
41 (void *)&the_volatile
),
44 gcc_jit_block_end_with_return (
46 gcc_jit_lvalue_as_rvalue (read_of_the_volatile
));
50 verify_code (gcc_jit_context
*ctxt
, gcc_jit_result
*result
)
52 typedef int (*fn_type
) (void);
53 CHECK_NON_NULL (result
);
55 fn_type test_using_volatile
=
56 (fn_type
)gcc_jit_result_get_code (result
, "test_using_volatile");
57 CHECK_NON_NULL (test_using_volatile
);
61 /* Call the JIT-generated function. */
62 test_using_volatile ();
64 CHECK_VALUE (test_using_volatile (), 42);