9 create_code (gcc_jit_context
*ctxt
, void *user_data
)
11 /* Let's try to inject the equivalent of:
14 test_fn (void *some_ptr)
16 ((some_unspecified_fn_ptr_type)some_ptr) (42);
19 and verify that the API complains about the 42 not being a
21 gcc_jit_type
*void_type
=
22 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_VOID
);
23 gcc_jit_type
*void_ptr_type
=
24 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_VOID_PTR
);
25 gcc_jit_type
*int_type
=
26 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_INT
);
28 /* Build the test_fn. */
29 gcc_jit_param
*some_ptr
=
30 gcc_jit_context_new_param (ctxt
, NULL
, void_ptr_type
, "some_ptr");
32 gcc_jit_function
*test_fn
=
33 gcc_jit_context_new_function (ctxt
, NULL
,
34 GCC_JIT_FUNCTION_EXPORTED
,
40 gcc_jit_context_new_rvalue_from_int (ctxt
, int_type
, 42);
42 /* ((some_unspecified_fn_ptr_type)some_ptr) (42); */
43 gcc_jit_block
*block
= gcc_jit_function_new_block (test_fn
, NULL
);
44 gcc_jit_block_add_eval (
46 gcc_jit_context_new_call_through_ptr (
49 /* This is not a function pointer. */
50 gcc_jit_param_as_rvalue (some_ptr
),
52 gcc_jit_block_end_with_void_return (block
, NULL
);
56 verify_code (gcc_jit_context
*ctxt
, gcc_jit_result
*result
)
58 CHECK_VALUE (result
, NULL
);
60 /* Verify that the correct error message was emitted. */
61 CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt
),
62 ("gcc_jit_context_new_call_through_ptr:"
63 " fn_ptr is not a function ptr: some_ptr type: void *"));