13 called_function (void);
20 create_code (gcc_jit_context
*ctxt
, void *user_data
)
22 /* Let's try to inject the equivalent of:
24 test_caller (void (*some_fn_ptr) (void), int a)
29 and verify that the API complains about the mismatching arg
32 gcc_jit_type
*void_type
=
33 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_VOID
);
34 gcc_jit_type
*int_type
=
35 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_INT
);
37 /* Build the function ptr type. */
38 gcc_jit_type
*fn_ptr_type
=
39 gcc_jit_context_new_function_ptr_type (ctxt
, NULL
,
43 /* Build the test_fn. */
44 gcc_jit_param
*param_fn_ptr
=
45 gcc_jit_context_new_param (ctxt
, NULL
, fn_ptr_type
, "some_fn_ptr");
46 gcc_jit_param
*param_a
=
47 gcc_jit_context_new_param (ctxt
, NULL
, int_type
, "a");
48 gcc_jit_param
*params
[2];
49 params
[0] = param_fn_ptr
;
52 gcc_jit_function
*test_fn
=
53 gcc_jit_context_new_function (ctxt
, NULL
,
54 GCC_JIT_FUNCTION_EXPORTED
,
59 gcc_jit_block
*block
= gcc_jit_function_new_block (test_fn
, NULL
);
61 /* some_fn_ptr (a); */
62 gcc_jit_rvalue
*arg
= gcc_jit_param_as_rvalue (param_a
);
63 gcc_jit_block_add_eval (
65 gcc_jit_context_new_call_through_ptr (
68 gcc_jit_param_as_rvalue (param_fn_ptr
),
70 /* the above has too many args. */
71 gcc_jit_block_end_with_void_return (block
, NULL
);
75 verify_code (gcc_jit_context
*ctxt
, gcc_jit_result
*result
)
77 /* Ensure that mismatching arg count leads to the API giving a NULL
79 CHECK_VALUE (result
, NULL
);
81 /* Verify that the correct error message was emitted. */
82 CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt
),
83 "gcc_jit_context_new_call_through_ptr:"
84 " too many arguments to fn_ptr:"
85 " some_fn_ptr (got 1 args, expected 0)");