9 create_code (gcc_jit_context
*ctxt
, void *user_data
)
11 /* Let's try to inject the equivalent of:
14 test_fn (void (*some_fn_ptr) (void *))
19 and verify that the API complains about the mismatching argument
20 type ("int" vs "void *"). */
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 function ptr type. */
29 gcc_jit_type
*fn_ptr_type
=
30 gcc_jit_context_new_function_ptr_type (ctxt
, NULL
,
32 1, &void_ptr_type
, 0);
34 /* Build the test_fn. */
35 gcc_jit_param
*param_fn_ptr
=
36 gcc_jit_context_new_param (ctxt
, NULL
, fn_ptr_type
, "some_fn_ptr");
38 gcc_jit_function
*test_fn
=
39 gcc_jit_context_new_function (ctxt
, NULL
,
40 GCC_JIT_FUNCTION_EXPORTED
,
45 /* some_fn_ptr (42); */
47 gcc_jit_context_new_rvalue_from_int (ctxt
, int_type
, 42);
49 gcc_jit_block
*block
= gcc_jit_function_new_block (test_fn
, NULL
);
50 gcc_jit_block_add_eval (
52 gcc_jit_context_new_call_through_ptr (
55 gcc_jit_param_as_rvalue (param_fn_ptr
),
57 /* the above has the wrong type for argument 1. */
58 gcc_jit_block_end_with_void_return (block
, NULL
);
62 verify_code (gcc_jit_context
*ctxt
, gcc_jit_result
*result
)
64 CHECK_VALUE (result
, NULL
);
66 /* Verify that the correct error message was emitted. */
67 CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt
),
68 ("gcc_jit_context_new_call_through_ptr:"
69 " mismatching types for argument 1 of fn_ptr:"
71 " assignment to param 1 (type: void *)"
72 " from (int)42 (type: int)"));