13 called_function (void *ptr
);
20 create_code (gcc_jit_context
*ctxt
, void *user_data
)
22 /* Let's try to inject the equivalent of:
23 extern void called_function (void *ptr);
31 and verify that the API complains about the mismatching argument
32 type ("int" vs "void *"). */
33 gcc_jit_type
*void_type
=
34 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_VOID
);
35 gcc_jit_type
*void_ptr_type
=
36 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_VOID_PTR
);
37 gcc_jit_type
*int_type
=
38 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_INT
);
40 /* Declare the imported function. */
41 gcc_jit_param
*param
=
42 gcc_jit_context_new_param (ctxt
, NULL
, void_ptr_type
, "ptr");
43 gcc_jit_function
*called_fn
=
44 gcc_jit_context_new_function (ctxt
, NULL
,
45 GCC_JIT_FUNCTION_IMPORTED
,
51 /* Build the test_fn. */
52 gcc_jit_function
*test_fn
=
53 gcc_jit_context_new_function (ctxt
, NULL
,
54 GCC_JIT_FUNCTION_EXPORTED
,
59 /* called_function (42); */
61 gcc_jit_context_new_rvalue_from_int (ctxt
, int_type
, 42);
63 gcc_jit_block
*block
= gcc_jit_function_new_block (test_fn
, NULL
);
64 gcc_jit_block_add_eval (
66 gcc_jit_context_new_call (ctxt
,
70 /* the above has the wrong type for argument 1. */
71 gcc_jit_block_end_with_void_return (block
, NULL
);
75 verify_code (gcc_jit_context
*ctxt
, gcc_jit_result
*result
)
77 CHECK_VALUE (result
, NULL
);
79 /* Verify that the correct error message was emitted. */
80 CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt
),
81 ("gcc_jit_context_new_call:"
82 " mismatching types for argument 1"
83 " of function \"called_function\":"
84 " assignment to param ptr (type: void *)"
85 " from (int)42 (type: int)"));