11 create_code (gcc_jit_context
*ctxt
, void *user_data
)
13 /* Let's try to inject the equivalent of:
15 _Thread_local int foo;
23 gcc_jit_type
*int_type
=
24 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_INT
);
27 gcc_jit_context_new_global (
28 ctxt
, NULL
, GCC_JIT_GLOBAL_EXPORTED
, int_type
, "foo");
29 gcc_jit_lvalue_set_tls_model (foo
, GCC_JIT_TLS_MODEL_GLOBAL_DYNAMIC
);
31 /* Build the test_fn. */
32 gcc_jit_function
*test_fn
=
33 gcc_jit_context_new_function (ctxt
, NULL
,
34 GCC_JIT_FUNCTION_EXPORTED
,
39 gcc_jit_block
*block
= gcc_jit_function_new_block (test_fn
, NULL
);
40 gcc_jit_block_add_assignment (
43 gcc_jit_context_new_rvalue_from_int (ctxt
, int_type
, 42));
44 gcc_jit_block_end_with_return (block
,
46 gcc_jit_lvalue_as_rvalue (foo
));
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_tls
=
56 (fn_type
)gcc_jit_result_get_code (result
, "test_using_tls");
57 CHECK_NON_NULL (test_using_tls
);
58 int return_value
= test_using_tls();
59 CHECK_VALUE (return_value
, 42);
61 int *foo
= (int *)gcc_jit_result_get_global (result
, "foo");
63 CHECK_VALUE (*foo
, 42);