9 create_code (gcc_jit_context
*ctxt
, void *user_data
)
11 /* Let's try to inject the equivalent of:
13 typedef void (*fn_ptr_iii) (int, int, int);
14 typedef void (*fn_ptr_ifi) (int, float, int);
25 and verify that the API complains about the mismatching types
26 in the second assignment (but not the first).
28 gcc_jit_type
*void_type
=
29 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_VOID
);
30 gcc_jit_type
*int_type
=
31 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_INT
);
32 gcc_jit_type
*float_type
=
33 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_FLOAT
);
35 gcc_jit_type
*iii_types
[] = {int_type
, int_type
, int_type
};
36 gcc_jit_type
*fn_ptr_type_iii
37 = gcc_jit_context_new_function_ptr_type (ctxt
, NULL
,
42 gcc_jit_type
*ifi_types
[] = {int_type
, float_type
, int_type
};
43 gcc_jit_type
*fn_ptr_type_ifi
44 = gcc_jit_context_new_function_ptr_type (ctxt
, NULL
,
49 gcc_jit_function
*test_fn
=
50 gcc_jit_context_new_function (ctxt
, NULL
,
51 GCC_JIT_FUNCTION_EXPORTED
,
56 gcc_jit_lvalue
*iii_ptr
=
57 gcc_jit_function_new_local (
58 test_fn
, NULL
, fn_ptr_type_iii
, "iii_ptr");
59 gcc_jit_lvalue
*ifi_ptr
=
60 gcc_jit_function_new_local (
61 test_fn
, NULL
, fn_ptr_type_ifi
, "ifi_ptr");
63 gcc_jit_block
*block
= gcc_jit_function_new_block (test_fn
, NULL
);
66 gcc_jit_block_add_assignment (
69 gcc_jit_context_null (ctxt
, fn_ptr_type_iii
));
70 /* ifi_ptr = iii_ptr; */
71 gcc_jit_block_add_assignment (
74 gcc_jit_lvalue_as_rvalue (iii_ptr
));
75 gcc_jit_block_end_with_void_return (block
, NULL
);
79 verify_code (gcc_jit_context
*ctxt
, gcc_jit_result
*result
)
81 CHECK_VALUE (result
, NULL
);
83 /* Verify that the correct error message was emitted. */
84 CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt
),
85 "gcc_jit_block_add_assignment:"
87 " assignment to ifi_ptr"
88 " (type: void (*) (int, float, int))"
90 " (type: void (*) (int, int, int))");