9 create_code (gcc_jit_context
*ctxt
, void *user_data
)
11 /* Let's try to inject the equivalent of:
14 test_caller (void (*some_fn_ptr) (int p))
16 called_function (); // missing arg
19 and verify that the API complains about the missing argument.
21 gcc_jit_type
*void_type
=
22 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_VOID
);
23 gcc_jit_type
*int_type
=
24 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_INT
);
26 /* Build the function ptr type. */
27 gcc_jit_type
*fn_ptr_type
=
28 gcc_jit_context_new_function_ptr_type (ctxt
, NULL
,
32 /* Build the test_fn. */
33 gcc_jit_param
*param_fn_ptr
=
34 gcc_jit_context_new_param (ctxt
, NULL
, fn_ptr_type
, "some_fn_ptr");
36 gcc_jit_function
*test_fn
=
37 gcc_jit_context_new_function (ctxt
, NULL
,
38 GCC_JIT_FUNCTION_EXPORTED
,
44 gcc_jit_block
*block
= gcc_jit_function_new_block (test_fn
, NULL
);
45 /* called_function (); */
46 gcc_jit_block_add_eval (
48 gcc_jit_context_new_call_through_ptr (
51 gcc_jit_param_as_rvalue (param_fn_ptr
),
53 /* the above has not enough args. */
54 gcc_jit_block_end_with_void_return (block
, NULL
);
58 verify_code (gcc_jit_context
*ctxt
, gcc_jit_result
*result
)
60 /* Ensure that mismatching arg count leads to the API giving a NULL
62 CHECK_VALUE (result
, NULL
);
64 /* Verify that the correct error message was emitted. */
65 CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt
),
66 ("gcc_jit_context_new_call_through_ptr:"
67 " not enough arguments to fn_ptr: some_fn_ptr"
68 " (got 0 args, expected 1)"));